# File lib/multi_json/vendor/ok_json.rb, line 506
    def uchardec(s, i)
      n = s.length - i
      return [Ucharerr, 1] if n < 1

      c0 = s[i].ord

      # 1-byte, 7-bit sequence?
      if c0 < Utagx
        return [c0, 1]
      end

      # unexpected continuation byte?
      return [Ucharerr, 1] if c0 < Utag2

      # need continuation byte
      return [Ucharerr, 1] if n < 2
      c1 = s[i+1].ord
      return [Ucharerr, 1] if c1 < Utagx || Utag2 <= c1

      # 2-byte, 11-bit sequence?
      if c0 < Utag3
        u = (c0&Umask2)<<6 | (c1&Umaskx)
        return [Ucharerr, 1] if u <= Uchar1max
        return [u, 2]
      end

      # need second continuation byte
      return [Ucharerr, 1] if n < 3
      c2 = s[i+2].ord
      return [Ucharerr, 1] if c2 < Utagx || Utag2 <= c2

      # 3-byte, 16-bit sequence?
      if c0 < Utag4
        u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx)
        return [Ucharerr, 1] if u <= Uchar2max
        return [u, 3]
      end

      # need third continuation byte
      return [Ucharerr, 1] if n < 4
      c3 = s[i+3].ord
      return [Ucharerr, 1] if c3 < Utagx || Utag2 <= c3

      # 4-byte, 21-bit sequence?
      if c0 < Utag5
        u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx)
        return [Ucharerr, 1] if u <= Uchar3max
        return [u, 4]
      end

      return [Ucharerr, 1]
    end