shorten a URI with standard prefix @returns an array of bytes
773039
function encode(uri) {
    
    var prefix,
        protocolCode,
        encoded;

    // check each protocol, unless we've found a match
    // "urn:" is the one exception where we need to keep checking
    // slice so we don't check ""
    protocols.slice(1).forEach(function(protocol) {                        
        if ((!prefix || prefix === "urn:") && uri.indexOf(protocol) === 0) { 
            prefix = protocol;
        }
    });

    if (!prefix) {
        prefix = "";
    }
    
    encoded = util.stringToBytes(uri.slice(prefix.length));
    protocolCode = protocols.indexOf(prefix);    
    // prepend protocol code
    encoded.unshift(protocolCode);
    
    return encoded; 
}
744593
private static String massageUri(String uriString) {
        if(!uriString.startsWith(SCHEMA_SPECIFIC_PREFIX)) {
            uriString = SCHEMA_SPECIFIC_PREFIX + uriString;
        }
        return uriString;
    }
137211
public static function shorten($url)
    {
        $client = new Client();
        $request = $client->get(self::$_BITLY_URL);
        $request->getQuery()->add('access_token', self::$_ACCESS_KEY);
        $request->getQuery()->add('longUrl', $url);
        $resp = $request->send();
        $jsonRep = $resp->json();
        return $jsonRep['data']['url'];
    }
882792
@Override
    public short getShort(final int index) {
        boundsCheck(index, Bits.SHORT_SIZE_IN_BYTES);

        short bits = MEM.getShort(byteArray, addressOffset + index);
        if (NATIVE_BYTE_ORDER != PROTOCOL_BYTE_ORDER) {
            bits = Short.reverseBytes(bits);
        }

        return bits;
    }
801448
String
rrToString() {
	StringBuffer sb = new StringBuffer();
	sb.append(prefixBits);
	if (suffix != null) {
		sb.append(" ");
		sb.append(suffix.getHostAddress());
	}
	if (prefix != null) {
		sb.append(" ");
		sb.append(prefix);
	}
	return sb.toString();
}
172958
private String urlPrefix(URL url) {
        StringBuilder result = new StringBuilder();
        result.append(url.getProtocol());
        String[] splits = StringUtils.split(url.getHost(), '.');
        if (splits.length > 0) {
            for (String split : splits) {
                result.append(split);
            }
        }
        if (url.getPort() > -1) {
            result.append(Integer.toString(url.getPort()));
        }
        return result.toString();
    }
1318395
@Override
    public String doGetNamespaceURI(String prefix)
    {
        // Note: base class checks for 'known' problems and prefixes:
        if (mNsByPrefix == null) {
            mNsByPrefix = buildByPrefixMap();
        }
        Namespace ns = mNsByPrefix.get(prefix);
        if (ns == null && mParentCtxt != null) {
            return mParentCtxt.getNamespaceURI(prefix);
        }
        return (ns == null) ? null : ns.getNamespaceURI();
    }
123265
function encodeURIParams(params, prefix) {
    let parts = [];
    for (const name in params) {
        if (Object.prototype.hasOwnProperty.call(params, name)) {
            const paramName = prefix ? (`${prefix}[${encodeURIComponent(name)}]`) : encodeURIComponent(name);
            if (typeof params[name] === 'object') {
                parts = Array.prototype.concat.apply(parts,
                    encodeURIParams(params[name], paramName));
            } else {
                parts.push(`${paramName}=${encodeURIComponent(params[name])}`);
            }
        }
    }
    return parts;
}
171710
@Nullable
    public static String shortenURI(@Nullable final URI uri) {
        if (uri == null) {
            return null;
        }
        final String prefix = Data.namespaceToPrefix(uri.getNamespace(), Data.getNamespaceMap());
        if (prefix != null) {
            return prefix + ':' + uri.getLocalName();
        }
        final String ns = uri.getNamespace();
        return "&lt;.." + uri.stringValue().substring(ns.length() - 1) + "&gt;";
        // final int index = uri.stringValue().lastIndexOf('/');
        // if (index >= 0) {
        // return "&lt;.." + uri.stringValue().substring(index) + "&gt;";
        // }
        // return "&lt;" + uri.stringValue() + "&gt;";
    }
626732
public String[] getShortPath() {
        if (path == null || path.length == 0)
            return null;
        int index = 0;
        if (path[0].equals(pmiroot)) {
            index = 1;
        }
        if (index == 0)
            return path;

        String[] ret = new String[path.length - index];
        for (int i = 0; i < ret.length; i++)
            ret[i] = path[i + index];

        return ret;
    }
433660
public static String decodeUri(String url)
	{
		int index1 = url.indexOf(sessUrlRewritePrefix);
		int index2 = url.indexOf(qMark);

		String tmp = null;
		if (index2 != -1 && index2 > index1)
		{
			tmp = url.substring(index2);
		}
		if (index1 != -1)
		{
			url = url.substring(0, index1);
			if (tmp != null)
			{
				url = url + tmp;
			}
		}
		return url;
	}
1038481
public static String shortUuid() {
        // source: java.util.UUID.randomUUID()
        final byte[] randomBytes = new byte[16];
        UUID_GENERATOR.nextBytes(randomBytes);
        randomBytes[6] = (byte) (randomBytes[6] & 0x0f); // clear version
        randomBytes[6] = (byte) (randomBytes[6] | 0x40); // set to version 4
        randomBytes[8] = (byte) (randomBytes[8] & 0x3f); // clear variant
        randomBytes[8] = (byte) (randomBytes[8] | 0x80); // set to IETF variant

        // all base 64 encoding schemes use A-Z, a-z, and 0-9 for the first 62 characters. for the
        // last 2 characters, we use hyphen and underscore, which are URL safe
        return BaseEncoding.base64Url().omitPadding().encode(randomBytes);
    }
154797
String getSuffix(URI uri) {

        String fragment = uri.getFragment();
        if (fragment != null) {
            fragment = "#" + fragment;
        } else {
            fragment = "";
        }

        String query = uri.getRawQuery();
        if (query != null) {
            query = "?" + query;
        } else {
            query = "";
        }
        return query.concat(fragment);
    }
48279
public String normalizeUri(String uri, boolean isWindows)
    throws IOException
  {
    CharBuffer cb = new CharBuffer();

    int len = uri.length();

    if (_maxURILength < len)
      throw new BadRequestException(L.l("The request contains an illegal URL because it is too long."));

    char ch;
    if (len == 0 || (ch = uri.charAt(0)) != '/' && ch != '\\')
      cb.append('/');

    for (int i = 0; i < len; i++) {
      ch = uri.charAt(i);

      if (ch == '/' || ch == '\\') {
      dots:
        while (i + 1 < len) {
          ch = uri.charAt(i + 1);

          if (ch == '/' || ch == '\\')
            i++;
          else if (ch != '.')
            break dots;
          else if (len <= i + 2
                   || (ch = uri.charAt(i + 2)) == '/' || ch == '\\') {
            i += 2;
          }
          else if (ch != '.')
            break dots;
          else if (len <= i + 3
                   || (ch = uri.charAt(i + 3)) == '/' || ch == '\\') {
            int j;

            for (j = cb.length() - 1; j >= 0; j--) {
              if ((ch = cb.charAt(j)) == '/' || ch == '\\')
                break;
            }
            if (j > 0)
              cb.length(j);
            else
              cb.length(0);
            i += 3;
          } else {
            throw new BadRequestException(L.l("The request contains an illegal URL."));
          }
        }

        while (isWindows && cb.length() > 0
               && ((ch = cb.lastChar()) == '.' || ch == ' ')) {
          cb.length(cb.length() - 1);

          if (cb.length() > 0
              && (ch = cb.lastChar()) == '/' || ch == '\\') {
            cb.length(cb.length() - 1);
            // server/003n
            continue;
          }
        }

        cb.append('/');
      }
      else if (ch == 0)
        throw new BadRequestException(L.l("The request contains an illegal URL."));
      else
        cb.append(ch);
    }

    while (isWindows && cb.length() > 0
           && ((ch = cb.lastChar()) == '.' || ch == ' ')) {
      cb.length(cb.length() - 1);
    }

    return cb.toString();
  }
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;
        }
    }
181002
private String encodeUri( String uri )
	{
		StringBuilder newUri = new StringBuilder();
		StringTokenizer st = new StringTokenizer( uri, "/ ", true );
		while ( st.hasMoreTokens())
		{
			String tok = st.nextToken();
			if ( tok.equals( "/" )) {
				newUri.append('/');
			} else if ( tok.equals( " " )) {
				newUri.append("%20");
			} else {
				try {
					newUri.append(URLEncoder.encode( tok, "UTF-8" ));
				} catch ( UnsupportedEncodingException uee ) { // NOPMD - imported code
					// imported code
				}
			}
		}
		return newUri.toString();
	}
619304
def shorten(original_chars, chars, length_without_trailing)
      truncated = []
      char_width = display_width(chars[0])
      while length_without_trailing - char_width > 0
        orig_char = original_chars.shift
        char = chars.shift
        break unless char
        while orig_char != char # consume ansi
          ansi = true
          truncated << orig_char
          orig_char = original_chars.shift
        end
        truncated << char
        char_width = display_width(char)
        length_without_trailing -= char_width
      end
      truncated << ["\e[0m"] if ansi
      truncated
    end