simdjson: include/simdjson/padded_string.h Source File

1#ifndef SIMDJSON_PADDED_STRING_H

2#define SIMDJSON_PADDED_STRING_H

3

4#include "simdjson/base.h"

5#include "simdjson/error.h"

6

7#include "simdjson/error-inl.h"

8

9#include <cstring>

10#include <memory>

11#include <string>

12#include <ostream>

13

15

16class padded_string_view;

17

24

42#ifdef __cpp_char8_t

44#endif

50 inline padded_string(const std::string & str_ ) noexcept;

56 inline padded_string(std::string_view sv_) noexcept;

75

81 size_t size() const noexcept;

82

88 size_t length() const noexcept;

89

93 const char *data() const noexcept;

94 const uint8_t *u8data() const noexcept { return static_cast<const uint8_t*>(static_cast<const void*>(data_ptr));}

95

99 char *data() noexcept;

100

109 inline bool append(const char *data, size_t length) noexcept;

110

115

120

139

140 #if defined(_WIN32) && SIMDJSON_CPLUSPLUS17

151 #endif

152

153private:

157

158 size_t viable_size{0};

159 char *data_ptr{nullptr};

160

161};

162

169public:

174

181

186

191

196

201

206

214 inline bool append(const char *newdata, size_t length) noexcept;

215

222 inline bool append(std::string_view sv) noexcept;

223

227 inline size_t length() const noexcept;

228

236

244private:

245 size_t size{0};

246 size_t capacity{0};

247 char *data{nullptr};

248

255 inline bool reserve(size_t additional) noexcept;

256};

257

265inline std::ostream& operator<<(std::ostream& out, const padded_string& s) { return out << s.data(); }

266

267#if SIMDJSON_EXCEPTIONS

277inline std::ostream& operator<<(std::ostream& out, simdjson_result<padded_string> &s) noexcept(false) { return out << s.value(); }

278#endif

279

280}

281

282

284#ifdef __cpp_char8_t

286#endif

287

289namespace internal {

290

291

292

293

294

295

296

297inline char *allocate_padded_buffer(size_t length) noexcept;

298

299}

300}

301

302#endif

Builder for constructing padded_string incrementally.

padded_string convert() noexcept

Convert the current content into a padded_string.

size_t length() const noexcept

Get the current length of the built string.

padded_string build() const noexcept

Build a padded_string from the current content.

bool append(const char *newdata, size_t length) noexcept

Append data to the builder.

padded_string_builder() noexcept

Create a new, empty padded string builder.

User-provided string that promises it has extra padded bytes at the end for use with parser::parse().

The top level simdjson namespace, containing everything the library provides.

String with extra allocation for ease of use with parser::parse()

size_t size() const noexcept

The length of the string.

operator std::string_view() const

Create a std::string_view with the same content.

bool append(const char *data, size_t length) noexcept

Append data to the padded string.

size_t length() const noexcept

The length of the string.

padded_string() noexcept

Create a new, empty padded string.

padded_string & operator=(padded_string &&o) noexcept

Move one padded string into another.

const char * data() const noexcept

The string data.

static simdjson_result< padded_string > load(std::string_view path) noexcept

Load this padded string from a file.

The result of a simdjson operation that could fail.