1
  X   ˆl–ßi~””Ò~ê�Æ]¸ÛJbÑ¿“þZl«6R‚GÆÓÄyà-7³WüÿÂ{‹„„-i[D<†ªoZƒ›Ù«Ã519_‹I|¥Žƒî4ÃVŸÃÂ     ‹      �SM‹Û0½ëWL.k'Ë:i¡Ph…M…méaËJZyœhW–\}d–ü÷Ž,ËqØRJÆöÌ›™7OOËÅŒÁ‚îd‡ñëÚt+·;_Š9¼^½z¶Š;¸ÞYé¼évháN*gtÄþt7R vXÓÿ’±"8ç­¾`l¹Xô0S…€¿:c½«bèCî•©¨íóÕ�‡uf”ë7èÑ¶R#È<Q@àô|15V"öJÉG„š{Šˆ¢F›Y¹çÓ¤&há¥Ñ°ãî+•m¨à&ãKâ�¼�Ã3Øs{êD”R®Ce‡sFØÆX(c�$àê½ÞOX(Ô[¿£èåejq�r|—?*Í[„õz…Ñ©ï€°èƒÕàmÀ>rdñac¢áÊ!;Žb}ëµ>0†Æš¸RP£óRó¸~/MR‡[Â<›ûþ8Ô¼8 Q¶t0gBÅ]fÓ ÐYóŸàöÐáGk�-n·¡Eí3/éhƒŸAZ¬IÅa§ØÌS�i²àibÒ&ÓÕY.ã”+ç*‰sVTÎÙIÀ<�J²oVÕ[ò�xÌKüÍyây³©IþÉ3B‡ÿišœ$øÔ;ì…£’›fQ1¡�ëÐpqH=Ý&Œ&“ŒVË*K½7t¿èîM÷=qª9,kÕ«sd¿=m³^    F   ˆl–ßi~”*eJe@ãm\TÅ£�þY�·ÖnP¶&Þr¸@?Æ„a}ŸÅ_�uÐb&=LyZËcõÅÄ ;Y    # encoding: UTF-8
#
# Copyright 2011, 2012 Keith Rarick
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# See https://github.com/kr/okjson for updates.

require 'stringio'

module MultiJson
  # Some parts adapted from
  # https://golang.org/src/encoding/json/decode.go and
  # https://golang.org/src/unicode/utf8/utf8.go
  module OkJson
    Upstream = '45'
    extend self


    # Decodes a json document in string s and
    # returns the corresponding ruby value.
    # String s must be valid UTF-8. If you have
    # a string in some other encoding, convert
    # it first.
    #
    # String values in the resulting structure
    # will be UTF-8.
    def decode(s)
      ts = lex(s)
      v, ts = textparse(ts)
      if ts.length > 0
        raise Error, 'trailing garbage'
      end
      v
    end


    # Encodes x into a json text. It may contain only
    # Array, Hash, String, Numeric, true, false, nil.
    # (Note, this list excludes Symbol.)
    # X itself must be an Array or a Hash.
    # No other value can be encoded, and an error will
    # be raised if x contains any other value, such as
    # Nan, Infinity, Symbol, and Proc, or if a Hash key
    # is not a String.
    # Strings contained in x must be valid UTF-8.
    def encode(x)
      case x
      when Hash    then objenc(x)
      when Array   then arrenc(x)
      else
        raise Error, 'root value must be an Array or a Hash'
      end
    end


    def valenc(x)
      case x
      when Hash    then objenc(x)
      when Array   then arrenc(x)
      when String  then strenc(x)
      when Numeric then numenc(x)
      when true    then "true"
      when false   then "false"
      when nil     then "null"
      else
        if x.respond_to?(:to_json)
          x.to_json
        else
          raise Error, "cannot encode #{x.class}: #{x.inspect}"
        end
      end
    end


  private


    # Parses a "json text" in the sense of RFC 4627.
    # Returns the parsed value and any trailing tokens.
    # Note: this is almost the same as valparse,
    # except that it does not accept atomic values.
    def textparse(ts)
      if ts.length <= 0
        raise Error, 'empty'
      end

      typ, _, val = ts[0]
      case typ
      when '{' then objparse(ts)
      when '[' then arrparse(ts)
      else
        raise Error, "unexpected #{val.inspect}"
      end
    end


    # Parses 