@param IUrl $url
@param bool $encode

@return string
434990
public function build(IUrl $url, $encode = false) {
        $pattern = $this->pattern;
        $pattern = $this->setProtocol($pattern, $url, $encode);
        $pattern = $this->setCredentials($pattern, $url, $encode);
        $pattern = $this->setHost($pattern, $url, $encode);
        $pattern = $this->setPort($pattern, $url, $encode);
        $pattern = $this->setPath($pattern, $url, $encode);
        $pattern = $this->setQuery($pattern, $url, $encode);
        $pattern = $this->setFragment($pattern, $url, $encode);

        return $pattern;
    }
732118
public function encodePopup(Popup $popup, Encoder $encoder)
    {
        $source = $popup->getSource();
        $buffer = sprintf(
            '%s = L.popup(%s%s);',
            $encoder->encodeReference($popup),
            $encoder->encodeArray($popup->getOptions()),
            $source ? (', ' . $encoder->encodeReference($source)) : ''
        );

        $buffer .= $this->encodeMethodCalls($popup->getMethodCalls(), $encoder);

        return $buffer;
    }
1265894
function urlencode(obj) {
  var pairs = [];
  for (var key in obj) {
    if ({}.hasOwnProperty.call(obj, key))
      pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
  }
  return pairs.join('&');
}
1294666
static function realstring($str,$encode='utf8')
    {
        if($encode=='utf8') $n = preg_match('/^[\x{4e00}-\x{9fa5}|a-z|0-9|A-Z]+$/u',$str,$match);
        else $n = preg_match("/^[".chr(0xa1)."-".chr(0xff)."|a-z|0-9|A-Z]+$/",$str,$match);
        if($n===0) return false;
        else return $match[0];
    }
441941
public function append($tag, $value, $encode = true)
    {
        if ($value instanceof URL) {
            $value = $value->__toString();
        }

        if ($encode) {
            $value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
        }

        $this->getTagRefList($tag, $template);
        foreach ($template as $key => &$ref) {
            $ref[] = $value;
        }

        return $this;
    }
1338481
public function post($url, $data = [], $encode = false) {

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);

        if (!empty($data)) {
            if (is_array($data) && $encode === true) {
                $data = http_build_query($data);
            }
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }

        $this->_parse_result($ch);

        $content = curl_exec($ch);
        curl_close($ch);

        if ($this->handle_referer) {
            $this->referer = $url;
        }

        return $this->_parse_result($content);
    }
395498
@Override
    public String encodeRedirectURL(String url) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "encodeRedirectURL: " + url);
        }
        return encodeURL(url);
    }
1087962
private static function encodeHeader(string $s, int &$offset = 0, bool $quotes = false): string
    {
        if (\strspn($s,
                "!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === \strlen($s)) {
            if ($quotes && \preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =
                return self::append('"' . \addcslashes($s, '"\\') . '"', $offset);
            }

            return self::append($s, $offset);
        }

        $o = '';
        if ($offset >= 55) { // maximum for iconv_mime_encode
            $o = self::EOL . "\t";
            $offset = 1;
        }

        $filed = \str_repeat(' ', $old = $offset);
        if (\function_exists('\iconv_mime_encode')) {
            $s = \iconv_mime_encode($filed, $s, [
                'scheme' => 'B', // Q is broken
                'input-charset' => 'UTF-8',
                'output-charset' => 'UTF-8',
            ]);
        } else {
            $s = $filed . ': ' . \mb_encode_mimeheader($s, 'UTF-8', 'B');
        }

        $offset = \strlen($s) - \strrpos($s, "\n");
        $s = \str_replace("\n ", "\n\t", \substr($s, $old + 2)); // adds ': '

        return $o . $s;
    }
621936
public function getCode(bool $upper = false): string
    {
        $this->checkLocale();
        if (isset($this->locales[$this->selectLocale]['code'])) {
            $code = $this->locales[$this->selectLocale]['code'];
            return ($upper ? strtoupper($code) : $code);
        }
        return '';
    }
1076355
private static String encodeUrl(String url) {
        try {
            URL u = new URL(url);
            return encodeUrl(u).toExternalForm();
        } catch (Exception e) {
            return url;
        }
	}
160524
public function getValue(bool $urldecoded = true) : string
    {
        return (($urldecoded === true) ? rawurldecode($this->value) : $this->value);
    }
1171147
public static String encode( String url, String encoding )
    {
        String encodedURL = null;
        try
        {
            encodedURL = URLCodec.encode( url, encoding );
        }
        catch ( java.io.UnsupportedEncodingException e )
        {
            // try utf-8 as a default encoding
            try
            {
                encodedURL = URLCodec.encode( url, DEFAULT_ENCODING );
            }
            catch ( java.io.UnsupportedEncodingException ignore )
            {
            }
        }
        return encodedURL;
    }
1294923
public static function urlEncode($str = null, $keep_mask = true)
    {
        if (
            (!empty($str) && is_numeric($str)) ||
            (true===$keep_mask && $str==='%s')
        ) {
            return $str;
        }
        if (empty($str) || !is_string($str)) {
            return '';
        }
        return urlencode($str);
    }
294406
protected function setHost($pattern, IUrl $url, $encode = false, $key = ':host') {
        $host = $url->getHost();
        $pattern = s($pattern, [$key => $host]);

        return $pattern;
    }
612433
public function getCacheFile(callable $encoder = null): string
    {
        if (\is_null($encoder)) {
            $encoder = function ($value): string {
                return var_export($value, true);
            };
        }

        $statics = $encoder($this->staticRoutes);
        $counts = $encoder($this->segmentCounts);
        $values = $encoder($this->segmentValues);
        $definitions = $encoder($this->routeDefinitions);
        $names = $encoder($this->routesByName);

        return <<<TEMPLATE
<?php return new class extends \Simply\Router\RouteDefinitionProvider {
    protected \$staticRoutes = $statics;
    protected \$segmentCounts = $counts;
    protected \$segmentValues = $values;
    protected \$routeDefinitions = $definitions;
    protected \$routesByName = $names;
};
TEMPLATE;
    }
475941
public function mail_domain($host, $encode=true)
    {
        $domain = $host;

        if (is_array($this->prop['mail_domain'])) {
            if (isset($this->prop['mail_domain'][$host])) {
                $domain = $this->prop['mail_domain'][$host];
            }
        }
        else if (!empty($this->prop['mail_domain'])) {
            $domain = rcube_utils::parse_host($this->prop['mail_domain']);
        }

        if ($encode) {
            $domain = rcube_utils::idn_to_ascii($domain);
        }

        return $domain;
    }
156425
public function flush($encode = true)
    {
        $this->_ensureReadable(false);
        $content = stream_get_contents($this->_resource);
        return $encode && $this->_encoding ? Mime::encode($content, $this->_encoding) : $content;
    }