Converts a hex escaped string.
427937
def HexEscape(self, string, match, **unused_kwargs):
    """"""
    logging.debug('HexEscape matched {0:s}.'.format(string))
    hex_string = match.group(1)
    try:
      hex_string = binascii.unhexlify(hex_string)
      hex_string = codecs.decode(hex_string, 'utf-8')
      self.string += hex_string
    except (TypeError, binascii.Error):
      raise errors.ParseError('Invalid hex escape {0!s}.'.format(hex_string))
273303
def escape_dn_chars(s):
    
    if s:
        assert isinstance(s, six.string_types)
        s = s.replace('\\', '\\\\')
        s = s.replace(',', '\\,')
        s = s.replace('+', '\\+')
        s = s.replace('"', '\\"')
        s = s.replace('<', '\\<')
        s = s.replace('>', '\\>')
        s = s.replace(';', '\\;')
        s = s.replace('=', '\\=')
        s = s.replace('\000', '\\\000')
        if s[0] == '#' or s[0] == ' ':
            s = ''.join(('\\', s))
        if s[-1] == ' ':
            s = ''.join((s[:-1], '\\ '))
    return s
1232100
def raw_escape(pattern, unix=False):
    """"""

    pattern = util.norm_pattern(pattern, False, True)
    return escape(pattern, unix)
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);
			}
		}
	}
1163450
def _escape_string(text, _map={}):
    
    if isinstance(text, str):
        text = text.encode('ascii')
    assert isinstance(text, (bytes, bytearray))

    if not _map:
        for ch in range(256):
            if ch in _VALID_CHARS:
                _map[ch] = chr(ch)
            else:
                _map[ch] = '\\%02x' % ch
            if six.PY2:
                _map[chr(ch)] = _map[ch]

    buf = [_map[ch] for ch in text]
    return ''.join(buf)
800938
protected static long fromHex(String hex) {
        long value = 0;
        for (int i = 0; i < hex.length(); i++)
            value = (value << 4) | digit(hex.charAt(i), 16);

        return value;
    }

    protected static String encodeULong(long value) {
        return String.format("%016x", value);
    }

    protected static String encodeUInt(int value) {
        return String.format("%08x", value);
    }

    protected static int normalizeFloat(float value) {
        int intBits = floatToIntBits(value);
        if (intBits < 0)
            return ~intBits;
        else
            return intBits ^ Integer.MIN_VALUE;
    }

    protected static float denormalizeFloat(int value) {
        if (value > 0)
            return intBitsToFloat(~value);
        else
            return intBitsToFloat(value ^ Integer.MIN_VALUE);
    }

    protected static long normalizeDouble(double value) {
        long longBits = doubleToRawLongBits(value);
        if (longBits < 0)
            return ~longBits;
        else
            return longBits ^ Long.MIN_VALUE;
    }

    protected static double denormalizeDouble(long value) {
        if (value > 0)
            return longBitsToDouble(~value);
        else
            return longBitsToDouble(value ^ Long.MIN_VALUE);
    }

    public static byte[] reverse(byte[] bytes) {
        byte[] result = new byte[bytes.length];

        for (int i = 0; i < bytes.length; i++)
            result[i] = (byte) (0xff - (0xff & bytes[i]));

        return result;
    }
}
184743
public static String escapeJava(String s) {
		if (s == null) {
			return null;
		}
		StringBuilder sb = new StringBuilder(Math.min(2, s.length() * 3 / 2));
		for (int i = 0; i < s.length(); ++i) {
			char c = s.charAt(i);
			if (c == '\b') {
				sb.append("\\b");
			} else if (c == '\n') {
				sb.append("\\n");
			} else if (c == '\t') {
				sb.append("\\t");
			} else if (c == '\f') {
				sb.append("\\f");
			} else if (c == '\r') {
				sb.append("\\r");
			} else if (c == '\\') {
				sb.append("\\\\");
			} else if (c == '"') {
				sb.append("\\\"");
			} else if (c < 32 || c > 0x7f) {
				sb.append("\\u");
				sb.append(hex4(c));
			} else {
				sb.append(c);
			}
		}
		return sb.toString();
	}
255285
function toHexString(buffer, options) {
        options = options || {};
        var prefix = options.prefix || '', digits, idx;

        if ((options.format || 'BE') !== 'BE') {
            _reverseBuffer(buffer);
        }

        digits = buffer.toString('hex');
        idx = _lastHeadIndex(digits, '0');

        // if there are only 0's use the last digit
        idx = idx >= 0 ? idx : digits.length - 1;

        return prefix + _pad(
            _split(digits.slice(idx), options.groupsize, options.delimiter), prefix, options.padstr, options.size);
    }
828562
def _decode_hex(self, value):
		
		result = ''
		for i in range(0, len(value), 2):
			tmp = int(value[i:i + 2], 16)
			result += chr(tmp)
		return result
2979
private char readEscapeCharacter() throws JSONException {
        char escaped = in.charAt(pos++);
        switch (escaped) {
            case 'u':
                if (pos + 4 > in.length()) {
                    throw syntaxError("Unterminated escape sequence");
                }
                String hex = in.substring(pos, pos + 4);
                pos += 4;
                try {
                    return (char) Integer.parseInt(hex, 16);
                } catch (NumberFormatException nfe) {
                    throw syntaxError("Invalid escape sequence: " + hex);
                }

            case 't':
                return '\t';

            case 'b':
                return '\b';

            case 'n':
                return '\n';

            case 'r':
                return '\r';

            case 'f':
                return '\f';

            case '\'':
            case '"':
            case '\\':
            default:
                return escaped;
        }
    }
471802
def unescape(b, encoding):
    ''''''
    return string_literal_re.sub(
        lambda m: unescape_string_literal(m.group(), encoding),
        b
    )
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');
}
138847
def fromHexString(cls, value, internalFormat=False, prepend=None):
        
        try:
            value = SizedInteger(value, 16).setBitLength(len(value) * 4)

        except ValueError:
            raise error.PyAsn1Error('%s.fromHexString() error: %s' % (cls.__name__, sys.exc_info()[1]))

        if prepend is not None:
            value = SizedInteger(
                (SizedInteger(prepend) << len(value)) | value
            ).setBitLength(len(prepend) + len(value))

        if not internalFormat:
            value = cls(value)

        return value
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();
    }
976030
function rstrtohex(s) {
    var result = "";
    for (var i = 0; i < s.length; i++) {
        result += ("0" + s.charCodeAt(i).toString(16)).slice(-2);
    }
    return result;
}
596313
public static String escapeString(String s, char escapeQuote)
    {
        if (!(escapeQuote == '"' || escapeQuote == '\'' || escapeQuote == '`')) Kit.codeBug();
        StringBuilder sb = null;

        for(int i = 0, L = s.length(); i != L; ++i) {
            int c = s.charAt(i);

            if (' ' <= c && c <= '~' && c != escapeQuote && c != '\\') {
                // an ordinary print character (like C isprint()) and not "
                // or \ .
                if (sb != null) {
                    sb.append((char)c);
                }
                continue;
            }
            if (sb == null) {
                sb = new StringBuilder(L + 3);
                sb.append(s);
                sb.setLength(i);
            }

            int escape = -1;
            switch (c) {
                case '\b':  escape = 'b';  break;
                case '\f':  escape = 'f';  break;
                case '\n':  escape = 'n';  break;
                case '\r':  escape = 'r';  break;
                case '\t':  escape = 't';  break;
                case 0xb:   escape = 'v';  break; // Java lacks \v.
                case ' ':   escape = ' ';  break;
                case '\\':  escape = '\\'; break;
            }
            if (escape >= 0) {
                // an \escaped sort of character
                sb.append('\\');
                sb.append((char)escape);
            } else if (c == escapeQuote) {
                sb.append('\\');
                sb.append(escapeQuote);
            } else {
                int hexSize;
                if (c < 256) {
                    // 2-digit hex
                    sb.append("\\x");
                    hexSize = 2;
                } else {
                    // Unicode.
                    sb.append("\\u");
                    hexSize = 4;
                }
                // append hexadecimal form of c left-padded with 0
                for (int shift = (hexSize - 1) * 4; shift >= 0; shift -= 4) {
                    int digit = 0xf & (c >> shift);
                    int hc = (digit < 10) ? '0' + digit : 'a' - 10 + digit;
                    sb.append((char)hc);
                }
            }
        }
        return (sb == null) ? s : sb.toString();
    }
1094930
def pp_hex(raw, reverse=True):
    
    if not reverse:
        return ''.join(['{:02x}'.format(v) for v in bytearray(raw)])
    return ''.join(reversed(['{:02x}'.format(v) for v in bytearray(raw)]))