simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
padded_string_view.h
1#ifndef SIMDJSON_PADDED_STRING_VIEW_H
2#define SIMDJSON_PADDED_STRING_VIEW_H
3
4#include "simdjson/portability.h"
5#include "simdjson/base.h" // for SIMDJSON_PADDING
6#include "simdjson/error.h"
7
8#include <cstring>
9#include <memory>
10#include <string>
11#include <ostream>
12#if SIMDJSON_CPLUSPLUS17
13#include <variant>
14#endif
15
16namespace simdjson {
17
21class padded_string_view : public std::string_view {
22private:
23 size_t _capacity{0};
24
25public:
27 inline padded_string_view() noexcept = default;
28
37 explicit inline padded_string_view(const char* s, size_t len, size_t capacity) noexcept;
39 explicit inline padded_string_view(const uint8_t* s, size_t len, size_t capacity) noexcept;
40#ifdef __cpp_char8_t
41 explicit inline padded_string_view(const char8_t* s, size_t len, size_t capacity) noexcept;
42#endif
50 explicit inline padded_string_view(const std::string &s) noexcept;
51
59 explicit inline padded_string_view(std::string_view s, size_t capacity) noexcept;
60
62 inline size_t capacity() const noexcept;
63
65 inline bool has_sufficient_padding() const noexcept;
66
72 inline bool remove_utf8_bom() noexcept;
73
75 inline size_t padding() const noexcept;
76
77}; // padded_string_view
78
88inline uint32_t get_page_size() noexcept;
89
90#if SIMDJSON_CPLUSPLUS17
98struct padded_input {
104 inline explicit padded_input(std::string_view sv);
110 inline explicit padded_input(const char *data, size_t length);
117 inline explicit padded_input(const std::string &s);
118
124 inline bool is_view() const noexcept;
125
131 inline operator simdjson::padded_string_view() const noexcept;
132
133private:
134 std::variant<simdjson::padded_string_view, simdjson::padded_string> storage;
135 // whether we cross a page boundary and need to allocate a new padded string.
136 static inline bool needs_allocation(const char* buf, size_t len, size_t padding = SIMDJSON_PADDING) noexcept;
137};
138
139#endif // SIMDJSON_CPLUSPLUS17
140
141#if SIMDJSON_EXCEPTIONS
151inline std::ostream& operator<<(std::ostream& out, simdjson_result<padded_string_view> &s) noexcept(false);
152#endif
153
162inline padded_string_view pad(std::string& s) noexcept;
163
172inline padded_string_view pad_with_reserve(std::string& s) noexcept;
173
195inline padded_string_view slice_at(padded_string_view data, char delimiter,
196 size_t block_size, size_t index) noexcept;
197
198} // namespace simdjson
199
200#endif // SIMDJSON_PADDED_STRING_VIEW_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.
bool has_sufficient_padding() const noexcept
check that the view has sufficient padding
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8
padded_string_view slice_at(padded_string_view data, char delimiter, size_t block_size, size_t index) noexcept
Return the index-th document-aligned slice of a delimited stream.
padded_string_view pad_with_reserve(std::string &s) noexcept
Create a padded_string_view from a string.
uint32_t get_page_size() noexcept
Get the system's memory page size.
padded_string_view pad(std::string &s) noexcept
Create a padded_string_view from a string.
constexpr size_t SIMDJSON_PADDING
The amount of padding needed in a buffer to parse JSON.
Definition base.h:42
The result of a simdjson operation that could fail.
Definition error.h:281