# File lib/multi_json/vendor/ok_json.rb, line 445
    def strenc(s)
      t = StringIO.new
      t.putc(?")
      r = 0
      while r < s.length
        case s[r]
        when ?"  then t.print('\\"')
        when ?\\ then t.print('\\\\')
        when ?\b then t.print('\\b')
        when ?\f then t.print('\\f')
        when ?\n then t.print('\\n')
        when ?\r then t.print('\\r')
        when ?\t then t.print('\\t')
        else
          c = s[r]
          case true
          when Spc <= c && c <= ?~
            t.putc(c)
          when true
            u, size = uchardec(s, r)
            r += size - 1 # we add one more at the bottom of the loop
            if u < 0x10000
              t.print('\\u')
              hexenc4(t, u)
            else
              u1, u2 = unsubst(u)
              t.print('\\u')
              hexenc4(t, u1)
              t.print('\\u')
              hexenc4(t, u2)
            end
          else
            # invalid byte; skip it
          end
        end
        r += 1
      end
      t.putc(?")
      t.string
    end