unescapes JSON Pointer using ~0 for ~ and ~1 for /
@param s the string to unescape
@return the unescaped string
14091
function jpunescape(s) {
    s = s.split('~1').join('/');
    s = s.split('~0').join('~');
    return s;
}
91760
public static String decode(String s, Charset cs) {
        boolean needToChange = false;
        int numChars = s.length();
        StringBuilder sb = new StringBuilder(numChars > 500 ? numChars / 2 : numChars); // MTD: Using StringBuilder instead of StringBuffer
        int i = 0;

        char c;
        byte[] bytes = null;
        while (i < numChars) {
            c = s.charAt(i);
            switch (c) {
            case '+':
                sb.append(' ');
                i++;
                needToChange = true;
                break;
            case '%':
                /*
                 * Starting with this instance of %, process all
                 * consecutive substrings of the form %xy. Each
                 * substring %xy will yield a byte. Convert all
                 * consecutive  bytes obtained this way to whatever
                 * character(s) they represent in the provided
                 * encoding.
                 */

                try {

                    // (numChars-i)/3 is an upper bound for the number
                    // of remaining bytes
                    if (bytes == null)
                        bytes = new byte[(numChars-i)/3];
                    int pos = 0;

                    while ( ((i+2) < numChars) &&
                            (c=='%')) {
                        int v = Integer.parseInt(s.substring(i+1,i+3),16);
                        if (v < 0)
                            throw new IllegalArgumentException("ExtendedURLDecoder: Illegal hex characters in escape (%) pattern - negative value");
                        bytes[pos++] = (byte) v;
                        i+= 3;
                        if (i < numChars)
                            c = s.charAt(i);
                    }

                    // A trailing, incomplete byte encoding such as
                    // "%x" will cause an exception to be thrown

                    if ((i < numChars) && (c=='%'))
                        throw new IllegalArgumentException(
                         "ExtendedURLDecoder: Incomplete trailing escape (%) pattern");

                    sb.append(new String(bytes, 0, pos, cs)); // MTD: Using the Charset directly instead of first have to look it up from a string at this point
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException(
                    "ExtendedURLDecoder: Illegal hex characters in escape (%) pattern - "
                    + e.getMessage());
                }
                needToChange = true;
                break;
            default:
                sb.append(c);
                i++;
                break;
            }
        }

        return (needToChange? sb.toString() : s);
    }
657255
public static String decodeAmpersand_UNKNOWN(String s) {
    if (s == null) {
      return null;
    }
    StringBuffer sb = new StringBuffer(s.length());
    while (s != null && s.length() != 0) {
      int i = s.indexOf("&");
      if (i == -1) {
        sb.append(s);
        s = null;
      } else {
        boolean space = false;
        boolean end = false;
        sb.append(s.substring(0, i));
        s = s.substring(i);
        int j1 = s.indexOf(";");
        int j2 = s.indexOf(" ");
        int j = -1;
        if (j1 == -1 || j2 == -1) {
          if (j1 == -1 && j2 == -1) {
            end = true;
            j = s.length();
          } else if (j1 == -1) {
            j = j2;
          } else if (j2 == -1) {
            j = j1;
          }
        } else if (j1 < j2) {
          j = j1;
        } else if (j1 > j2) {
          j = j2;
          space = true;
        }
        String a = s.substring(1, j);
        if (ampersandMap.get(a) != null) {
          sb.append(ampersandMap.get(a));
          if (space) {
            sb.append(' ');
          }
        } else if (a.startsWith("#")) {
          try {
            sb.append(((char) Integer.parseInt(a.substring(1))));
          } catch (Exception e) {
            sb.append(a);
          }
          if (space) {
            sb.append(' ');
          }
        } else {
          if (end) {
            sb.append(s.substring(0, j));
          } else {
            sb.append(s.substring(0, j + 1));
          }
        }
        if (end) {
          s = s.substring(j);
        } else {
          s = s.substring(j + 1);
        }
      }
    }
    return sb.toString();
  }
915532
protected StringBuffer slice_to(StringBuffer s)
    {
	slice_check();
	int len = ket - bra;
	s.replace(0, s.length(), current.substring(bra, ket));
	return s;
    }
389154
@Nonnull
  @ReturnsMutableCopy
  public static byte [] decode (@Nonnull final String s) throws IOException
  {
    return decode (s, NO_OPTIONS);
  }
491622
public static String unescape(String value) {
        for (int i = 0; i < value.length(); i++) {
            final char c = value.charAt(i);
            if (c < ' ' || c >= '~' || (c == '%' && i + 2 < value.length())) {
                return doUnescape(value.getBytes(StandardCharsets.US_ASCII));
            }
        }
        return value;
    }
473903
@Override
    public Map<String, String> deserialize(String s) {

        try {

            String input = multiline ? s : s.replace('&', '\n');

            Properties props = new Properties();
            if (s != null) {
                props.load(new StringReader(input));
            }

            LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
            for (Entry<Object, Object> entry : props.entrySet()) {
                result.put(entry.getKey().toString(), entry.getValue().toString());
            }
            return result;

        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

    }
1204632
public static String escape(String s, JSONStyle compression) {
		if (s == null)
			return null;
		StringBuilder sb = new StringBuilder();
		compression.escape(s, sb);
		return sb.toString();
	}
770422
public static String convertText(String s) {
        StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
        StringBuffer stringbuffer = new StringBuffer();
        int ai[] = new int[s.length()];
        int i = 0;
        int j = 0;
        for(char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next())
            if(c == '%')
            {
                c = stringcharacteriterator.next();
                if(c != '%')
                {
                    stringbuffer.append('%');
                    c = stringcharacteriterator.previous();
                } else
                {
                    c = stringcharacteriterator.next();
                    switch(c)
                    {
                    case 37: // '%'
                        stringbuffer.append('%');
                        break;

                    case 80: // 'P'
                    case 112: // 'p'
                        stringbuffer.append('\361');
                        break;

                    case 67: // 'C'
                    case 99: // 'c'
                        stringbuffer.append('\355');
                        break;

                    case 68: // 'D'
                    case 100: // 'd'
                        stringbuffer.append('\u00b0');
                        break;

                    case 85: // 'U'
                    case 117: // 'u'
                        ai[stringbuffer.length()] ^= 1;
                        i++;
                        break;

                    case 79: // 'O'
                    case 111: // 'o'
                        ai[stringbuffer.length()] ^= 2;
                        j++;
                        break;

                    default:
                        if(c >= '0' && c <= '9')
                        {
                            int k = 3;
                            char c1 = (char)(c - 48);
                            for(c = stringcharacteriterator.next(); c >= '0' && c <= '9' && --k > 0; c = stringcharacteriterator.next())
                                c1 = (char)(10 * c1 + (c - 48));

                            stringbuffer.append(c1);
                        }
                        c = stringcharacteriterator.previous();
                        break;
                    }
                }
            } else
            if(c == '^')
            {
                c = stringcharacteriterator.next();
                if(c == ' ')
                    stringbuffer.append('^');
            } else
            {
                stringbuffer.append(c);
            }
        s = Unicode.char2DOS437(stringbuffer, 2, '?');

		String ss = s;
		return ss;
	}
}
1280729
public static byte[] decode(String s)
  {
	  ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int len = s.length();
 	  
	  boolean toggle = false;
	  int keep = 0;

    for (int i = 0; i < len; i++) {
      char ch = s.charAt(i);
 	    int n = ALPHABET.indexOf(Character.toLowerCase(ch));
	    if (n == -1) {
		    throw new 
		      IllegalArgumentException(s+" is not properly encoded");
	    }

 	    toggle = !toggle;

 	    if (toggle) {
		    keep = n;
	    } else {
		    baos.write((keep << 4) | n);
 	    }
 	  }
	  return baos.toByteArray();
  }
807690
private static String unescapeString(String str){
        if(str.startsWith("\"") && str.endsWith("\"")){
            String s = str.replaceAll("\\\\\"", "\"");
            return s.substring(1, s.length() -1);
        }
        return null;
    }
758629
public static String decodeUTF8(String s) {
    StringBuilder result = new StringBuilder();
    int[] eatLength = new int[1];
    while (s.length() != 0) {
      char c = eatUtf8(s, eatLength);
      if (eatLength[0] != -1) {
        result.append(c);
        s = s.substring(eatLength[0]);
      } else {
        result.append(s.charAt(0));
        s = s.substring(1);
      }
    }
    return (result.toString());
  }
1022521
private static CharSequence decode0(final CharSequence s) {
    final int length = s.length();
    final CharBuffer cb = CharBuffer.allocate(length);

    for (int i = 0; i < length; ) {
      final char c = s.charAt(i);

      // Not encoded?
      if (c != '%') {
        cb.append(c);
        i++;
        continue;
      }

      // UTF8 - 1 Byte
      int b1 = decodePercent(s, length, i);
      if (b1 == INVALID) {
        return null;
      }
      i += 3;
      final int n = utf8Length(b1);
      if (n == INVALID) {
        return null;
      }
      if (n == 1) {
        cb.append((char) b1);
        continue;
      }

      // UTF8 - 2 Bytes
      final int b2 = decodePercent(s, length, i);
      if (b2 == INVALID) {
        return null;
      }
      i += 3;
      if (n == 2) {
        final int cp = utf8Read2(b1, b2);
        if (cp == INVALID) {
          return null;
        }
        cb.append((char) cp);
        continue;
      }

      // UTF8 - 3 Bytes
      final int b3 = decodePercent(s, length, i);
      if (b3 == INVALID) {
        return null;
      }
      i += 3;
      if (n == 3) {
        final int cp = utf8Read3(b1, b2, b3);
        if (cp == INVALID) {
          return null;
        }
        cb.append((char) cp);
        continue;
      }

      // UTF8 - 4 Bytes
      final int b4 = decodePercent(s, length, i);
      if (b4 == INVALID) {
        return null;
      }
      i += 3;
      final int cp = utf8Read4(b1, b2, b3, b4);
      if (cp == INVALID) {
        return null;
      }
      final int offset = cp - MIN_SUPPLEMENTARY_CODE_POINT;
      cb.append((char) ((offset >>> 10) + MIN_HIGH_SURROGATE));
      cb.append((char) ((offset & 0x3ff) + MIN_LOW_SURROGATE));
    }

    cb.flip();
    return cb;
  }
825737
public static String decodeBackslash(String s) {
	  if(s==null || s.indexOf('\\')==-1) return(s);
    StringBuilder result = new StringBuilder();
    int[] eatLength = new int[1];
    while (s.length() != 0) {
      char c = eatBackslash(s, eatLength);
      if (eatLength[0] > 1) {
        result.append(c);
        s = s.substring(eatLength[0]);
      } else {
        result.append(s.charAt(0));
        s = s.substring(1);
      }
    }
    return (result.toString());
  }
1364718
@Nullable
  public static String getWithoutForbiddenChars (@Nullable final String s)
  {
    if (s == null)
      return null;

    final StringBuilder aCleanValue = new StringBuilder (s.length ());
    int nForbidden = 0;

    for (final char c : s.toCharArray ())
      if (isForbiddenParamValueChar (c))
        nForbidden++;
      else
        aCleanValue.append (c);

    if (nForbidden == 0)
    {
      // Return "as-is"
      return s;
    }

    if (LOGGER.isWarnEnabled ())
      LOGGER.warn ("Removed " + nForbidden + " forbidden character(s) from a request parameter value!");

    return aCleanValue.toString ();
  }
1296462
public static String unescape(String string, char escape)
   {
      CharArrayWriter out = new CharArrayWriter(string.length());
      for (int i = 0; i < string.length(); i++)
      {
         char c = string.charAt(i);
         if (c == escape)
         {
            try
            {
               out.write(Integer.parseInt(string.substring(i + 1, i + 3), 16));
            }
            catch (NumberFormatException e)
            {
               throw new IllegalArgumentException(e);
            }
            i += 2;
         }
         else
         {
            out.write(c);
         }
      }
      return new String(out.toCharArray());
   }
280767
def unescape_json_str(st):
    
    c = 0
    ln = len(st)
    escape_chmap = {
        b'b': b'\b',
        b'f': b'\f',
        b'n': b'\n',
        b'r': b'\r',
        b't': b'\t',
        b'\\': b'\\',
        b'"': b'\"',
        b'/': b'\/'
    }

    ret = []

    def at(i):
        return st[i:i+1]

    while c < ln:
        if at(c) == b'\\':
            if at(c+1) == b'u':
                ret.append(bytes([int(st[c+2:c+6], 16)]))
                # ret.append(st[c:c+6].decode('unicode_escape').encode('utf8'))
                c += 6

            else:
                ret.append(escape_chmap[at(c+1)])
                c += 2

        else:
            ret.append(at(c))
            c += 1

    df = (b''.join(ret))
    return df