code: 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
docs: Retrieve a dict of {index: escape_code} for a given string.
          If no escape codes are found, an empty dict is returned.