jsoncons 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/jsoncons/extconf.rb +43 -0
- data/ext/jsoncons/jsoncons.cpp +161 -0
- data/ext/jsoncons/jsoncons.h +10 -0
- data/jsoncons.gemspec +44 -0
- data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
- data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
- data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
- data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
- data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
- data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
- data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
- data/lib/jsoncons/version.rb +5 -0
- data/lib/jsoncons.rb +33 -0
- data/test/jsoncons_test.rb +108 -0
- data/test/test_helper.rb +7 -0
- metadata +268 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
// Copyright 2019 Daniel Parker
|
|
2
|
+
// Distributed under the Boost license, Version 1.0.
|
|
3
|
+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
4
|
+
|
|
5
|
+
// See https://github.com/danielaparker/jsoncons for latest version
|
|
6
|
+
|
|
7
|
+
#ifndef JSONCONS_STRING_VIEW_HPP
|
|
8
|
+
#define JSONCONS_STRING_VIEW_HPP
|
|
9
|
+
|
|
10
|
+
#include <stdexcept>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <vector>
|
|
13
|
+
#include <ostream>
|
|
14
|
+
#include <cmath>
|
|
15
|
+
#include <algorithm> // std::find, std::min, std::reverse
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <iterator>
|
|
18
|
+
#include <exception>
|
|
19
|
+
#include <stdexcept>
|
|
20
|
+
#include <istream> // std::basic_istream
|
|
21
|
+
#include <jsoncons/config/compiler_support.hpp>
|
|
22
|
+
|
|
23
|
+
namespace jsoncons {
|
|
24
|
+
namespace detail {
|
|
25
|
+
|
|
26
|
+
template <class CharT, class Traits = std::char_traits<CharT>>
|
|
27
|
+
class basic_string_view
|
|
28
|
+
{
|
|
29
|
+
private:
|
|
30
|
+
const CharT* data_;
|
|
31
|
+
std::size_t length_;
|
|
32
|
+
public:
|
|
33
|
+
using value_type = CharT;
|
|
34
|
+
using const_reference = const CharT&;
|
|
35
|
+
using traits_type = Traits;
|
|
36
|
+
using size_type = std::size_t;
|
|
37
|
+
static constexpr size_type npos = size_type(-1);
|
|
38
|
+
using const_iterator = const CharT*;
|
|
39
|
+
using iterator = const CharT*;
|
|
40
|
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
|
41
|
+
|
|
42
|
+
constexpr basic_string_view() noexcept
|
|
43
|
+
: data_(nullptr), length_(0)
|
|
44
|
+
{
|
|
45
|
+
}
|
|
46
|
+
constexpr basic_string_view(const CharT* data, std::size_t length)
|
|
47
|
+
: data_(data), length_(length)
|
|
48
|
+
{
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
basic_string_view(const CharT* data)
|
|
52
|
+
: data_(data), length_(Traits::length(data))
|
|
53
|
+
{
|
|
54
|
+
}
|
|
55
|
+
constexpr basic_string_view(const basic_string_view& other) noexcept = default;
|
|
56
|
+
|
|
57
|
+
template <class Tr, class Allocator>
|
|
58
|
+
JSONCONS_CPP14_CONSTEXPR basic_string_view(const std::basic_string<CharT,Tr,Allocator>& s) noexcept
|
|
59
|
+
: data_(s.data()), length_(s.length())
|
|
60
|
+
{
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
JSONCONS_CPP14_CONSTEXPR basic_string_view& operator=( const basic_string_view& view ) noexcept
|
|
64
|
+
{
|
|
65
|
+
data_ = view.data();
|
|
66
|
+
length_ = view.length();
|
|
67
|
+
|
|
68
|
+
return *this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
template <class Allocator>
|
|
72
|
+
explicit operator std::basic_string<CharT,Traits,Allocator>() const
|
|
73
|
+
{
|
|
74
|
+
return std::basic_string<CharT,Traits,Allocator>(data_,length_);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// iterator support
|
|
78
|
+
const_iterator begin() const noexcept
|
|
79
|
+
{
|
|
80
|
+
return data_;
|
|
81
|
+
}
|
|
82
|
+
const_iterator end() const noexcept
|
|
83
|
+
{
|
|
84
|
+
return data_ + length_;
|
|
85
|
+
}
|
|
86
|
+
const_iterator cbegin() const noexcept
|
|
87
|
+
{
|
|
88
|
+
return data_;
|
|
89
|
+
}
|
|
90
|
+
const_iterator cend() const noexcept
|
|
91
|
+
{
|
|
92
|
+
return data_ + length_;
|
|
93
|
+
}
|
|
94
|
+
const_reverse_iterator rbegin() const noexcept
|
|
95
|
+
{
|
|
96
|
+
return const_reverse_iterator(end());
|
|
97
|
+
}
|
|
98
|
+
const_reverse_iterator rend() const noexcept
|
|
99
|
+
{
|
|
100
|
+
return const_reverse_iterator(begin());
|
|
101
|
+
}
|
|
102
|
+
const_reverse_iterator crbegin() const noexcept
|
|
103
|
+
{
|
|
104
|
+
return const_reverse_iterator(end());
|
|
105
|
+
}
|
|
106
|
+
const_reverse_iterator crend() const noexcept
|
|
107
|
+
{
|
|
108
|
+
return const_reverse_iterator(begin());
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// capacity
|
|
112
|
+
|
|
113
|
+
std::size_t size() const
|
|
114
|
+
{
|
|
115
|
+
return length_;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
std::size_t length() const
|
|
119
|
+
{
|
|
120
|
+
return length_;
|
|
121
|
+
}
|
|
122
|
+
size_type max_size() const noexcept
|
|
123
|
+
{
|
|
124
|
+
return length_;
|
|
125
|
+
}
|
|
126
|
+
bool empty() const noexcept
|
|
127
|
+
{
|
|
128
|
+
return length_ == 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// element access
|
|
132
|
+
|
|
133
|
+
const_reference operator[](size_type pos) const
|
|
134
|
+
{
|
|
135
|
+
return data_[pos];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const_reference at(std::size_t pos) const
|
|
139
|
+
{
|
|
140
|
+
if (pos >= length_)
|
|
141
|
+
{
|
|
142
|
+
JSONCONS_THROW(std::out_of_range("pos exceeds length"));
|
|
143
|
+
}
|
|
144
|
+
return data_[pos];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const_reference front() const
|
|
148
|
+
{
|
|
149
|
+
return data_[0];
|
|
150
|
+
}
|
|
151
|
+
const_reference back() const
|
|
152
|
+
{
|
|
153
|
+
return data_[length_-1];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const CharT* data() const
|
|
157
|
+
{
|
|
158
|
+
return data_;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// string operations
|
|
162
|
+
|
|
163
|
+
basic_string_view substr(size_type pos, size_type n=npos) const
|
|
164
|
+
{
|
|
165
|
+
if (pos > length_)
|
|
166
|
+
{
|
|
167
|
+
JSONCONS_THROW(std::out_of_range("pos exceeds size"));
|
|
168
|
+
}
|
|
169
|
+
if (n == npos || pos + n > length_)
|
|
170
|
+
{
|
|
171
|
+
n = length_ - pos;
|
|
172
|
+
}
|
|
173
|
+
return basic_string_view(data_ + pos, n);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
int compare(const basic_string_view& s) const noexcept
|
|
177
|
+
{
|
|
178
|
+
const int rc = Traits::compare(data_, s.data_, (std::min)(length_, s.length_));
|
|
179
|
+
return rc != 0 ? rc : (length_ == s.length_ ? 0 : length_ < s.length_ ? -1 : 1);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
int compare(const CharT* data) const noexcept
|
|
183
|
+
{
|
|
184
|
+
const size_t length = Traits::length(data);
|
|
185
|
+
const int rc = Traits::compare(data_, data, (std::min)(length_, length));
|
|
186
|
+
return rc != 0 ? rc : (length_ == length? 0 : length_ < length? -1 : 1);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
template <class Allocator>
|
|
190
|
+
int compare(const std::basic_string<CharT,Traits,Allocator>& s) const noexcept
|
|
191
|
+
{
|
|
192
|
+
const int rc = Traits::compare(data_, s.data(), (std::min)(length_, s.length()));
|
|
193
|
+
return rc != 0 ? rc : (length_ == s.length() ? 0 : length_ < s.length() ? -1 : 1);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
size_type find(basic_string_view s, size_type pos = 0) const noexcept
|
|
197
|
+
{
|
|
198
|
+
if (pos > length_)
|
|
199
|
+
{
|
|
200
|
+
return npos;
|
|
201
|
+
}
|
|
202
|
+
if (s.length_ == 0)
|
|
203
|
+
{
|
|
204
|
+
return pos;
|
|
205
|
+
}
|
|
206
|
+
const_iterator it = std::search(cbegin() + pos, cend(),
|
|
207
|
+
s.cbegin(), s.cend(), Traits::eq);
|
|
208
|
+
return it == cend() ? npos : std::distance(cbegin(), it);
|
|
209
|
+
}
|
|
210
|
+
size_type find(CharT ch, size_type pos = 0) const noexcept
|
|
211
|
+
{
|
|
212
|
+
return find(basic_string_view(&ch, 1), pos);
|
|
213
|
+
}
|
|
214
|
+
size_type find(const CharT* s, size_type pos, size_type n) const noexcept
|
|
215
|
+
{
|
|
216
|
+
return find(basic_string_view(s, n), pos);
|
|
217
|
+
}
|
|
218
|
+
size_type find(const CharT* s, size_type pos = 0) const noexcept
|
|
219
|
+
{
|
|
220
|
+
return find(basic_string_view(s), pos);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
size_type rfind(basic_string_view s, size_type pos = npos) const noexcept
|
|
224
|
+
{
|
|
225
|
+
if (length_ < s.length_)
|
|
226
|
+
{
|
|
227
|
+
return npos;
|
|
228
|
+
}
|
|
229
|
+
if (pos > length_ - s.length_)
|
|
230
|
+
{
|
|
231
|
+
pos = length_ - s.length_;
|
|
232
|
+
}
|
|
233
|
+
if (s.length_ == 0)
|
|
234
|
+
{
|
|
235
|
+
return pos;
|
|
236
|
+
}
|
|
237
|
+
for (const CharT* p = data_ + pos; true; --p)
|
|
238
|
+
{
|
|
239
|
+
if (Traits::compare(p, s.data_, s.length_) == 0)
|
|
240
|
+
{
|
|
241
|
+
return p - data_;
|
|
242
|
+
}
|
|
243
|
+
if (p == data_)
|
|
244
|
+
{
|
|
245
|
+
return npos;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
size_type rfind(CharT ch, size_type pos = npos) const noexcept
|
|
250
|
+
{
|
|
251
|
+
return rfind(basic_string_view(&ch, 1), pos);
|
|
252
|
+
}
|
|
253
|
+
size_type rfind(const CharT* s, size_type pos, size_type n) const noexcept
|
|
254
|
+
{
|
|
255
|
+
return rfind(basic_string_view(s, n), pos);
|
|
256
|
+
}
|
|
257
|
+
size_type rfind(const CharT* s, size_type pos = npos) const noexcept
|
|
258
|
+
{
|
|
259
|
+
return rfind(basic_string_view(s), pos);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept
|
|
263
|
+
{
|
|
264
|
+
if (pos >= length_ || s.length_ == 0)
|
|
265
|
+
{
|
|
266
|
+
return npos;
|
|
267
|
+
}
|
|
268
|
+
const_iterator it = std::find_first_of
|
|
269
|
+
(cbegin() + pos, cend(), s.cbegin(), s.cend(), Traits::eq);
|
|
270
|
+
return it == cend() ? npos : std::distance (cbegin(), it);
|
|
271
|
+
}
|
|
272
|
+
size_type find_first_of(CharT ch, size_type pos = 0) const noexcept
|
|
273
|
+
{
|
|
274
|
+
return find_first_of(basic_string_view(&ch, 1), pos);
|
|
275
|
+
}
|
|
276
|
+
size_type find_first_of(const CharT* s, size_type pos, size_type n) const noexcept
|
|
277
|
+
{
|
|
278
|
+
return find_first_of(basic_string_view(s, n), pos);
|
|
279
|
+
}
|
|
280
|
+
size_type find_first_of(const CharT* s, size_type pos = 0) const noexcept
|
|
281
|
+
{
|
|
282
|
+
return find_first_of(basic_string_view(s), pos);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept
|
|
286
|
+
{
|
|
287
|
+
if (s.length_ == 0)
|
|
288
|
+
{
|
|
289
|
+
return npos;
|
|
290
|
+
}
|
|
291
|
+
if (pos >= length_)
|
|
292
|
+
{
|
|
293
|
+
pos = 0;
|
|
294
|
+
}
|
|
295
|
+
else
|
|
296
|
+
{
|
|
297
|
+
pos = length_ - (pos+1);
|
|
298
|
+
}
|
|
299
|
+
const_reverse_iterator it = std::find_first_of
|
|
300
|
+
(crbegin() + pos, crend(), s.cbegin(), s.cend(), Traits::eq);
|
|
301
|
+
return it == crend() ? npos : (length_ - 1 - std::distance(crbegin(), it));
|
|
302
|
+
}
|
|
303
|
+
size_type find_last_of(CharT ch, size_type pos = npos) const noexcept
|
|
304
|
+
{
|
|
305
|
+
return find_last_of(basic_string_view(&ch, 1), pos);
|
|
306
|
+
}
|
|
307
|
+
size_type find_last_of(const CharT* s, size_type pos, size_type n) const noexcept
|
|
308
|
+
{
|
|
309
|
+
return find_last_of(basic_string_view(s, n), pos);
|
|
310
|
+
}
|
|
311
|
+
size_type find_last_of(const CharT* s, size_type pos = npos) const noexcept
|
|
312
|
+
{
|
|
313
|
+
return find_last_of(basic_string_view(s), pos);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept
|
|
317
|
+
{
|
|
318
|
+
if (pos >= length_)
|
|
319
|
+
return npos;
|
|
320
|
+
if (s.length_ == 0)
|
|
321
|
+
return pos;
|
|
322
|
+
|
|
323
|
+
const_iterator it = cend();
|
|
324
|
+
for (auto p = cbegin()+pos; p != cend(); ++p)
|
|
325
|
+
{
|
|
326
|
+
if (Traits::find(s.data_, s.length_, *p) == 0)
|
|
327
|
+
{
|
|
328
|
+
it = p;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return it == cend() ? npos : std::distance (cbegin(), it);
|
|
333
|
+
}
|
|
334
|
+
size_type find_first_not_of(CharT ch, size_type pos = 0) const noexcept
|
|
335
|
+
{
|
|
336
|
+
return find_first_not_of(basic_string_view(&ch, 1), pos);
|
|
337
|
+
}
|
|
338
|
+
size_type find_first_not_of(const CharT* s, size_type pos, size_type n) const noexcept
|
|
339
|
+
{
|
|
340
|
+
return find_first_not_of(basic_string_view(s, n), pos);
|
|
341
|
+
}
|
|
342
|
+
size_type find_first_not_of(const CharT* s, size_type pos = 0) const noexcept
|
|
343
|
+
{
|
|
344
|
+
return find_first_not_of(basic_string_view(s), pos);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept
|
|
348
|
+
{
|
|
349
|
+
if (pos >= length_)
|
|
350
|
+
{
|
|
351
|
+
pos = length_ - 1;
|
|
352
|
+
}
|
|
353
|
+
if (s.length_ == 0)
|
|
354
|
+
{
|
|
355
|
+
return pos;
|
|
356
|
+
}
|
|
357
|
+
pos = length_ - (pos+1);
|
|
358
|
+
|
|
359
|
+
const_iterator it = crend();
|
|
360
|
+
for (auto p = crbegin()+pos; p != crend(); ++p)
|
|
361
|
+
{
|
|
362
|
+
if (Traits::find(s.data_, s.length_, *p) == 0)
|
|
363
|
+
{
|
|
364
|
+
it = p;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return it == crend() ? npos : (length_ - 1 - std::distance(crbegin(), it));
|
|
369
|
+
}
|
|
370
|
+
size_type find_last_not_of(CharT ch, size_type pos = npos) const noexcept
|
|
371
|
+
{
|
|
372
|
+
return find_last_not_of(basic_string_view(&ch, 1), pos);
|
|
373
|
+
}
|
|
374
|
+
size_type find_last_not_of(const CharT* s, size_type pos, size_type n) const noexcept
|
|
375
|
+
{
|
|
376
|
+
return find_last_not_of(basic_string_view(s, n), pos);
|
|
377
|
+
}
|
|
378
|
+
size_type find_last_not_of(const CharT* s, size_type pos = npos) const noexcept
|
|
379
|
+
{
|
|
380
|
+
return find_last_not_of(basic_string_view(s), pos);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
friend std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>& os, const basic_string_view& sv)
|
|
384
|
+
{
|
|
385
|
+
os.write(sv.data_,sv.length_);
|
|
386
|
+
return os;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// ==
|
|
391
|
+
template<class CharT,class Traits>
|
|
392
|
+
bool operator==(const basic_string_view<CharT,Traits>& lhs,
|
|
393
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
394
|
+
{
|
|
395
|
+
return lhs.compare(rhs) == 0;
|
|
396
|
+
}
|
|
397
|
+
template<class CharT,class Traits,class Allocator>
|
|
398
|
+
bool operator==(const basic_string_view<CharT,Traits>& lhs,
|
|
399
|
+
const std::basic_string<CharT,Traits,Allocator>& rhs) noexcept
|
|
400
|
+
{
|
|
401
|
+
return lhs.compare(rhs) == 0;
|
|
402
|
+
}
|
|
403
|
+
template<class CharT,class Traits,class Allocator>
|
|
404
|
+
bool operator==(const std::basic_string<CharT,Traits,Allocator>& lhs,
|
|
405
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
406
|
+
{
|
|
407
|
+
return rhs.compare(lhs) == 0;
|
|
408
|
+
}
|
|
409
|
+
template<class CharT,class Traits>
|
|
410
|
+
bool operator==(const basic_string_view<CharT,Traits>& lhs,
|
|
411
|
+
const CharT* rhs) noexcept
|
|
412
|
+
{
|
|
413
|
+
return lhs.compare(rhs) == 0;
|
|
414
|
+
}
|
|
415
|
+
template<class CharT,class Traits>
|
|
416
|
+
bool operator==(const CharT* lhs,
|
|
417
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
418
|
+
{
|
|
419
|
+
return rhs.compare(lhs) == 0;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// !=
|
|
423
|
+
template<class CharT,class Traits>
|
|
424
|
+
bool operator!=(const basic_string_view<CharT,Traits>& lhs,
|
|
425
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
426
|
+
{
|
|
427
|
+
return lhs.compare(rhs) != 0;
|
|
428
|
+
}
|
|
429
|
+
template<class CharT,class Traits,class Allocator>
|
|
430
|
+
bool operator!=(const basic_string_view<CharT,Traits>& lhs,
|
|
431
|
+
const std::basic_string<CharT,Traits,Allocator>& rhs) noexcept
|
|
432
|
+
{
|
|
433
|
+
return lhs.compare(rhs) != 0;
|
|
434
|
+
}
|
|
435
|
+
template<class CharT,class Traits,class Allocator>
|
|
436
|
+
bool operator!=(const std::basic_string<CharT,Traits,Allocator>& lhs,
|
|
437
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
438
|
+
{
|
|
439
|
+
return rhs.compare(lhs) != 0;
|
|
440
|
+
}
|
|
441
|
+
template<class CharT,class Traits>
|
|
442
|
+
bool operator!=(const basic_string_view<CharT,Traits>& lhs,
|
|
443
|
+
const CharT* rhs) noexcept
|
|
444
|
+
{
|
|
445
|
+
return lhs.compare(rhs) != 0;
|
|
446
|
+
}
|
|
447
|
+
template<class CharT,class Traits>
|
|
448
|
+
bool operator!=(const CharT* lhs,
|
|
449
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
450
|
+
{
|
|
451
|
+
return rhs.compare(lhs) != 0;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// <=
|
|
455
|
+
template<class CharT,class Traits>
|
|
456
|
+
bool operator<=(const basic_string_view<CharT,Traits>& lhs,
|
|
457
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
458
|
+
{
|
|
459
|
+
return lhs.compare(rhs) <= 0;
|
|
460
|
+
}
|
|
461
|
+
template<class CharT,class Traits,class Allocator>
|
|
462
|
+
bool operator<=(const basic_string_view<CharT,Traits>& lhs,
|
|
463
|
+
const std::basic_string<CharT,Traits,Allocator>& rhs) noexcept
|
|
464
|
+
{
|
|
465
|
+
return lhs.compare(rhs) <= 0;
|
|
466
|
+
}
|
|
467
|
+
template<class CharT,class Traits,class Allocator>
|
|
468
|
+
bool operator<=(const std::basic_string<CharT,Traits,Allocator>& lhs,
|
|
469
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
470
|
+
{
|
|
471
|
+
return rhs.compare(lhs) >= 0;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// <
|
|
475
|
+
template<class CharT,class Traits>
|
|
476
|
+
bool operator<(const basic_string_view<CharT,Traits>& lhs,
|
|
477
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
478
|
+
{
|
|
479
|
+
return lhs.compare(rhs) < 0;
|
|
480
|
+
}
|
|
481
|
+
template<class CharT,class Traits,class Allocator>
|
|
482
|
+
bool operator<(const basic_string_view<CharT,Traits>& lhs,
|
|
483
|
+
const std::basic_string<CharT,Traits,Allocator>& rhs) noexcept
|
|
484
|
+
{
|
|
485
|
+
return lhs.compare(rhs) < 0;
|
|
486
|
+
}
|
|
487
|
+
template<class CharT,class Traits,class Allocator>
|
|
488
|
+
bool operator<(const std::basic_string<CharT,Traits,Allocator>& lhs,
|
|
489
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
490
|
+
{
|
|
491
|
+
return rhs.compare(lhs) > 0;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// >=
|
|
495
|
+
template<class CharT,class Traits>
|
|
496
|
+
bool operator>=(const basic_string_view<CharT,Traits>& lhs,
|
|
497
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
498
|
+
{
|
|
499
|
+
return lhs.compare(rhs) >= 0;
|
|
500
|
+
}
|
|
501
|
+
template<class CharT,class Traits,class Allocator>
|
|
502
|
+
bool operator>=(const basic_string_view<CharT,Traits>& lhs,
|
|
503
|
+
const std::basic_string<CharT,Traits,Allocator>& rhs) noexcept
|
|
504
|
+
{
|
|
505
|
+
return lhs.compare(rhs) >= 0;
|
|
506
|
+
}
|
|
507
|
+
template<class CharT,class Traits,class Allocator>
|
|
508
|
+
bool operator>=(const std::basic_string<CharT,Traits,Allocator>& lhs,
|
|
509
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
510
|
+
{
|
|
511
|
+
return rhs.compare(lhs) <= 0;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// >
|
|
515
|
+
template<class CharT,class Traits>
|
|
516
|
+
bool operator>(const basic_string_view<CharT,Traits>& lhs,
|
|
517
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
518
|
+
{
|
|
519
|
+
return lhs.compare(rhs) > 0;
|
|
520
|
+
}
|
|
521
|
+
template<class CharT,class Traits,class Allocator>
|
|
522
|
+
bool operator>(const basic_string_view<CharT,Traits>& lhs,
|
|
523
|
+
const std::basic_string<CharT,Traits,Allocator>& rhs) noexcept
|
|
524
|
+
{
|
|
525
|
+
return lhs.compare(rhs) > 0;
|
|
526
|
+
}
|
|
527
|
+
template<class CharT,class Traits,class Allocator>
|
|
528
|
+
bool operator>(const std::basic_string<CharT,Traits,Allocator>& lhs,
|
|
529
|
+
const basic_string_view<CharT,Traits>& rhs) noexcept
|
|
530
|
+
{
|
|
531
|
+
return rhs.compare(lhs) < 0;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
} // namespace detail
|
|
535
|
+
} // namespace jsoncons
|
|
536
|
+
|
|
537
|
+
#endif
|