diff options
author | michelou <michelou@epfl.ch> | 2008-03-13 14:21:50 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2008-03-13 14:21:50 +0000 |
commit | f8a14831d854fd00aaa5cb229fb1eb6c7351ba25 (patch) | |
tree | 513ac7d2922f103e98c35161d050fb80fba70f82 | |
parent | e9aec18ddf0292300c7bb039977f7192e5913a70 (diff) | |
download | scala-f8a14831d854fd00aaa5cb229fb1eb6c7351ba25.tar.gz scala-f8a14831d854fd00aaa5cb229fb1eb6c7351ba25.tar.bz2 scala-f8a14831d854fd00aaa5cb229fb1eb6c7351ba25.zip |
removed unchecked warnings, fixed parseFull
-rw-r--r-- | src/library/scala/util/parsing/json/JSON.scala | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/library/scala/util/parsing/json/JSON.scala b/src/library/scala/util/parsing/json/JSON.scala index 71bf2fbcb3..96d541b0f2 100644 --- a/src/library/scala/util/parsing/json/JSON.scala +++ b/src/library/scala/util/parsing/json/JSON.scala @@ -1,6 +1,6 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2006-2008, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** @@ -19,25 +19,32 @@ package scala.util.parsing.json object JSON extends Parser { /** - * Parse the given JSON string and return a List of elements. If the - * string is a JSON object it will be a list of Pairs. If it's a JSON + * Parse the given JSON string and return a list of elements. If the + * string is a JSON object it will be a list of pairs. If it's a JSON * array it will be be a list of individual elements. + * + * @param input the given JSON string. + * @return an optional list of of elements. */ - def parse(input: String) = + def parse(input: String): Option[List[Any]] = phrase(root)(new lexical.Scanner(input)) match { case Success(result, _) => Some(result) case _ => None } /** - * Parse the given JSON string and return either a List[Any] if the JSON string - * specifies an Array, or a Map[String,Any] if the JSON string specifies an - * object. + * Parse the given JSON string and return either a <code>List[Any]</code> + * if the JSON string specifies an <code>Array</code>, or a + * <code>Map[String,Any]</code> if the JSON string specifies an object. + * + * @param input the given JSON string. + * @return an optional list or map. */ - def parseFull(input: String) = parse(input) match { - case Some(data) => resolveType(data) - case None => None - } + def parseFull(input: String): Option[Any] = + parse(input) match { + case Some(data) => Some(resolveType(data)) + case None => None + } /** * A utility method to resolve a parsed JSON list into objects or @@ -46,9 +53,9 @@ object JSON extends Parser { def resolveType(input: List[Any]): Any = { var objMap = Map[String, Any]() - if(input.forall { - case (key: String, value : List[Any]) => - objMap = objMap + key -> resolveType(value) + if (input.forall { + case (key: String, value: List[_]) => + objMap += (key -> resolveType(value)) true case _ => false }) objMap |