docs: def char2range(d, is_bytes=False, invert=True):
      """Convert the characters in the dict to a range in string form."""
  
      fmt = bytesformat if is_bytes else uniformat
      maxrange = MAXASCII if is_bytes else MAXUNICODE
  
      for k1 in sorted(d.keys()):
          v1 = d[k1]
          if not isinstance(v1, list):
              char2range(v1, is_bytes=is_bytes, invert=invert)
          else:
              inverted = k1.startswith('^')
              v1.sort()
              last = None
              first = None
              ilast = None
              ifirst = None
              v2 = []
              iv2 = []
              if v1 and v1[0] != 0:
                  ifirst = 0
              for i in v1:
                  if first is None:
                      first = i
                      last = i
                  elif i == last + 1:
                      last = i
                  elif first is not None:
                      if first == last:
                          v2.append(fmt(first))
                      else:
                          v2.append("%s-%s" % (fmt(first), fmt(last)))
                      if invert and ifirst is not None:
                          ilast = first - 1
                          if ifirst == ilast:
                              iv2.append(fmt(ifirst))
                          else:
                              iv2.append("%s-%s" % (fmt(ifirst), fmt(ilast)))
                      ifirst = last + 1
                      first = i
                      last = i
  
              if not v1:
                  iv2 = ["%s-%s" % (fmt(0), fmt(maxrange))]
              elif first is not None:
                  if first == last:
                      v2.append(fmt(first))
                  else:
                      v2.append("%s-%s" % (fmt(first), fmt(last)))
                  if invert and ifirst is not None:
                      ilast = first - 1
                      if ifirst == ilast:
                          iv2.append(fmt(ifirst))
                      else:
                          iv2.append("%s-%s" % (fmt(ifirst), fmt(ilast)))
                  ifirst = last + 1
                  if invert and ifirst <= maxrange:
                      ilast = maxrange
                      if ifirst == ilast:
                          iv2.append(fmt(ifirst))
                      else:
                          iv2.append("%s-%s" % (fmt(ifirst), fmt(ilast)))
              d[k1] = ''.join(v2)
              if invert:
                  d[k1[1:] if inverted else '^' + k1] = ''.join(iv2)