simdjson 4.6.4
Ridiculously Fast JSON
Loading...
Searching...
No Matches
simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder Class Reference

A builder for JSON strings representing documents. More...

#include <json_string_builder.h>

Public Member Functions

simdjson_inline string_builder (size_t initial_capacity=DEFAULT_INITIAL_CAPACITY)
 
template<typename number_type , typename = typename std::enable_if<std::is_arithmetic<number_type>::value>::type>
simdjson_inline void append (number_type v) noexcept
 Append number (includes Booleans).
 
simdjson_inline void append (char c) noexcept
 Append character c.
 
simdjson_inline void append_null () noexcept
 Append the string 'null'.
 
simdjson_inline void clear () noexcept
 Clear the content.
 
simdjson_inline void escape_and_append (std::string_view input) noexcept
 Append the std::string_view, after escaping it.
 
simdjson_inline void escape_and_append_with_quotes (std::string_view input) noexcept
 Append the std::string_view surrounded by double quotes, after escaping it.
 
simdjson_inline void escape_and_append_with_quotes (char input) noexcept
 Append the character surrounded by double quotes, after escaping it.
 
simdjson_inline void escape_and_append_with_quotes (const char *input) noexcept
 Append the character surrounded by double quotes, after escaping it.
 
simdjson_inline void append_raw (const char *c) noexcept
 Append the C string directly, without escaping.
 
simdjson_inline void start_object () noexcept
 Append "{" to the buffer.
 
simdjson_inline void end_object () noexcept
 Append "}" to the buffer.
 
simdjson_inline void start_array () noexcept
 Append "[" to the buffer.
 
simdjson_inline void end_array () noexcept
 Append "]" to the buffer.
 
simdjson_inline void append_comma () noexcept
 Append "," to the buffer.
 
simdjson_inline void append_colon () noexcept
 Append ":" to the buffer.
 
template<typename key_type , typename value_type >
simdjson_inline void append_key_value (key_type key, value_type value) noexcept
 Append a key-value pair to the buffer.
 
simdjson_inline void append_raw (std::string_view input) noexcept
 Append the std::string_view directly, without escaping.
 
simdjson_inline void append_raw (const char *str, size_t len) noexcept
 Append len characters from str.
 
simdjson_inline operator std::string () const noexcept(false)
 Creates an std::string from the written JSON buffer.
 
simdjson_inline operator std::string_view () const noexcept(false) simdjson_lifetime_bound
 Creates an std::string_view from the written JSON buffer.
 
simdjson_inline simdjson_result< std::string_view > view () const noexcept
 Returns a view on the written JSON buffer.
 
simdjson_inline simdjson_result< const char * > c_str () noexcept
 Appends the null character to the buffer and returns a pointer to the beginning of the written JSON buffer.
 
simdjson_inline bool validate_unicode () const noexcept
 Return true if the content is valid UTF-8.
 
simdjson_inline size_t size () const noexcept
 Returns the current size of the written JSON buffer.
 

Static Public Attributes

static constexpr size_t DEFAULT_INITIAL_CAPACITY = 1024
 

Detailed Description

A builder for JSON strings representing documents.

This is a low-level builder that is not meant to be used directly by end-users. Though it supports atomic types (Booleans, strings), it does not support composed types (arrays and objects).

Ultimately, this class can support kernel-specific optimizations. E.g., it may make use of SIMD instructions to escape strings faster.

Definition at line 51 of file json_string_builder.h.

Constructor & Destructor Documentation

◆ string_builder()

simdjson_inline simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::string_builder ( size_t  initial_capacity = DEFAULT_INITIAL_CAPACITY)

Definition at line 487 of file json_string_builder-inl.h.

Member Function Documentation

◆ append() [1/2]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append ( char  c)
noexcept

Append character c.

Definition at line 538 of file json_string_builder-inl.h.

◆ append() [2/2]

template<typename number_type , typename >
simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append ( number_type  v)
noexcept

Append number (includes Booleans).

Booleans are mapped to the strings false and true. Numbers are converted to strings abiding by the JSON standard. Floating-point numbers are converted to the shortest string that 'correctly' represents the number.

Definition at line 643 of file json_string_builder-inl.h.

◆ append_colon()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_colon ( )
noexcept

Append ":" to the buffer.

Definition at line 960 of file json_string_builder-inl.h.

◆ append_comma()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_comma ( )
noexcept

Append "," to the buffer.

Definition at line 954 of file json_string_builder-inl.h.

◆ append_key_value()

template<typename key_type , typename value_type >
simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_key_value ( key_type  key,
value_type  value 
)
noexcept

Append a key-value pair to the buffer.

The key is escaped and surrounded by double quotes. The value is escaped if it is a string.

Definition at line 968 of file json_string_builder-inl.h.

◆ append_null()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_null ( )
noexcept

Append the string 'null'.

Definition at line 544 of file json_string_builder-inl.h.

◆ append_raw() [1/3]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_raw ( const char *  c)
noexcept

Append the C string directly, without escaping.

There is no UTF-8 validation.

Definition at line 807 of file json_string_builder-inl.h.

◆ append_raw() [2/3]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_raw ( const char *  str,
size_t  len 
)
noexcept

Append len characters from str.

There is no UTF-8 validation.

Definition at line 820 of file json_string_builder-inl.h.

◆ append_raw() [3/3]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::append_raw ( std::string_view  input)
noexcept

Append the std::string_view directly, without escaping.

There is no UTF-8 validation.

Definition at line 813 of file json_string_builder-inl.h.

◆ c_str()

simdjson_inline simdjson_result< const char * > simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::c_str ( )
noexcept

Appends the null character to the buffer and returns a pointer to the beginning of the written JSON buffer.

Returns an error if memory allocation failed. The result is null-terminated.

The result may not be valid UTF-8 if some of your content was not valid UTF-8. Use validate_unicode() to check the content.

Definition at line 918 of file json_string_builder-inl.h.

◆ clear()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::clear ( )
noexcept

Clear the content.

Definition at line 553 of file json_string_builder-inl.h.

◆ end_array()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::end_array ( )
noexcept

Append "]" to the buffer.

Definition at line 948 of file json_string_builder-inl.h.

◆ end_object()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::end_object ( )
noexcept

Append "}" to the buffer.

Definition at line 936 of file json_string_builder-inl.h.

◆ escape_and_append()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::escape_and_append ( std::string_view  input)
noexcept

Append the std::string_view, after escaping it.

There is no UTF-8 validation.

Definition at line 757 of file json_string_builder-inl.h.

◆ escape_and_append_with_quotes() [1/3]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::escape_and_append_with_quotes ( char  input)
noexcept

Append the character surrounded by double quotes, after escaping it.

There is no UTF-8 validation.

Definition at line 785 of file json_string_builder-inl.h.

◆ escape_and_append_with_quotes() [2/3]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::escape_and_append_with_quotes ( const char *  input)
noexcept

Append the character surrounded by double quotes, after escaping it.

There is no UTF-8 validation.

Definition at line 796 of file json_string_builder-inl.h.

◆ escape_and_append_with_quotes() [3/3]

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::escape_and_append_with_quotes ( std::string_view  input)
noexcept

Append the std::string_view surrounded by double quotes, after escaping it.

There is no UTF-8 validation.

Definition at line 770 of file json_string_builder-inl.h.

◆ operator std::string()

simdjson_inline simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::operator std::string ( ) const

Creates an std::string from the written JSON buffer.

Throws if memory allocation failed

The result may not be valid UTF-8 if some of your content was not valid UTF-8. Use validate_unicode() to check the content if needed.

Definition at line 900 of file json_string_builder-inl.h.

◆ operator std::string_view()

simdjson_inline simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::operator std::string_view ( ) const

Creates an std::string_view from the written JSON buffer.

Throws if memory allocation failed.

The result may not be valid UTF-8 if some of your content was not valid UTF-8. Use validate_unicode() to check the content if needed.

Definition at line 904 of file json_string_builder-inl.h.

◆ size()

simdjson_inline size_t simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::size ( ) const
noexcept

Returns the current size of the written JSON buffer.

If an error occurred, returns 0.

Definition at line 534 of file json_string_builder-inl.h.

◆ start_array()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::start_array ( )
noexcept

Append "[" to the buffer.

Definition at line 942 of file json_string_builder-inl.h.

◆ start_object()

simdjson_inline void simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::start_object ( )
noexcept

Append "{" to the buffer.

Definition at line 930 of file json_string_builder-inl.h.

◆ validate_unicode()

simdjson_inline bool simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::validate_unicode ( ) const
noexcept

Return true if the content is valid UTF-8.

Definition at line 926 of file json_string_builder-inl.h.

◆ view()

simdjson_inline simdjson_result< std::string_view > simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::view ( ) const
noexcept

Returns a view on the written JSON buffer.

Returns an error if memory allocation failed.

The result may not be valid UTF-8 if some of your content was not valid UTF-8. Use validate_unicode() to check the content.

Definition at line 911 of file json_string_builder-inl.h.

Member Data Documentation

◆ DEFAULT_INITIAL_CAPACITY

constexpr size_t simdjson::SIMDJSON_IMPLEMENTATION::builder::string_builder::DEFAULT_INITIAL_CAPACITY = 1024
staticconstexpr

Definition at line 55 of file json_string_builder.h.


The documentation for this class was generated from the following files: