Retrieve a dict of {index: escape_code} for a given string.
        If no escape codes are found, an empty dict is returned.
175441
def get_code_indices(s: Union[str, 'ChainedBase']) -> Dict[int, str]:
    
    indices = {}
    i = 0
    codes = get_codes(s)
    for code in codes:
        codeindex = s.index(code)
        realindex = i + codeindex
        indices[realindex] = code
        codelen = len(code)
        i = realindex + codelen
        s = s[codeindex + codelen:]
    return indices
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
1086476
def _get_string_slice(self, key):
        """"""
        parsed, resolution = _parse_iso8601_with_reso(self.date_type, key)
        try:
            loc = self._partial_date_slice(resolution, parsed)
        except KeyError:
            raise KeyError(key)
        return loc
1321010
def decode_dict_keys(d, coding="utf-8"):
    """"""
    assert compat.PY2
    res = {}
    for k, v in d.items():  #
        if type(k) is str:
            k = k.decode(coding)
        if type(v) is dict:
            v = decode_dict_keys(v, coding)
        res[k] = v
    return res
671090
def escape(self, string):
        
        html_entities = {"&": "&amp;", '<': '&lt;', '>': '&gt;'}
        return HTML("".join(html_entities.get(c, c) for c in string))
1096344
def get_code(self, value, exclude=()):
        
        key = (value, exclude)
        if key not in self:
            self[key] = self._get(value, exclude)
        return self[key]
1294277
def _escape(self, text):
        """"""
        ret = EMPTYSTRING if text is None else str(text)
        if self.escape:
            return html_escape(ret)
        else:
            return ret
302711
def escape(string, escape_pattern):
    """"""
    try:
        return string.translate(escape_pattern)
    except AttributeError:
        warnings.warn("Non-string-like data passed. "
                      "Attempting to convert to 'str'.")
        return str(string).translate(tag_escape)
669912
def _parse_dash_escaped_line(dash_escaped_line: str) -> str:
        
        text = str()
        regex_dash_escape_prefix = compile('^' + DASH_ESCAPE_PREFIX)
        # if prefixed by a dash escape prefix...
        if regex_dash_escape_prefix.match(dash_escaped_line):
            # remove dash '-' (0x2D) and space ' ' (0x20) prefix
            text += dash_escaped_line[2:]

        return text
1144629
def _decode_var(cls, string):
        

        str_match = cls.quoted_string_regex.match(string)
        if str_match:
            return string.strip("'" if str_match.groups()[0] else '"')
        # NOTE: "¹".isdigit() results in True because they are idiots
        elif string.isdigit() and cls.is_digit_regex.match(string) is not None:
            return int(string)
        elif string.lower() in ("true", "false"):
            return string.lower() == "true"
        elif string.lstrip("-").isdigit():
            try:
                return int(string)
            except ValueError:
                # case where we mistake something like "--0" as a int
                return string
        elif "." in string.lstrip("-"):
            try:
                return float(string)
            except ValueError:
                # one off case where we mistake a single "." as a float
                return string
        else:
            return string
674649
def _get_string_match(self, key):
        

        expression = r'(?:\s*)'.join([
            '^',
            'define',
            r'\(',
            '\'{}\''.format(key),
            ',',
            r'\'(.*)\'',
            r'\)',
            ';'
        ])

        pattern = re.compile(expression, re.MULTILINE)
        return pattern.search(self._content)
317531
def _opts_to_dict(*opts):
	''''''
	ret = {}
	for key, val in opts:
		if key[:2] == '--':
			key = key[2:]
		elif key[:1] == '-':
			key = key[1:]
		if val == '':
			val = True
		ret[key.replace('-','_')] = val
	return ret
795626
def get_string(self, idx):
        
        if idx in self.hook_strings:
            return self.hook_strings[idx]

        try:
            off = self.__manage_item[TypeMapItem.STRING_ID_ITEM][idx].get_string_data_off()
        except IndexError:
            log.warning("unknown string item @ %d" % idx)
            return "AG:IS: invalid string"

        try:
            if self.recode_ascii_string:
                if self.recode_ascii_string_meth:
                    return self.recode_ascii_string_meth(
                        self.__strings_off[off].get())
                return self.get_ascii_string(self.__strings_off[off].get())
            return self.__strings_off[off].get()
        except KeyError:
            log.warning("unknown string item @ 0x%x(%d)" % (off, idx))
            return "AG:IS: invalid string"
384060
def nonull_dict(self):
        
        return {k: v for k, v in six.iteritems(self.dict) if v and k != '_codes'}
1254885
function() {
        var str = "",
          quote = exprI(index++),
          closed = false,
          ch;

        while (index < length) {
          ch = exprI(index++);
          if (ch === quote) {
            closed = true;
            break;
          } else if (ch === "\\") {
            // Check for all of the common escape codes
            ch = exprI(index++);
            switch (ch) {
              case "n":
                str += "\n";
                break;
              case "r":
                str += "\r";
                break;
              case "t":
                str += "\t";
                break;
              case "b":
                str += "\b";
                break;
              case "f":
                str += "\f";
                break;
              case "v":
                str += "\x0B";
                break;
              default:
                str += "\\" + ch;
            }
          } else {
            str += ch;
          }
        }

        if (!closed) {
          throwError('Unclosed quote after "' + str + '"', index);
        }

        return {
          type: code.LITERAL,
          value: str,
          raw: quote + str + quote
        };
      }
711644
def _encode_dict_as_string(value):
        """"""
        # Strip the first and last newlines
        if value.startswith("{\n"):
            value = "{" + value[2:]
        if value.endswith("\n}"):
            value = value[:-2] + "}"
        # escape double quotes and newlines
        return value.replace('"', '\\"').replace("\\n", "\\\\n").replace("\n", "\\n")
1348707
def unescape(msg, extra_format_dict={}):
    """"""
    new_msg = ''

    extra_format_dict.update(format_dict)

    while len(msg):
        char = msg[0]
        msg = msg[1:]
        if char == escape_character:
            escape_key = msg[0]
            msg = msg[1:]

            # we handle this character separately, otherwise we mess up and
            #   double escape characters while escaping and unescaping
            if escape_key == escape_character:
                new_msg += escape_character

            elif escape_key == '{':
                buf = ''
                new_char = ''
                while True:
                    new_char = msg[0]
                    msg = msg[1:]

                    if new_char == '}':
                        break
                    else:
                        buf += new_char

                new_msg += _get_from_format_dict(extra_format_dict, buf)

            else:
                new_msg += _get_from_format_dict(extra_format_dict, escape_key)

            if escape_key == 'c':
                fill_last = len(msg) and msg[0] in digits
                colours, msg = extract_girc_colours(msg, fill_last)
                new_msg += colours
        else:
            new_msg += char

    return new_msg