Skip to content

Commit 99aadb8

Browse files
authored
bug fix..
test with c++14?
1 parent 9db25bf commit 99aadb8

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

claujson.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,34 @@
99

1010
#include "fmt/format.h"
1111

12+
#if __cpp_lib_string_view
13+
14+
#else
15+
16+
claujson::StringView operator""sv(const char* str, size_t sz) {
17+
return claujson::StringView(str, sz);
18+
}
19+
20+
bool operator==(const std::string& str, claujson::StringView sv) {
21+
return claujson::StringView(str.data(), str.size()) == sv;
22+
}
23+
24+
#endif
25+
1226
namespace claujson {
1327
// todo? make Document class? like simdjson?
1428
_Value _Value::empty_value{ nullptr, false }; // valid is false..
1529
const uint64_t _Value::npos = -1; //
30+
#if __cpp_lib_string_view
31+
32+
#else
33+
const uint64_t StringView::npos = -1;
34+
#endif
35+
36+
Log::Info info;
37+
Log::Warning warn;
38+
39+
1640

1741
const uint64_t StructuredPtr::npos = -1;
1842
_Value StructuredPtr::empty_value{ nullptr, false };

claujson.h

-14
Original file line numberDiff line numberDiff line change
@@ -590,20 +590,6 @@ namespace claujson {
590590
/* error.make(__LINE__, StringView(msg)); */ \
591591
} while (false)
592592

593-
#if __cpp_lib_string_view
594-
#else
595-
596-
claujson::StringView operator""sv(const char* str, size_t sz) {
597-
return claujson::StringView(str, sz);
598-
}
599-
600-
uint64_t claujson::StringView::npos = -1;
601-
602-
bool operator==(const std::string& str, claujson::StringView sv) {
603-
return strcmp(str.data(), sv.data()) == 0;
604-
}
605-
606-
#endif
607593
namespace claujson {
608594
claujson::_Value& Convert(claujson::_Value& data, uint64_t buf_idx, uint64_t next_buf_idx, bool key,
609595
char* buf, uint64_t token_idx, bool& err);

claujson_internal.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace claujson {
9494
const char* m_str;
9595
size_t m_len;
9696
public:
97-
static uint64_t npos;
97+
static const uint64_t npos;
9898

9999
friend std::ostream& operator<<(std::ostream& stream, const claujson::StringView& sv) {
100100
stream << sv.data();
@@ -135,11 +135,11 @@ namespace claujson {
135135
};
136136
}
137137

138-
139138
claujson::StringView operator""sv(const char* str, size_t sz);
140139
bool operator==(const std::string& str, claujson::StringView sv);
141140

142141

142+
143143
#endif
144144

145145

@@ -482,8 +482,8 @@ namespace claujson {
482482
return log;
483483
}
484484

485-
static Log::Info info;
486-
static Log::Warning warn;
485+
extern Log::Info info;
486+
extern Log::Warning warn;
487487
extern Log log; // no static..
488488
// inline Error error;
489489

main.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// need C++14~, 64bit..
44
// mainly tested with C++17...
55

6-
#include "mimalloc-new-delete.h"
6+
//#include "mimalloc-new-delete.h"
77

88
#include <iostream>
99
#include <string>
@@ -314,7 +314,9 @@ int main(int argc, char* argv[])
314314
auto b = std::chrono::steady_clock::now();
315315
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(b - a);
316316
std::cout << "total " << dur.count() << "ms\n";
317-
// continue;
317+
return 0;
318+
319+
// continue;
318320
auto c = std::chrono::steady_clock::now();
319321
{
320322
auto z = j.Get().clone();

0 commit comments

Comments
 (0)