Returns the scheme portion of a uri.  Since schemes are case-insensitive,
normalize them to lower case.
176798
protected String scanScheme(String uri)
  {
    int i = 0;
    if (uri == null)
      return null;

    int length = uri.length();
    if (length == 0)
      return null;

    int ch = uri.charAt(0);
    if (ch >= 'a' && ch <= 'z' ||
        ch >= 'A' && ch <= 'Z') {
      for (i = 1; i < length; i++) {
        ch = uri.charAt(i);

        if (ch == ':')
          return uri.substring(0, i).toLowerCase(Locale.ENGLISH);

        if (! (ch >= 'a' && ch <= 'z' ||
               ch >= 'A' && ch <= 'Z' ||
               ch >= '0' && ch <= '0' ||
               ch == '+' || ch == '-' || ch == '.'))
          break;
      }
    }

    return null;
  }
955516
public function getScheme(): string
    {
        if (!isset($this->segments['scheme'])) {
            throw new UrlException('Unable to get scheme for ' . $this->url);
        }

        return $this->segments['scheme'];
    }
383356
def _remove_uri_scheme_from_textbuffer(self, scheme):
        """"""
        length = len(scheme)
        while length:
            if length < len(self._textbuffer[-1]):
                self._textbuffer[-1] = self._textbuffer[-1][:-length]
                break
            length -= len(self._textbuffer[-1])
            self._textbuffer.pop()
249317
public String toDecodedString(final java.net.URI uri) {
    final String scheme = uri.getScheme();
    final String part = uri.getSchemeSpecificPart();
    if ((scheme == null)) {
      return part;
    }
    return ((scheme + ":") + part);
  }
1000364
def uriunsplit(parts):
    
    scheme, authority, path, query, fragment = parts
    if isinstance(path, bytes):
        result = SplitResultBytes
    else:
        result = SplitResultUnicode
    return result(scheme, authority, path, query, fragment).geturi()
991706
static String normalizeUri(String s) {
    int n = s.length();
    boolean colonsIrrelevant = false;
    for (int i = 0; i < n; ++i) {
      char ch = s.charAt(i);
      switch (ch) {
        case '/': case '#': case '?': case ':':
          colonsIrrelevant = true;
          break;
        case '(': case ')':
        case '{': case '}':
          return normalizeUriFrom(s, i, colonsIrrelevant);
        case '\u0589':
        case '\u05c3':
        case '\u2236':
        case '\uff1a':
          if (!colonsIrrelevant) {
            return normalizeUriFrom(s, i, false);
          }
          break;
        default:
          if (ch <= 0x20) {
            return normalizeUriFrom(s, i, false);
          }
          break;
      }
    }
    return s;
  }
101152
def fix_scheme(url):
    ''''''
    splitted = url.split('://')
    if len(splitted) == 2:
        if splitted[0] in ('http', 'https'):
            return url
        else:
            raise exc.WileECoyoteException(
                'Bad scheme! Got: {}, expected http or https'.format(
                    splitted[0]))
    elif len(splitted) == 1:
        return 'http://' + url
    else:
        raise exc.ZachMorrisException('Too many schemes!')
751167
private static String getCidUriValue(String uri) {
		int colon = uri.indexOf(':');
		if (colon == 3) {
			String scheme = uri.substring(0, colon);
			return "cid".equalsIgnoreCase(scheme) ? uri.substring(colon + 1) : null;
		}

		if (uri.length() > 0 && uri.charAt(0) == '<' && uri.charAt(uri.length() - 1) == '>') {
			return uri.substring(1, uri.length() - 1);
		}

		return null;
	}
231486
def _parse_free_uri_scheme(self):
        """"""
        valid = "abcdefghijklmnopqrstuvwxyz0123456789+.-"
        scheme = []
        try:
            # We have to backtrack through the textbuffer looking for our
            # scheme since it was just parsed as text:
            for chunk in reversed(self._textbuffer):
                for char in reversed(chunk):
                    if char.isspace() or char in self.MARKERS:
                        raise StopIteration()
                    if char not in valid:
                        raise BadRoute()
                    scheme.append(char)
        except StopIteration:
            pass
        scheme = "".join(reversed(scheme))
        slashes = self._read() == self._read(1) == "/"
        if not is_scheme(scheme, slashes):
            raise BadRoute()
        self._push(self._context | contexts.EXT_LINK_URI)
        self._emit_text(scheme)
        self._emit_text(":")
        if slashes:
            self._emit_text("//")
            self._head += 2
901070
def normalize(url):
    
    url = url.strip()
    if url == '':
        return ''
    parts = split(url)
    if parts.scheme:
        netloc = parts.netloc
        if parts.scheme in SCHEMES:
            path = normalize_path(parts.path)
        else:
            path = parts.path
    # url is relative, netloc (if present) is part of path
    else:
        netloc = parts.path
        path = ''
        if '/' in netloc:
            netloc, path_raw = netloc.split('/', 1)
            path = normalize_path('/' + path_raw)
    username, password, host, port = split_netloc(netloc)
    host = normalize_host(host)
    port = _normalize_port(parts.scheme, port)
    query = normalize_query(parts.query)
    fragment = normalize_fragment(parts.fragment)
    return construct(URL(parts.scheme, username, password, None, host, None,
                         port, path, query, fragment, None))
498823
public CmsSiteMatcher forDifferentScheme(String scheme) {

        try {
            URI uri = new URI(getUrl());
            URI changedUri = new URI(scheme, uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment());
            CmsSiteMatcher res = new CmsSiteMatcher(changedUri.toString(), m_timeOffset);
            res.setRedirect(m_redirect);
            return res;
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
            return null;
        }
    }
744593
private static String massageUri(String uriString) {
        if(!uriString.startsWith(SCHEMA_SPECIFIC_PREFIX)) {
            uriString = SCHEMA_SPECIFIC_PREFIX + uriString;
        }
        return uriString;
    }
352393
function baseStringUri(uri) {
    var parsed = url.parse(uri);

    //  The port MUST be included if it is not the default port for the
    //  scheme, and MUST be excluded if it is the default.
    if (parsed.protocol === 'https:/') {
        parsed.host = parsed.host.replace(/:443$/, '');
    } else if (parsed.protocol === 'http:/') {
        parsed.host = parsed.host.replace(/:80$/, '');
    }

    return url.format({
        protocol: parsed.protocol,
        host: parsed.host,
        auth: parsed.auth,
        pathname: parsed.pathname
    });
}
1286076
def _uri_split(uri):
    """"""
    scheme, netloc, path, query, fragment = _safe_urlsplit(uri)

    auth = None
    port = None

    if '@' in netloc:
        auth, netloc = netloc.split('@', 1)

    if netloc.startswith('['):
        host, port_part = netloc[1:].split(']', 1)
        if port_part.startswith(':'):
            port = port_part[1:]
    elif ':' in netloc:
        host, port = netloc.split(':', 1)
    else:
        host = netloc
    return scheme, auth, host, port, path, query, fragment
524785
def uriunsplit(uri):
    
    (scheme, authority, path, query, fragment) = uri
    result = ''
    if scheme:
        result += scheme + ':'
    if authority:
        result += '//' + authority
    if path:
        result += path
    if query:
        result += '?' + query
    if fragment:
        result += '#' + fragment
    return result
1215144
public URLNormalizer lowerCaseSchemeHost() {
        URL u = toURL();
        url = Pattern.compile(u.getProtocol(),
                Pattern.CASE_INSENSITIVE).matcher(url).replaceFirst(
                u.getProtocol().toLowerCase());
        url = Pattern.compile(u.getHost(),
                Pattern.CASE_INSENSITIVE).matcher(url).replaceFirst(
                u.getHost().toLowerCase());
        return this;
    }
1124817
def startswith_strip(s, startswith='http://', ignorecase=True):
    
    if ignorecase:
        if s.lower().startswith(startswith.lower()):
            return s[len(startswith):]
    else:
        if s.endswith(startswith):
            return s[len(startswith):]
    return s