diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2011-12-22 09:30:03 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2011-12-22 09:30:03 -0800 |
| commit | 47d27af228e574e281184a10f9a98f47ecce32ac (patch) | |
| tree | d5dce2b742d73bb01ea0a9c528d9f996aacf1216 /src/libstd | |
| parent | 8005f0c564311fe2a3c0a72a5f3d4482ad0947e2 (diff) | |
| parent | 07d7f828cd858bed67855e5a5ba24369625a981e (diff) | |
Merge branch 'master' of github.com:graydon/rust
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/json.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/json.rs b/src/libstd/json.rs index e0b559ec747..64ce2794bb4 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -34,6 +34,8 @@ tag json { list(@[json]); /* Variant: dict */ dict(map::hashmap<str,json>); + /* Variant: null */ + null; } /* @@ -63,6 +65,7 @@ fn to_str(j: json) -> str { }); str::concat(["{ ", str::connect(parts, ", "), " }"]) } + null { "null" } } } @@ -233,6 +236,14 @@ fn from_str_bool(s: str) -> (option::t<json>, str) { } } +fn from_str_null(s: str) -> (option::t<json>, str) { + if (str::starts_with(s, "null")) { + (some(null), str::slice(s, 4u, str::byte_len(s))) + } else { + (none, s) + } +} + fn from_str_helper(s: str) -> (option::t<json>, str) { let s = str::trim_left(s); if str::is_empty(s) { ret (none, s); } @@ -243,6 +254,7 @@ fn from_str_helper(s: str) -> (option::t<json>, str) { '{' { from_str_dict(s) } '0' to '9' | '-' | '+' | '.' { from_str_float(s) } 't' | 'f' { from_str_bool(s) } + 'n' { from_str_null(s) } _ { ret (none, s); } } } |
