summaryrefslogtreecommitdiff
path: root/AK/JsonParser.cpp
AgeCommit message (Collapse)Author
2023-04-24AK: Use `JsonArray::append` when parsing arrayCameron Youell
2023-04-24AK: Add new failable `JsonArray::{append/set}` functionsCameron Youell
Move all old usages to the more explicit `JsonArray:must_{append/set}`
2022-12-06Everywhere: Rename to_{string => deprecated_string}() where applicableLinus Groh
This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-10-23AK: Make the JsonParser use the new double parser for numbersdavidot
Because we still support u64 and i64 (on top of i32 and u32) we do still have to parse the number ourself first. Then if we determine that the number is a floating point or is outside of the range of i64 and u64 we fallback and parse it as a double. Before JsonParser had ifdefs guarding the double computation, but it just build when we error on ifdef KERNEL so JsonParser is no longer usable in the Kernel. This can be remedied fairly easily but since it is not needed we #error on that for now.
2022-09-02AK: Allow exponents in JSON double valuesdavidot
This is required for ECMA-404 compliance, but probably not for serenity itself.
2022-07-12Everywhere: Split Error::from_string_literal and Error::from_string_viewsin-ack
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
2022-02-16AK: Fix userland parsing of rounded floating point numbersserenitydev
Parse JSON floating point literals properly, No longer throwing a SyntaxError when the decimal portion of the number exceeds the capacity of u32. Added tests to AK/TestJSON and LibJS/builtins/JSON/JSON.parse
2022-01-19AK: Identify negative zero when parsing Json and represent with a doubleForLoveOfCats
Regardless of the backing type that the number would otherwise parse to, if it is zero and the sign was supposed to be negative then it needs to be a floating point number to represent the correct value.
2021-11-17AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)Andreas Kling
Also add slightly richer parse errors now that we can include a string literal with returned errors. This will allow us to use TRY() when working with JSON data.
2021-09-16AK: Reduce the scope of fraction_string to where it's neededBrian Gianforcaro
pvs-studio flagged this a potential optimization, as we only need to really construct the fraction_string if is_double is true.
2021-07-15AK: Make JsonParser correctly parse unsigned values larger than u32Ali Mohammad Pur
Prior to this, it'd try to stuff them into an i64, which could fail and give us nothing. Even though this is an extension we've made to JSON, the parser should be able to correctly round-trip from whatever our serialiser has generated.
2021-07-05JsonParser: Bring parser more to specstelar7
2021-05-14AK: Use move semantics to avoid copying in JSON parserAndreas Kling
The JSON parser was deep-copying JsonValues left and right, and it was all totally avoidable. :^)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-02-26Everywhere: Remove a bunch of redundant 'AK::' namespace prefixesLinus Groh
This is basically just for consistency, it's quite strange to see multiple AK container types next to each other, some with and some without the namespace prefix - we're 'using AK::Foo;' a lot and should leverage that. :^)
2021-02-08Everywhere: Remove unnecessary headers 4/4Ben Wiederhake
Arbitrarily split up to make git bisect easier. These unnecessary #include's were found by combining an automated tool (which determined likely candidates) and some brain power (which decided whether the #include is also semantically superfluous).
2020-12-21AK: Make JsonParser::parse_number properly parse >32bit intsSahan Fernando
2020-10-06AK: check fractional string has_value() in JsonParserTucker Polomik
Resolves #3670
2020-09-27AK: Remove the ctype adapters and use the actual ctype functions insteadBenoît Lormeau
This finally takes care of the kind-of excessive boilerplate code that were the ctype adapters. On the other hand, I had to link `LibC/ctype.cpp` to the Kernel (for `AK/JsonParser.cpp` and `AK/Format.cpp`). The previous commit actually makes sense now: the `string.h` includes in `ctype.{h,cpp}` would require to link more LibC stuff to the Kernel when it only needs the `_ctype_` array of `ctype.cpp`, and there wasn't any string stuff used in ctype. Instead of all this I could have put static derivatives of `is_any_of()` in the concerned AK files, however that would have meant more boilerplate and workarounds; so I went for the Kernel approach.
2020-08-09AK: Add a GenericLexer and extend the JsonParser with it (#2696)Benoît Lormeau
2020-08-05Unicode: Try s/codepoint/code_point/g againNico Weber
This time, without trailing 's'. Ran: git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05Revert "Unicode: s/codepoint/code_point/g"Nico Weber
This reverts commit ea9ac3155d1774f13ac4e9a96605c0e85a8f299e. It replaced "codepoint" with "code_points", not "code_point".
2020-08-03Unicode: s/codepoint/code_point/gAndreas Kling
Unicode calls them "code points" so let's follow their style.
2020-06-20AK: Fix JsonParser double encoding multibyte utf-8 chararctersLepkoQQ
2020-06-16AK: JsonParser, replace char type to u32 for code pointHüseyin ASLITÜRK
2020-06-13AK: JsonParser improvementsMatthew Olsson
- Parsing invalid JSON no longer asserts Instead of asserting when coming across malformed JSON, JsonParser::parse now returns an Optional<JsonValue>. - Disallow trailing commas in JSON objects and arrays - No longer parse 'undefined', as that is a purely JS thing - No longer allow non-whitespace after anything consumed by the initial parse() call. Examples of things that were valid and no longer are: - undefineddfz - {"foo": 1}abcd - [1,2,3]4 - JsonObject.for_each_member now iterates in original insertion order
2020-06-12AK: Make string-to-number conversion helpers return OptionalAndreas Kling
Get rid of the weird old signature: - int StringType::to_int(bool& ok) const And replace it with sensible new signature: - Optional<int> StringType::to_int() const
2020-06-03AK: JSON, Escape spacial character in string serializationHüseyin ASLITÜRK
2020-04-04AK: Break on end of input in JsonParser::consume_quoted_stringTibor Nagy
Fixes #1599
2020-03-31AK: A few JSON improvementsEmanuel Sprung
* Add double number to object serializer * Handle negative double numbers correctly * Handle \r and \n in quoted strings independently This improves the situation when keys contain \r or \n that currently has the effect that "a\rkey" and "a\nkey" in an JSON object are the same key value.
2020-03-24AK: Fix JsonParser kernel build (no floats/doubles in kernel code)Andreas Kling
2020-03-24AK: Add parsing of JSON double valuesEmanuel Sprung
This patch adds the parsing of double values to the JSON parser. There is another char buffer that get's filled when a "." is present in the number parsing. When number finished, a divider is calculated to transform the number behind the "." to the actual fraction value.
2020-03-08AK: Move memory stuff (fast memcpy, etc) to a separate headerAndreas Kling
Move the "fast memcpy" stuff out of StdLibExtras.h and into Memory.h. This will break a ton of things that were relying on StdLibExtras.h to include a bunch of other headers. Fix will follow immediately after. This makes it possible to include StdLibExtras.h from Types.h, which is the main point of this exercise.
2020-03-01AK: Remove unnecessary casts to size_t, after Vector changesAndreas Kling
Now that Vector uses size_t, we can remove a whole bunch of redundant casts to size_t.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-12-29AK: Fix JSON parser crashing when encountering UTF-8Andreas Kling
The mechanism that caches the most recently seen string for each first character was indexing into the cache using a 'char' subscript. Oops!
2019-12-09AK: Use size_t for the length of stringsAndreas Kling
Using int was a mistake. This patch changes String, StringImpl, StringView and StringBuilder to use size_t instead of int for lengths. Obviously a lot of code needs to change as a result of this.
2019-08-14JsonParser: "" is an empty string, not a null valueAndreas Kling
2019-08-07JsonParser: Scan ahead to find the first special char in quoted stringsAndreas Kling
This allows us to take advantage of the now-optimized (to do memmove()) Vector::append(const T*, int count) for collecting these strings. This is a ~15% speedup on the load_4chan_catalog benchmark.
2019-08-04JsonParser: Fold extract_while() into parse_number()Andreas Kling
It wasn't unsed anywhere else anyway, and this is actually ~1% faster on the load_4chan_catalog benchmark.
2019-08-04JsonParser: Oops, fix build.Andreas Kling
2019-08-04JsonParser: Cache the last seen string starting with each possible charAndreas Kling
Keep a 256-entry string cache during parse to avoid creating some new strings when possible. This cache is far from perfect but very cheap. Since none of the strings are transient, this only costs us a couple of pointers and a bit of ref-count manipulation. The cache hit rate on 4chan_catalog.json is ~33% and the speedup on the load_4chan_catalog benchmark is ~7%.
2019-08-04JsonParser: Some minor optimizationsAndreas Kling
- Return more specific types from parse_array() and parse_object(). - Don't create a throwaway String in extract_while(). - Use a StringView in parse_number() to avoid a throwaway String.
2019-08-04JsonParser: Use Vector<char, 1024> instead of StringBuilder in parsingAndreas Kling
This is a 10-12% speedup on the 4chan thread catalog JSON.
2019-08-04JsonParser: When encountering \uXXXX, just emit a "?" for now.Andreas Kling
2019-08-01JsonParser: Merge the parsing of '\n' and '\r' in quoted stringsAndreas Kling
2019-07-08AK: Add JsonObject::set(key, &&value) overload.Andreas Kling
This dodges a whole bunch of value copying in JsonParser.
2019-06-29Kernel: Change the format of /proc/all to JSON.Andreas Kling
Update ProcessManager, top and WSCPUMonitor to handle the new format. Since the kernel is not allowed to use floating-point math, we now compile the JSON classes in AK without JsonValue::Type::Double support. To accomodate large unsigned ints, I added a JsonValue::Type::UnsignedInt.
2019-06-25JsonParser: Support basic escaped string characters.Andreas Kling
I didn't implement \uXXXX-style escape in this patch. That's a FIXME.