~ubuntu-branches/debian/experimental/jawn/experimental

« back to all changes in this revision

Viewing changes to support/json4s/src/main/scala/Parser.scala

  • Committer: Package Import Robot
  • Author(s): Frédéric Bonnard
  • Date: 2017-04-14 12:48:39 UTC
  • Revision ID: package-import@ubuntu.com-20170414124839-p3xxui7g9mjqperi
Tags: upstream-0.10.4
Import upstream version 0.10.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package jawn
 
2
package support.json4s
 
3
 
 
4
import scala.collection.mutable
 
5
import org.json4s.JsonAST._
 
6
 
 
7
object Parser extends SupportParser[JValue] {
 
8
 
 
9
  implicit val facade: Facade[JValue] =
 
10
    new Facade[JValue] {
 
11
      def jnull() = JNull
 
12
      def jfalse() = JBool(false)
 
13
      def jtrue() = JBool(true)
 
14
      def jnum(s: String) = JDouble(java.lang.Double.parseDouble(s))
 
15
      def jint(s: String) = JInt(java.lang.Integer.parseInt(s))
 
16
      def jstring(s: String) = JString(s)
 
17
 
 
18
      def singleContext() =
 
19
        new FContext[JValue] {
 
20
          var value: JValue = null
 
21
          def add(s: String) { value = jstring(s) }
 
22
          def add(v: JValue) { value = v }
 
23
          def finish: JValue = value
 
24
          def isObj: Boolean = false
 
25
        }
 
26
 
 
27
      def arrayContext() =
 
28
        new FContext[JValue] {
 
29
          val vs = mutable.ListBuffer.empty[JValue]
 
30
          def add(s: String) { vs += jstring(s) }
 
31
          def add(v: JValue) { vs += v }
 
32
          def finish: JValue = JArray(vs.toList)
 
33
          def isObj: Boolean = false
 
34
        }
 
35
 
 
36
      def objectContext() =
 
37
        new FContext[JValue] {
 
38
          var key: String = null
 
39
          val vs = mutable.ListBuffer.empty[JField]
 
40
          def add(s: String): Unit =
 
41
            if (key == null) key = s
 
42
            else { vs += JField(key, jstring(s)); key = null }
 
43
          def add(v: JValue): Unit =
 
44
            { vs += JField(key, v); key = null }
 
45
          def finish: JValue = JObject(vs.toList)
 
46
          def isObj: Boolean = true
 
47
        }
 
48
    }
 
49
}