Normalize a nested URI.
@param uri The URI
@param nested The nested URI
@return The new URI
439473
protected String normalizeNested(String uri, CharSequence nested) {
        if (StringUtils.isEmpty(nested)) {
            return uri;
        }

        String nestedStr = nested.toString();
        char firstNested = nestedStr.charAt(0);
        int len = nestedStr.length();
        if (len == 1 && firstNested == SLASH_OPERATOR) {
            return uri;
        }

        switch (firstNested) {
            case VAR_START:
                if (len > 1) {
                    switch (nested.charAt(1)) {
                        case SLASH_OPERATOR:
                        case HASH_OPERATOR:
                        case QUERY_OPERATOR:
                        case AND_OPERATOR:
                            if (uri.endsWith(SLASH_STRING)) {
                                return uri.substring(0, uri.length() - 1) + nestedStr;
                            } else {
                                return uri + nestedStr;
                            }
                        default:
                            if (!uri.endsWith(SLASH_STRING)) {
                                return uri + SLASH_STRING + nestedStr;
                            } else {
                                return uri + nestedStr;
                            }
                    }
                } else {
                    return uri;
                }
            case SLASH_OPERATOR:
                if (uri.endsWith(SLASH_STRING)) {
                    return uri + nestedStr.substring(1);
                } else {
                    return uri + nestedStr;
                }
            default:
                if (uri.endsWith(SLASH_STRING)) {
                    return uri + nestedStr;
                } else {
                    return uri + SLASH_STRING + nestedStr;
                }
        }
    }
1028158
public static URI updateUriHost(URI uri, String newHostPrefix) {
        try {
            return new URI(uri.getScheme(), uri.getUserInfo(), newHostPrefix + uri.getHost(),
                           uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
638611
private String convertURItoURL(String uri) {
        int indexScheme = uri.indexOf("://");
        if (-1 != indexScheme) {
            int indexQuery = uri.indexOf('?');
            if (-1 == indexQuery || indexScheme < indexQuery) {
                // already a full url
                return uri;
            }
        }
        StringBuilder sb = new StringBuilder();
        String scheme = this.request.getScheme();
        sb.append(scheme).append("://");
        sb.append(this.request.getServerName());
        int port = this.request.getServerPort();
        if ("http".equalsIgnoreCase(scheme) && 80 != port) {
            sb.append(':').append(port);
        } else if ("https".equalsIgnoreCase(scheme) && 443 != port) {
            sb.append(':').append(port);
        }
        String data = this.request.getContextPath();
        if (!"".equals(data)) {
            sb.append(data);
        }
        if (0 == uri.length()) {
            sb.append('/');
        } else if (uri.charAt(0) == '/') {
            // relative to servlet container root...
            sb.append(uri);
        } else {
            // relative to current URI,
            data = this.request.getServletPath();
            if (!"".equals(data)) {
                sb.append(data);
            }
            data = this.request.getPathInfo();
            if (null != data) {
                sb.append(data);
            }
            sb.append('/');
            sb.append(uri);
            // TODO: webcontainer converted "/./" and "/../" info too
        }

        return sb.toString();
    }
95163
private static URI createUriFromName(String name) {
        if (name == null) {
            throw new NullPointerException("name");
        }
        try {
            return new URI(name);
        } catch (final URISyntaxException e) {
            throw new IllegalArgumentException("Invalid name: " + name, e);
        }
    }
937231
private String normalizeParentPath(String uri) {
        String relativeUri = extractRelativeUrl(uri, null);
        if (relativeUri.endsWith("/") && relativeUri.length() != 1) {
            relativeUri = StringUtils.removeEndIgnoreCase(relativeUri, "/");
        }
        return relativeUri;
    }
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);
        }
    }
1159095
private String encodeUri( String uri ) {
    String newUri = "";
    StringTokenizer st = new StringTokenizer( uri, "/ ", true );
    while ( st.hasMoreTokens()) {
      String tok = st.nextToken();
      if ( tok.equals( "/" ))
        newUri += "/";
      else if ( tok.equals( " " ))
        newUri += "%20";
      else {
        try {
          newUri += URLEncoder.encode( tok, "UTF-8" );
        } catch( UnsupportedEncodingException e ) {
          throw  Log.errRTExcept(e);
        }
      }
    }
    return newUri;
  }
1178746
public RequestHeader withUri(URI uri) {
        return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
    }
1042107
public static String normalizeUri(SoyValue value) {
    value = normalizeNull(value);
    return normalizeUri(value.coerceToString());
  }
624513
public static URI toURI(String uri) throws URISyntaxException {
		final URI u = new URI(uri);
		// Inspired by ZeroMQ
		String adr = u.getAuthority();
		if (adr == null) {
			adr = u.getPath();
		}
		if (adr != null && adr.endsWith(":*")) { //$NON-NLS-1$
			return new URI(u.getScheme(), u.getUserInfo(), adr.substring(0, adr.length() - 2), -1, null, u.getQuery(),
					u.getFragment());
		}
		return u;
	}
1142534
private static URI toURI(String encodedUrl) {
    try {
      return new URI(encodedUrl);
    } catch (URISyntaxException e) {
      throw new IllegalArgumentException(e);
    }
  }
219540
function URI(options) {
  if (!(this instanceof URI))
    return new URI(options);

  this.address = new Address();
  this.amount = -1;
  this.label = null;
  this.message = null;
  this.request = null;

  if (options)
    this.fromOptions(options);
}
328060
def normalize_uri_result(uri):
    
    ref = uri_reference(uri).normalize()

    return ref._replace(
        authority=normalize_uri_authority(ref),
        query=normalize_uri_query(ref),
        path=normalize_uri_path(ref),
    )
514423
public static URI createRestURI(
            final String matrixId, final int row, final int col,
            final WMTSLayerParam layerParam) throws URISyntaxException {
        String path = layerParam.baseURL;
        if (layerParam.dimensions != null) {
            for (int i = 0; i < layerParam.dimensions.length; i++) {
                String dimension = layerParam.dimensions[i];
                String value = layerParam.dimensionParams.optString(dimension);
                if (value == null) {
                    value = layerParam.dimensionParams.getString(dimension.toUpperCase());
                }
                path = path.replace("{" + dimension + "}", value);
            }
        }
        path = path.replace("{TileMatrixSet}", layerParam.matrixSet);
        path = path.replace("{TileMatrix}", matrixId);
        path = path.replace("{TileRow}", String.valueOf(row));
        path = path.replace("{TileCol}", String.valueOf(col));
        path = path.replace("{style}", layerParam.style);
        path = path.replace("{Layer}", layerParam.layer);

        return new URI(path);
    }
731922
public static List<URI> uris(AbstractConfig config, String key) {
    List<URI> result = new ArrayList<>();
    List<String> input = config.getList(key);
    for (String s : input) {
      result.add(uri(key, s));
    }
    return ImmutableList.copyOf(result);
  }
1203059
private static String normalize(String url) {
        if (StringUtils.isBlank(url)) {
            return null;
        }
        // Strip "/tree/..."
        if (url.contains("/tree/")) {
            url = url.replaceFirst("/tree/.*$", "");
        }
        if (!url.endsWith("/")) {
            url += '/';
        }
        return url;
    }
1009622
protected function _normalizedUrl($uri)
    {
        $out = $uri->getScheme() . '://';
        $out .= strtolower($uri->getHost());
        $out .= $uri->getPath();

        return $out;
    }