Skip to content

Commit e1b1500

Browse files
committed
Make _padded available without using namespace simdjson
1 parent 2943a1c commit e1b1500

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

include/simdjson/padded_string.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ struct padded_string final {
105105

106106
}; // padded_string
107107

108-
inline padded_string operator "" _padded(const char *str, size_t len) {
109-
return padded_string(str, len);
110-
}
111-
112108
} // namespace simdjson
113109

110+
// This is deliberately outside of simdjson so that people get it without having to use the namespace
111+
inline simdjson::padded_string operator "" _padded(const char *str, size_t len) {
112+
return simdjson::padded_string(str, len);
113+
}
114+
114115
namespace simdjson::internal {
115116

116117
// low-level function to allocate memory with padding so we can read past the

tests/basictests.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,10 @@ namespace document_stream_tests {
409409
simdjson::document::stream s1 = parse_many_stream_return(parser, str);
410410
}
411411

412-
static bool parse_json_message_issue467(char const* message, std::size_t len, size_t expectedcount) {
412+
static bool parse_json_message_issue467(simdjson::padded_string &json, size_t expectedcount) {
413413
simdjson::document::parser parser;
414414
size_t count = 0;
415-
simdjson::padded_string str(message,len);
416-
for (auto [doc, error] : parser.parse_many(str, len)) {
415+
for (auto [doc, error] : parser.parse_many(json)) {
417416
if (error) {
418417
std::cerr << "Failed with simdjson error= " << error << std::endl;
419418
return false;
@@ -429,13 +428,13 @@ namespace document_stream_tests {
429428

430429
bool json_issue467() {
431430
std::cout << "Running " << __func__ << std::endl;
432-
const char * single_message = "{\"error\":[],\"result\":{\"token\":\"xxx\"}}";
433-
const char* two_messages = "{\"error\":[],\"result\":{\"token\":\"xxx\"}}{\"error\":[],\"result\":{\"token\":\"xxx\"}}";
431+
auto single_message = R"({"error":[],"result":{"token":"xxx"}})"_padded;
432+
auto two_messages = R"({"error":[],"result":{"token":"xxx"}}{"error":[],"result":{"token":"xxx"}})"_padded;
434433

435-
if(!parse_json_message_issue467(single_message, strlen(single_message),1)) {
434+
if(!parse_json_message_issue467(single_message, 1)) {
436435
return false;
437436
}
438-
if(!parse_json_message_issue467(two_messages, strlen(two_messages),2)) {
437+
if(!parse_json_message_issue467(two_messages, 2)) {
439438
return false;
440439
}
441440
return true;

0 commit comments

Comments
 (0)