simdjson  3.6.3
Ridiculously Fast JSON
padded_string_view-inl.h
1 #ifndef SIMDJSON_PADDED_STRING_VIEW_INL_H
2 #define SIMDJSON_PADDED_STRING_VIEW_INL_H
3 
4 #include "simdjson/padded_string_view.h"
5 #include "simdjson/error-inl.h"
6 
7 #include <cstring> /* memcmp */
8 
9 namespace simdjson {
10 
11 inline padded_string_view::padded_string_view(const char* s, size_t len, size_t capacity) noexcept
12  : std::string_view(s, len), _capacity(capacity)
13 {
14 }
15 
16 inline padded_string_view::padded_string_view(const uint8_t* s, size_t len, size_t capacity) noexcept
17  : padded_string_view(reinterpret_cast<const char*>(s), len, capacity)
18 {
19 }
20 
21 inline padded_string_view::padded_string_view(const std::string &s) noexcept
22  : std::string_view(s), _capacity(s.capacity())
23 {
24 }
25 
26 inline padded_string_view::padded_string_view(std::string_view s, size_t capacity) noexcept
27  : std::string_view(s), _capacity(capacity)
28 {
29 }
30 
31 inline size_t padded_string_view::capacity() const noexcept { return _capacity; }
32 
33 inline size_t padded_string_view::padding() const noexcept { return capacity() - length(); }
34 
35 inline bool padded_string_view::remove_utf8_bom() noexcept {
36  if(length() < 3) { return false; }
37  if (std::memcmp(data(), "\xEF\xBB\xBF", 3) == 0) {
38  remove_prefix(3);
39  _capacity -= 3;
40  return true;
41  }
42  return false;
43 }
44 
45 #if SIMDJSON_EXCEPTIONS
46 inline std::ostream& operator<<(std::ostream& out, simdjson_result<padded_string_view> &s) noexcept(false) { return out << s.value(); }
47 #endif
48 
49 } // namespace simdjson
50 
51 
52 #endif // SIMDJSON_PADDED_STRING_VIEW_INL_H
User-provided string that promises it has extra padded bytes at the end for use with parser::parse().
bool remove_utf8_bom() noexcept
Remove the UTF-8 Byte Order Mark (BOM) if it exists.
size_t padding() const noexcept
The amount of padding on the string (capacity() - length())
size_t capacity() const noexcept
The number of allocated bytes.
padded_string_view() noexcept=default
Create an empty padded_string_view.
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
std::ostream & operator<<(std::ostream &out, error_code error) noexcept
Write the error message to the output stream.
Definition: error-inl.h:35
The result of a simdjson operation that could fail.
Definition: error.h:214