Converts a hex escaped string.
169080
def HexEscape(self, string, match, **_):
    """"""
    hex_string = match.group(1)
    try:
      self.string += binascii.unhexlify(hex_string).decode("utf-8")
    # TODO: In Python 2 `binascii` throws `TypeError` for invalid
    # input values (for whathever reason). This behaviour is fixed in Python 3
    # where `binascii.Error` (a subclass of `ValueError`) is raised. Once we do
    # not have to support Python 2 anymore, this `TypeError` catch should be
    # removed.
    except (binascii.Error, TypeError) as error:
      raise ParseError("Invalid hex escape '{}': {}".format(hex_string, error))
517707
function decodeCssEscape(s) {
    var i = parseInt(s.substring(1), 16);
    // If parseInt didn't find a hex diigt, it returns NaN so return the
    // escaped character.
    // Otherwise, parseInt will stop at the first non-hex digit so there's no
    // need to worry about trailing whitespace.
    if (i > 0xffff) {
      // A supplemental codepoint.
      return i -= 0x10000,
        String.fromCharCode(
            0xd800 + (i >> 10),
            0xdc00 + (i & 0x3FF));
    } else if (i == i) {
      return String.fromCharCode(i);
    } else if (s[1] < ' ') {
      // "a backslash followed by a newline is ignored".
      return '';
    } else {
      return s[1];
    }
  }
1305385
function bufferFromHexStr(hexStr) {
  // Remove whitespace.
  hexStr = hexStr.replace(/\s+/g, '');

  // Remove 0x.
  hexStr = no0x(hexStr);

  // Hex values with an odd number of characters need to be padded; otherwise the last character will be truncated.
  if (hexStr.length % 2) hexStr = '0' + hexStr;

  // Convert to a buffer.
  return Buffer.from(hexStr, 'hex');
}
5822
private void escape(String value) {
        int n = value.length();
        int i = 0;
        for (int j = 0; j < n; ++j) {
            int k = ESCAPED_CHARS.indexOf(value.charAt(j));
            if (k >= 0) {
                if (i < j) {
                    append(value, i, j);
                }
                append(ESCAPE_SEQ[k]);
                i = j + 1;
            }
        }
        if (i < n) {
            append(value, i, n);
        }
    }
232607
def toHex(val):
    """"""
    hex = "0123456789abcdef"
    return hex[int(val / 16)] + hex[int(val - int(val / 16) * 16)]
329804
def unhex(inp):
    ''''''
    res = inp.split(r'\x')
    for i in xrange(1, len(res)):
        item = res[i]
        try:
            res[i] = _hextochr[item[:2]] + item[2:]
        except KeyError:
            res[i] = '%' + item
        except UnicodeDecodeError:
            res[i] = unichr(int(item[:2], 16)) + item[2:]
    return ''.join(res)
255419
def split_escape(string, sep, maxsplit=None, escape_char="\\"):
    

    assert len(sep) == 1
    assert len(escape_char) == 1

    if isinstance(string, bytes):
        if isinstance(escape_char, text_type):
            escape_char = escape_char.encode("ascii")
        iter_ = iterbytes
    else:
        iter_ = iter

    if maxsplit is None:
        maxsplit = len(string)

    empty = string[:0]
    result = []
    current = empty
    escaped = False
    for char in iter_(string):
        if escaped:
            if char != escape_char and char != sep:
                current += escape_char
            current += char
            escaped = False
        else:
            if char == escape_char:
                escaped = True
            elif char == sep and len(result) < maxsplit:
                result.append(current)
                current = empty
            else:
                current += char
    result.append(current)
    return result
557049
private static String escape(char c) {
		switch (c) {
		case '\b':
			return "\\b";
		case '\t':
			return "\\t";
		case '\n':
			return "\\n";
		case '\f':
			return "\\f";
		case '\r':
			return "\\r";
		default:
			if (c < StrUtil.C_SPACE || //
					(c >= '\u0080' && c <= '\u00a0') || //
					(c >= '\u2000' && c <= '\u2010') || //
					(c >= '\u2028' && c <= '\u202F') || //
					(c >= '\u2066' && c <= '\u206F')//
			) {
				return HexUtil.toUnicodeHex(c);
			} else {
				return Character.toString(c);
			}
		}
	}
920729
def to_hex_string(data):
    '''  '''
    if isinstance(data, int):
        return '%02X' % data
    return ':'.join([('%02X' % o) for o in data])
1010266
def calculate_hex(hex_string):
        """"""
        hex_conv = hex_string.split(':')
        converted_hex = (int(hex_conv[0], 16) + int(hex_conv[1], 16))/8192

        return converted_hex
806206
function stringToHex(value) {
  const val = value == null ? '' : value;

  let hex = '';
  let tmp = '';

  for (let i = 0; i < val.length; i++) {
    // Convert to Hex and Ensure it's in 2 digit sets
    tmp = ('0000' + val.charCodeAt(i).toString(16)).slice(-2);
    hex += '' + tmp;
  }

  return hex;
}
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();
    }
1160189
function hextorstr(sHex) {
    var s = "";
    for (var i = 0; i < sHex.length - 1; i += 2) {
        s += String.fromCharCode(parseInt(sHex.substr(i, 2), 16));
    }
    return s;
}
813924
def translate_escaped_str(cls, str_val):
        """"""
        if isinstance(str_val, string_types):
            str_val = str_val.encode('unicode_escape')
            if sys.version_info >= (3, 0):
                str_val = str_val.decode('utf-8')
            str_val = str_val.replace('"', r'\"')
        return '"{}"'.format(str_val)
1193109
def hex_escape_str(original_str):
    
    new = []
    for char in original_str:
        if str(char) in string.printable:
            new.append(str(char))
            continue

        if IS_PYTHON3:
            new.append(str(char).encode("unicode_escape").decode("ascii"))
        else:
            new.append(repr(char).replace("'", ""))
    return "".join(new)
557005
public static String decode_escaped(String str) {
		if(str.indexOf('\\')==-1)
			return str;
		StringBuilder sb=new StringBuilder(str.length());
		for(int i=0; i<str.length(); ++i) {
			char c=str.charAt(i);
			if(c=='\\') {
				// possible escape sequence
				char c2=str.charAt(++i);
				switch(c2) {
					case '\\':
						// double-escaped '\\'--> '\'
						sb.append(c);
						break;
					case 'x':
						// hex escaped "\x??"
						char h1=str.charAt(++i);
						char h2=str.charAt(++i);
						c2=(char)Integer.parseInt(""+h1+h2, 16);
						sb.append(c2);
						break;
					case 'n':
						sb.append('\n');
						break;
					case 'r':
						sb.append('\r');
						break;
					case 't':
						sb.append('\t');
						break;
					case '\'':
						sb.append('\'');		// sometimes occurs in protocol level 0 strings
						break;
					default:
						if(str.length()>80)
							str=str.substring(0, 80);
						throw new PickleException("invalid escape sequence char \'"+ (c2) + "\' in string \"" + str + " [...]\" (possibly truncated)");
				}
			} else {
				sb.append(str.charAt(i));
			}
		}
        return sb.toString();
	}
431604
private String escapeStringSpecialCharacters(String str)
    {
        if (logger.isLoggable(Level.FINER)) logger.exiting(className, "escapeStringSpecialCharacters(String)");

        if (str != null)
        {
            StringBuffer strBuf = new StringBuffer("");

            for (int i = 0; i < str.length(); i++)
            {
                char strChar = str.charAt(i);

                switch (strChar)
                {
                    case '"':
                        {
                            strBuf.append("\\\"");
                            break;
                        }
                    case '\t':
                        {
                            strBuf.append("\\t");
                            break;
                        }
                    case '\b':
                        {
                            strBuf.append("\\b");
                            break;
                        }
                    case '\\':
                        {
                            strBuf.append("\\\\");
                            break;
                        }
                    case '\f':
                        {
                            strBuf.append("\\f");
                            break;
                        }
                    case '\r':
                        {
                            strBuf.append("\\r");
                            break;
                        }
                    case '/':
                        {
                            strBuf.append("\\/");
                            break;
                        }
                    default:
                        {
                            if ((strChar >= 32) && (strChar <= 126) )
                            {
                                strBuf.append(strChar);
                            }
                            else if (strChar > 126)
                            {
                              if ((escapeNonAsciiChars)) 
                              {
                                  strBuf.append("\\u");
                                  StringBuffer sb = new StringBuffer(Integer.toHexString(strChar));
                                  while (sb.length() < 4)
                                  {
                                      sb.insert(0,'0');
                                  }
                                  strBuf.append(sb.toString());
                              }
                              else {
                                strBuf.append(strChar);
                              }
                            }
                            else 
                            {
                                strBuf.append("\\u");
                                StringBuffer sb = new StringBuffer(Integer.toHexString(strChar));
                                while (sb.length() < 4)
                                {
                                    sb.insert(0,'0');
                                }
                                strBuf.append(sb.toString());
                            }

                            break;
                        }
                }
            }
            str = strBuf.toString();
        }
        if (logger.isLoggable(Level.FINER)) logger.exiting(className, "escapeStringSpecialCharacters(String)");
        return str;
    }