Replace the scheme of the input {@link URI} if it matches the string to replace.
164498
public static URI replaceScheme(URI uri, String replace, String replacement) {
    if (replace != null && replace.equals(replacement)) {
      return uri;
    }
    try {
      if (replace != null && replace.equals(uri.getScheme())) {
        return new URI(replacement, uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
      } else {
        return uri;
      }
    } catch (URISyntaxException use) {
      throw new RuntimeException("Failed to replace scheme.");
    }
  }
1077038
public static String substitute(String input, Object model)
    throws MdwException {
        return substitute(input, model, null, false);
    }
1220911
public void normalizeByScheme() {
        String rURI = toString();
        String scheme = uri.getScheme();
        String authority = uri.getAuthority();
        String host = uri.getHost();
        int port = uri.getPort();
        String path = uri.getPath();

        if (port == defaultPort(scheme)) {
            rURI = rURI.replaceFirst(":" + port, "");
            try {
                uri = new URI(rURI);
            } catch (URISyntaxException e) {
                // This should never be reached
                e.printStackTrace();
            }
        }

        if (port == -1 && authority != null && authority.endsWith(":")) {
            rURI = rURI.replaceFirst(authority, authority.substring(0, authority.length() -1));
            try {
                uri = new URI(rURI);
            } catch (URISyntaxException e) {
                // This should never be reached
                e.printStackTrace();
            }
        }

        if (path == null || path.length() == 0) {
            if (host != null) {
                rURI = rURI.replaceFirst(host, host + '/');
            } else {
                rURI = rURI.replaceFirst(authority, authority + '/');
            }
            uri = URI.create(rURI);
        }
    }
1209553
String replace(String source) {
        if (source == null)
            return null;
        Matcher m = PATTERN.matcher(source);
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            String var = m.group(1);
            String value = values.getProperty(var);
            String replacement = (value != null) ? replace(value) : "";
            m.appendReplacement(sb, Matcher.quoteReplacement(replacement));
        }
        m.appendTail(sb);
        return sb.toString();
    }
597893
public boolean matches(String uri) {
		if (uri == null) {
			return false;
		}
		Matcher matcher = this.matchPattern.matcher(uri);
		return matcher.matches();
	}
282726
public ReplaceWith replace(String what) {
		ReplaceWith ret = new ReplaceWith(what, this, OPERATOR.Common.COMMA_SEPARATOR);
		QueryRecorder.recordInvocationConditional(this, "replace", ret, QueryRecorder.literal(what));
		return ret;
	}
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
466438
private String sanitizeUri(String uri) {
        if (uri == null || uri.length() == 0) {
            return null;
        }
        try {
            return new URI(uri).toString();
        } catch (URISyntaxException e) {
            return null;
        }
    }
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;
        }
    }
1114111
public static function removeSchemeFromUri($uri, &$scheme = "")
    {
        $scheme = "";

        return preg_replace_callback("/^[a-z0-9+\.\-]+:\/\//", function ($matches) use (&$scheme) {
            $scheme = $matches[0];
            return "";
        }, $uri);
    }
611303
private String substitute(String uri) {
    	List<String> params = extractRequiredParamsInURI(uri);
    	for (String param: params) {
    		if (param.equals(PARAMS)) {
    			uri = uri.replace("{" + PARAMS +"}", Utils.urlEncode(getParamsURI()));
    		}
    		else {
    			uri = uri.replace("{" + param + "}", (String)commandParams.get(param));
    		}
    	}
        return uri;
    }
693849
public static String newURI(String scheme, String server, int port, String path, String query) {
        StringBuilder builder = newURIBuilder(scheme, server, port);
        builder.append(path);
        if (query != null && query.length() > 0)
            builder.append('?').append(query);
        return builder.toString();
    }
552433
private void initializeScheme(String p_uriSpec) throws MalformedURIException
  {

    int uriSpecLen = p_uriSpec.length();
    int index = 0;
    String scheme = null;
    char testChar = '\0';

    while (index < uriSpecLen)
    {
      testChar = p_uriSpec.charAt(index);

      if (testChar == ':' || testChar == '/' || testChar == '?'
              || testChar == '#')
      {
        break;
      }

      index++;
    }

    scheme = p_uriSpec.substring(0, index);

    if (scheme.length() == 0)
    {
      throw new MalformedURIException(Utils.messages.createMessage(MsgKey.ER_NO_SCHEME_INURI, null)); //"No scheme found in URI.");
    }
    else
    {
      setScheme(scheme);
    }
  }
1299023
def with_scheme(self, scheme):
        """"""
        # N.B. doesn't cleanup query/fragment
        if not isinstance(scheme, str):
            raise TypeError("Invalid scheme type")
        if not self.is_absolute():
            raise ValueError("scheme replacement is not allowed " "for relative URLs")
        return URL(self._val._replace(scheme=scheme.lower()), encoded=True)
655847
protected boolean match(final URI uri) {

        final String methodName = "match";
        final String uriStr = prepareUri(uri);

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, methodName, this, uriStr, ignoreCase, wildcard);
        }

        if (this.matcher == null) {
            if (ignoreCase) {
                if (pattern.equalsIgnoreCase(uriStr)) {
                    return true;
                }
                if (wildcard && uriStr.toLowerCase().startsWith(pattern)) {
                    return true;
                }
            } else {
                if (pattern.equals(uriStr)) {
                    return true;
                }
                if (wildcard && uriStr.startsWith(pattern)) {
                    return true;
                }
            }
        } else {
            return this.matcher.matcher(uriStr).matches();
        }

        return false;
    }
1062411
public static URI newURIQuietly(final String uriString)
	{
		try
		{
			final URI uri = newURI(uriString);
			return uri;
		}
		catch (final URISyntaxException e)
		{
			throw new CompilerRuntimeException(
				"Given String " + uriString + " does not match to an uri", e);
		}
	}
1267292
@CheckReturnValue
  static URI createUri(String scheme, InetAddress address, int port) throws URISyntaxException {
    checkNotNull(address);
    return new URI(
        scheme,
        null /* userInfo */,
        InetAddresses.toUriString(address),
        port,
        null /* path */,
        null /* query */,
        null /* fragment */);
  }