8000 Fixed basictests · JavaScriptExpert/simdjson@abb0bf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit abb0bf9

Browse files
committed
Fixed basictests
1 parent 8f3ddd3 commit abb0bf9

File tree

5 files changed

+159
-122
lines changed

5 files changed

+159
-122
lines changed

include/simdjson/document.h

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ class document::element : protected internal::tape_ref {
413413
really_inline bool is_number() const noexcept;
414414
/** Whether this is a JSON integer (e.g. 1 or -1, but *not* 1.0 or 1e2) */
415415
really_inline bool is_integer() const noexcept;
416+
/** Whether this is a JSON integer in [9223372036854775808, 18446744073709551616)
417+
* that is, a value too large for a signed 64-bit integer, but that still fits
418+
* in a 64-bit word. Note that is_integer() is true when is_unsigned_integer()
419+
* is true.*/
420+
really_inline bool is_unsigned_integer() const noexcept;
416421
/** Whether this is a JSON number but not an integer */
417422
really_inline bool is_float() const noexcept;
418423
/** Whether this is a JSON string (e.g. "abc") */
@@ -889,17 +894,33 @@ class document::object : protected internal::tape_ref {
889894
/**
890895
* Get the value associated with the given key.
891896
*
892-
* Note: The key will be matched against **unescaped** JSON:
893-
*
894-
* document::parser parser;
895-
* parser.parse(R"({ "a\n": 1 })")["a\n"].as_uint64_t().value == 1
896-
* parser.parse(R"({ "a\n": 1 })")["a\\n"].as_uint64_t().error == NO_SUCH_FIELD
897+
* Note: The key will be matched against **unescaped** JSON.
897898
*
898899
* @return The value associated with this field, or:
899900
* - NO_SUCH_FIELD if the field does not exist in the object
900901
*/
901902
inline element_result at_key(const char *s) const noexcept;
902903

904+
/**
905+
* Get the value associated with the given key, the provided key is
906+
* considered to have length characters.
907+
*
908+
* Note: The key will be matched against **unescaped** JSON.
909+
*
910+
* @return The value associated with this field, or:
911+
* - NO_SUCH_FIELD if the field does not exist in the object
912+
*/
913+
inline element_result at_key(const char *s, size_t length) const noexcept;
914+
/**
915+
* Get the value associated with the given key in a case-insensitive manner.
916+
*
917+
* Note: The key will be matched against **unescaped** JSON.
918+
*
919+
* @return The value associated with this field, or:
920+
* - NO_SUCH_FIELD if the field does not exist in the object
921+
*/
922+
inline element_result at_key_case_insensitive(const char *s) const noexcept;
923+
903924
private:
904925
really_inline object(const document *_doc, size_t _json_index) noexcept;
905926
friend class document::element;

include/simdjson/inline/document.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,16 @@ inline document::element_result document::object::at(std::string_view json_point
783783

784784
return child;
785785
}
786+
inline document::element_result document::object::at_key(const char *key, size_t length) const noexcept {
787+
iterator end_field = end();
788+
for (iterator field = begin(); field != end_field; ++field) {
789+
std::string_view v{field.key()};
790+
if ((v.size() == length) && (!memcmp(v.data(), key, length))) {
791+
return field.value();
792+
}
793+
}
794+
return NO_SUCH_FIELD;
795+
}
786796
inline document::element_result document::object::at_key(std::string_view key) const noexcept {
787797
iterator end_field = end();
788798
for (iterator field = begin(); field != end_field; ++field) {
@@ -801,7 +811,18 @@ inline document::element_result document::object::at_key(const char *key) const
801811
}
802812
return NO_SUCH_FIELD;
803813
}
804-
814+
// In case you wonder why we need this, please see
815+
// https://github.com/simdjson/simdjson/issues/323
816+
// People do seek keys in a case-insensitive manner.
817+
inline document::element_result document::object::at_key_case_insensitive(const char *key) const noexcept {
818+
iterator end_field = end();
819+
for (iterator field = begin(); field != end_field; ++field) {
820+
if (!simdjson_strcasecmp(key, field.key_c_str())) {
821+
return field.value();
822+
}
823+
}
824+
return NO_SUCH_FIELD;
825+
}
805826
//
806827
// document::object::iterator inline implementation
807828
//
@@ -859,6 +880,9 @@ really_inline bool document::element::is_float() const noexcept {
859880
really_inline bool document::element::is_integer() const noexcept {
860881
return type() == internal::tape_type::UINT64 || type() == internal::tape_type::INT64;
861882
}
883+
really_inline bool document::element::is_unsigned_integer() const noexcept {
884+
return type() == internal::tape_type::UINT64;
885+
}
862886
really_inline bool document::element::is_string() const noexcept {
863887
return type() == internal::tape_type::STRING;
864888
}

include/simdjson/inline/padded_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ inline const char *padded_string::data() const noexcept { return data_ptr; }
9898

9999
inline char *padded_string::data() noexcept { return data_ptr; }
100100

101+
inline padded_string::operator std::string() const { return std::string(data(), length()); }
102+
101103
inline simdjson_result<padded_string> padded_string::load(const std::string &filename) noexcept {
102104
// Open the file
103105
std::FILE *fp = std::fopen(filename.c_str(), "rb");

include/simdjson/padded_string.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ struct padded_string final {
8989
**/
9090
char *data() noexcept;
9191

92+
/**
93+
* Create a new std::string with the same content.
94+
*/
95+
operator std::string() const;
96+
9297
/**
9398
* Load this padded string from a file.
9499
*

0 commit comments

Comments
 (0)
0