Converts a string of Unicode symbols (e.g. a domain name label) to a
Punycode string of ASCII-only symbols.
@param string input The string of Unicode symbols.
@returns string The resulting Punycode string of ASCII-only symbols.
179594
public function encode($input)
    {
        $output = [];

        // Convert the input in UCS-2 to an array of Unicode code points.
        $input = $this->ucs2Decode(mb_convert_encoding($input, "UTF-16"));

        // Cache the length.
        $inputLength = count($input);

        // Initialize the state.
        $n = self::INITIAL_N;
        $delta = 0;
        $bias = self::INITIAL_BIAS;

        // Handle the basic code points.
        for ( $i=0; $i<$inputLength; $i++) {
            $currentValue = $input[$i];
            if ( $currentValue < 0x80) {
                $output[] = chr($currentValue);
            }
        }

        $basicLength = count($output);
        $handledCPCount = $basicLength;

        // `handledCPCount` is the number of code points that have been handled;
        // `basicLength` is the number of basic code points.

        // Finish the basic string with a delimiter unless it's empty.
        if ($basicLength) {
            $output[] = self::DELIMITER;
        }

        // Main encoding loop:
        while ($handledCPCount < $inputLength) {

            // All non-basic code points < n have been handled already. Find the next
            // larger one:
            $m = self::MAX_INT;
            for ( $i=0; $i<$inputLength; $i++) {
                $currentValue = $input[$i];
                if ($currentValue >= $n && $currentValue < $m) {
                    $m = $currentValue;
                }
            }

            // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
            // but guard against overflow.
            $handledCPCountPlusOne = $handledCPCount + 1;
            if ($m - $n > floor((self::MAX_INT - $delta) / $handledCPCountPlusOne)) {
                $this->error('overflow');
            }

            $delta += ($m - $n) * $handledCPCountPlusOne;
            $n = $m;

            for ( $i=0; $i<$inputLength; $i++) {
                $currentValue = $input[$i];
                if ($currentValue < $n && ++$delta > self::MAX_INT) {
                    $this->error('overflow');
                }
                if ($currentValue == $n) {
                    // Represent delta as a generalized variable-$length integer.
                    $q = $delta;
                    for ($k = self::BASE; /* no condition */; $k += self::BASE) {
                        $t = $k <= $bias ? self::T_MIN : ($k >= $bias + self::T_MAX ? self::T_MAX : $k - $bias);
                        if ($q < $t) {
                            break;
                        }
                        $qMinusT = $q - $t;
                        $baseMinusT = self::BASE - $t;
                        $output[] = chr($this->digitToBasic($t + $qMinusT % $baseMinusT, 0));
                        $q = floor($qMinusT / $baseMinusT);
                    }

                    $output[] = chr($this->digitToBasic($q, 0));
                    $bias = $this->adapt($delta, $handledCPCountPlusOne, $handledCPCount == $basicLength);
                    $delta = 0;
                    ++$handledCPCount;
                }
            }

            ++$delta;
            ++$n;

        }
        return join('', $output);
    }
424824
public static ByteBuffer decode(String input) throws IOException {
		return decode(input.getBytes(StandardCharsets.US_ASCII));
	}
895281
public function convertFromPositive($input)
    {
        $matches = [];

        if (
            !preg_match(
                '
                /^0*(?<carets>\\^*)(?<alpha>[A-Z]*)(?<year>\d+)$/',
                $input,
                $matches
            )
        ) {
            return null;
        }

        if ($matches['alpha'] === '') {
            return $matches['year'];
        }

        if ($matches['carets'] === '') {
            $expectedLength = ord($matches['alpha']) - static::ORD_START + 5;
        } else {
            $len = strlen($matches['carets']);

            $expectedLength = 0;

            for ($i=0; $i < $len; $i++) {
                $expectedLength = $expectedLength * 26;
                $expectedLength += ord($matches['alpha'][$i]) - static::ORD_START;
                $expectedLength++;
            }

            $expectedLength += 30;
        }

        return str_pad($matches['year'], $expectedLength, '0', STR_PAD_RIGHT);
    }
438429
public static String escapeString(String input) {
        StringBuilder escaped = new StringBuilder(input.length() + 10);
        escaped.append('"');
        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == '"') {
                escaped.append("\"\"");
            } else {
                escaped.append(input.charAt(i));
            }
        }
        escaped.append('"');
        return escaped.toString();
    }
1009907
public static String urlEncode(String input)
	{
		if (input == null)
		{
			return "";
		}
		try
		{
			return URLEncoder.encode(input, "UTF-8");
		}
		catch (UnsupportedEncodingException uee)
		{
			String result = StringSupport.replaceAll(input, "&", "%26");
			result = StringSupport.replaceAll(result, "<", "%3c");
			result = StringSupport.replaceAll(result, ">", "%3e");
			result = StringSupport.replaceAll(result, "\"", "%22");
			result = StringSupport.replaceAll(result, " ", "+");
			return result;
		}
	}
118436
public static int indexOfControlOrNonAscii(String input) {
    for (int i = 0, length = input.length(); i < length; i++) {
      char c = input.charAt(i);
      if (c <= '\u001f' || c >= '\u007f') {
        return i;
      }
    }
    return -1;
  }
181712
public static String convertCharsToXml(String input) {
		StringBuffer result = new StringBuffer();
		for(int i=0; i<input.length(); i++) {
			switch(input.charAt(i)) {
				case '<':	result.append("&lt;"); break;
				case '>':	result.append("&gt;"); break;
				case '"':	result.append("&quot;"); break;
				case '\'':	result.append("&apos;"); break;
				case '&':	result.append("&amp;"); break;
				default:	result.append(input.charAt(i));
			}
		}
		return result.toString().trim();
	}
429796
function (string) {
			var ascii = "";

			for (var i = 0; i < string.length; i++) {
				ascii += string.charCodeAt(i) + ",";
			}

			// remove last ","
			ascii = ascii.substring(0, ascii.length - 1);

			return ascii;
		}
485233
private static String escapeJavaString(String input)
    {
        int len = input.length();
        // assume (for performance, not for correctness) that string will not expand by more than 10 chars
        StringBuilder out = new StringBuilder(len + 10);
        for (int i = 0; i < len; i++) {
            char c = input.charAt(i);
            if (c >= 32 && c <= 0x7f) {
                if (c == '"') {
                    out.append('\\');
                    out.append('"');
                } else if (c == '\\') {
                    out.append('\\');
                    out.append('\\');
                } else {
                    out.append(c);
                }
            } else {
                out.append('\\');
                out.append('u');
                // one liner hack to have the hex string of length exactly 4
                out.append(Integer.toHexString(c | 0x10000).substring(1));
            }
        }
        return out.toString();
    }
1319603
public static String encodeToString(byte[] input, int flags) {
    try {
      return new String(encode(input, flags), "US-ASCII");
    } catch (UnsupportedEncodingException e) {
      // US-ASCII is guaranteed to be available.
      throw new AssertionError(e);
    }
  }
1289163
public function encode($input)
    {
        $input = mb_strtolower($input, $this->encoding);
        $parts = explode('.', $input);
        foreach ($parts as &$part) {
            $length = strlen($part);
            if ($length < 1) {
                throw new LabelOutOfBoundsException(sprintf('The length of any one label is limited to between 1 and 63 octets, but %s given.', $length));
            }
            $part = $this->encodePart($part);
        }
        $output = implode('.', $parts);
        $length = strlen($output);
        if ($length > 255) {
            throw new DomainOutOfBoundsException(sprintf('A full domain name is limited to 255 octets (including the separators), %s given.', $length));
        }

        return $output;
    }
12030
public static String encode(final String input, final boolean urlSafeEncoding) {
		return new String(encode(input.getBytes(charsetUTF8), urlSafeEncoding), charsetISOLatin1);
	}
745580
public static function escapeInput(string $input): string
    {
        $escaped_input = htmlspecialchars(stripslashes(trim($input)));
        return $escaped_input;
    }
654661
public String decodeToString(final byte[] input, final String outputCharset)
        throws UnsupportedEncodingException {

        return new String(decode(input), outputCharset);
    }
560991
public static String decodeBrackets(final String input) {
		if (input == null || input.length() == 0) {  // For performance reasons don't use Util.empty
			return input;
		}
		return DECODE_BRACKETS.translate(input);
	}
717958
public static String underscored(final String input) {
        if (input == null || input.length() == 0) {
            return "";
        }

        return input.trim().replaceAll("([a-z\\d])([A-Z]+)", "$1_$2").replaceAll("[-\\s]+", "_").toLowerCase();
    }
281079
public static String encodeString(final String string) {
		String encodedString = null;

		try {
			encodedString = encodeString(string, "UTF-8");
		} catch (UnsupportedEncodingException uue) {
			// Should never happen, java has to support "UTF-8".
		}

		return encodedString;
	}