Lines Matching defs:string
31 #include <string> // string, stoi, to_string
166 #include <string> // string
187 #include <string> // to_string
204 #include <string> // string
2861 string, ///< string value
2874 - order: null < boolean < number < object < array < string < binary
2877 - binary is represented as a b"" string in python and directly comparable to a
2878 string; however, making a binary array directly comparable with a string would
2890 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */,
2942 @brief replace all occurrences of a substring by another string
2944 @param[in,out] s the string to manipulate; changed so that all
2947 @param[in] t the string to replace @a f
2949 @pre The search string @a f must not be empty. **This precondition is
2967 * @brief string escaping as described in RFC 6901 (Sect. 4)
2968 * @param[in] s string to escape
2969 * @return escaped string
2982 * @brief string unescaping as described in RFC 6901 (Sect. 4)
2983 * @param[in] s string to unescape
2984 * @return unescaped string
3357 #include <string> // string
3385 class StringType = std::string, class BooleanType = bool,
3395 /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
4107 // checks whether T is a [cv] char */[cv] char[] C string
4150 #include <string> // string
4276 template<typename OutStringType = std::string, typename... Args>
4303 /// returns the explanatory string
4316 static std::string name(const std::string& ename, int id_)
4321 static std::string diagnostics(std::nullptr_t /*leaf_element*/)
4327 static std::string diagnostics(const BasicJsonType* leaf_element)
4330 std::vector<std::string> tokens;
4362 case value_t::string: // LCOV_EXCL_LINE
4379 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4380 [](const std::string & a, const std::string & b)
4407 @param[in] what_arg the explanatory string
4411 static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
4413 std::string w = concat(exception::name("parse_error", id_), "parse error",
4419 static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context)
4421 std::string w = concat(exception::name("parse_error", id_), "parse error",
4442 static std::string position_string(const position_t& pos)
4455 static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
4457 std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
4473 static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
4475 std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
4490 static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
4492 std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
4507 static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
4509 std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
4630 case value_t::string:
4654 JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
4670 JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
4924 case value_t::string:
5021 JSON_THROW(type_error::create(302, concat("type must be string, but is ", j.type_name()), &j));
5068 #include <string> // string
5088 #include <string> // string, to_string
5131 /// a string representation of the array index
5133 /// an empty string (to return a reference for primitive values)
5215 case value_t::string:
5344 * allocated value (e.g., a string). See bug issue
5364 struct external_constructor<value_t::string>
5370 j.m_type = value_t::string;
5379 j.m_type = value_t::string;
5390 j.m_type = value_t::string;
5391 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5593 external_constructor<value_t::string>::construct(j, s);
5599 external_constructor<value_t::string>::construct(j, std::move(s));
5724 j = p.string();
5989 case BasicJsonType::value_t::string:
6061 #include <string> // char_traits, string
6084 #include <string> // string, char_traits
6577 #include <string> // string
6643 @brief a string value was read
6644 @param[in] val string value
6646 @note It is safe to move the passed string value.
6648 virtual bool string(string_t& val) = 0;
6670 @note It is safe to move the passed string.
6702 const std::string& last_token,
6785 bool string(string_t& val)
6852 bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
6969 bool string(string_t& val)
7102 bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/,
7254 bool string(string_t& /*unused*/)
7289 bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/)
7315 #include <string> // char_traits, string
7345 value_string, ///< a string -- use get_string() for actual value
7376 return "string literal";
7532 error_message = "invalid string: ill-formed UTF-8 byte";
7541 @brief scan a string literal
7543 This function scans a string according to Sect. 7 of RFC 8259. While
7547 string.
7549 @return token_type::value_string if string could be successfully scanned,
7568 // end of file while parsing string
7571 error_message = "invalid string: missing closing quote";
7627 error_message = "invalid string: '\\u' must be followed by 4 hex digits";
7641 error_message = "invalid string: '\\u' must be followed by 4 hex digits";
7661 error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7667 error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7675 error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7716 error_message = "invalid string: forbidden character after backslash";
7726 error_message = "invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7732 error_message = "invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7738 error_message = "invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7744 error_message = "invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7750 error_message = "invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7756 error_message = "invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7762 error_message = "invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7768 error_message = "invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7774 error_message = "invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7780 error_message = "invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7786 error_message = "invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7792 error_message = "invalid string: control character U+000B (VT) must be escaped to \\u000B";
7798 error_message = "invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7804 error_message = "invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7810 error_message = "invalid string: control character U+000E (SO) must be escaped to \\u000E";
7816 error_message = "invalid string: control character U+000F (SI) must be escaped to \\u000F";
7822 error_message = "invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7828 error_message = "invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7834 error_message = "invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7840 error_message = "invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7846 error_message = "invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7852 error_message = "invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7858 error_message = "invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7864 error_message = "invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7870 error_message = "invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7876 error_message = "invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7882 error_message = "invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7888 error_message = "invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7894 error_message = "invalid string: control character U+001C (FS) must be escaped to \\u001C";
7900 error_message = "invalid string: control character U+001D (GS) must be escaped to \\u001D";
7906 error_message = "invalid string: control character U+001E (RS) must be escaped to \\u001E";
7912 error_message = "invalid string: control character U+001F (US) must be escaped to \\u001F";
8134 error_message = "invalid string: ill-formed UTF-8 byte";
8233 This function scans a string according to Sect. 6 of RFC 8259.
8258 During scanning, the read bytes are stored in token_buffer. This string is
8730 /// return current string value (implicitly resets the token; useful only once)
8749 std::string get_token_string() const
8752 std::string result;
8765 result.push_back(static_cast<std::string::value_type>(c));
8867 // string
8886 // string literals)
8914 /// raw input token string (for error messages)
8950 #include <string> // string
8984 decltype(std::declval<T&>().string(std::declval<String&>()));
9010 std::declval<std::size_t>(), std::declval<const std::string&>(),
9078 "Missing/invalid function: bool string(string_t&)");
9095 "std::string&, const exception&)");
9261 @brief Parses a C-style string from the BSON input.
9262 @param[in,out] result A reference to the string variable where the read
9263 string is to be stored.
9264 @return `true` if the \x00-byte indicating the end of the string was
9286 @brief Parses a zero-terminated string of length @a len from the BSON
9289 string to be read.
9290 @param[in,out] result A reference to the string variable where the read
9291 string is to be stored.
9294 @return `true` if the string was successfully parsed
9303 exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr));
9357 case 0x02: // string
9361 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
9407 std::string cr_str{cr.data()};
9641 // UTF-8 string (0x00..0x17 bytes follow)
9666 case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
9667 case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
9668 case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
9669 case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
9670 case 0x7F: // UTF-8 string (indefinite length)
9673 return get_cbor_string(s) && sax->string(s);
9975 @brief reads a CBOR string
9978 string length and then copies this number of bytes into a string.
9981 @param[out] result created string
9983 @return whether string creation completed
9987 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
9994 // UTF-8 string (0x00..0x17 bytes follow)
10023 case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
10029 case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
10035 case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
10041 case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
10047 case 0x7F: // UTF-8 string (indefinite length)
10065 exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr));
10485 return get_msgpack_string(s) && sax->string(s);
10642 @brief reads a MessagePack string
10645 string length and then copies this number of bytes into a string.
10647 @param[out] result created string
10649 @return whether string creation completed
10653 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, "string")))
10719 exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr));
10910 @brief reads a UBJSON string
10913 indicating a string, or in case of an object key where the 'S' byte can be
10916 @param[out] result created string
10921 @return whether string creation completed
11001 std::string message;
11011 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "string"), nullptr));
11282 std::string message;
11531 return sax->string(s);
11534 case 'S': // string
11537 return get_ubjson_string(s) && sax->string(s);
11582 string_t type = it->second; // sax->string() takes a reference
11583 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
11749 // get size of following number string
11758 // get number string
11770 // parse number string
11891 @brief create a string by reading characters from the input
11896 @param[out] result string created by reading @a len bytes
11898 @return whether string creation completed
11902 the input before we run out of string memory.
11913 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string")))
11973 @return a string representation of the last read byte
11975 std::string get_token_string() const
11979 return std::string{cr.data()};
11986 @return a message string to use in the parse_error exceptions
11988 std::string exception_message(const input_format_t format,
11989 const std::string& detail,
11990 const std::string& context) const
11992 std::string error_msg = "syntax error while parsing ";
12104 #include <string> // string
12419 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
12564 std::string exception_message(const token_type expected, const std::string& context)
12566 std::string error_msg = "syntax error ";
12645 string). It's only purpose is to allow the iterator/const_iterator classes
12905 case value_t::string:
13008 case value_t::string:
13046 case value_t::string:
13087 case value_t::string:
13129 case value_t::string:
13182 case value_t::string:
13233 case value_t::string:
13274 case value_t::string:
13319 case value_t::string:
13378 case value_t::string:
13454 case value_t::string:
13485 case value_t::string:
13696 #include <string> // string
13713 /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
13747 /// @brief return a string representation of the JSON pointer
13759 /// @brief return a string representation of the JSON pointer
13768 /// @brief write string representation of the JSON pointer to stream
13891 @throw out_of_range.404 if string @a s could not be converted to an integer
13915 if (p == p_end // invalid input or empty string
14000 case detail::value_t::string:
14081 case detail::value_t::string:
14132 case detail::value_t::string:
14188 case detail::value_t::string:
14239 case detail::value_t::string:
14318 case detail::value_t::string:
14339 @brief split the string input to reference tokens
14351 // special case: empty reference string -> no reference tokens
14357 // check if nonempty reference string begins with slash
14364 // - slash: position of the last read slash (or end of string)
14409 @param[in] reference_string the reference string to the current value
14431 // iterate array and use index as reference string
14450 // iterate object and use keys as reference string
14460 case detail::value_t::string:
14469 // add primitive value with its reference string
14540 /// @brief compares JSON pointer and string for equality
14562 /// @brief compares JSON pointer and string for equality
14569 /// @brief compares string and JSON pointer for equality
14583 /// @brief compares JSON pointer and string for inequality
14590 /// @brief compares string and JSON pointer for inequality
14781 #include <string> // string
14804 #include <string> // basic_string
14987 case value_t::string:
15139 case value_t::string:
15141 // step 1: write control byte and the string length
15142 const auto N = j.m_value.string->size();
15170 // step 2: write the string
15172 reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
15173 j.m_value.string->size());
15462 case value_t::string:
15464 // step 1: write control byte and the string length
15465 const auto N = j.m_value.string->size();
15490 // step 2: write the string
15492 reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
15493 j.m_value.string->size());
15533 // step 1: write control byte and the byte string length
15602 // step 2: write the byte string
15698 case value_t::string:
15704 write_number_with_ubjson_prefix(j.m_value.string->size(), true, use_bjdata);
15706 reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
15707 j.m_value.string->size());
15920 @return The size of the BSON-encoded string in @a value
15928 @brief Writes a BSON element with key @a name and string value @a value
16106 case value_t::string:
16107 return header_size + calc_bson_string_size(*j.m_value.string);
16153 case value_t::string:
16154 return write_bson_string(name, *j.m_value.string);
16504 case value_t::string:
16777 #include <string> // string, char_traits
17684 // says "value is converted to a string as if by std::sprintf in the default ("C") locale"
17979 - floating-point numbers are converted to a string using `"%g"` format
18131 case value_t::string:
18134 dump_escaped(*val.m_value.string, ensure_ascii);
18262 @brief dump escaped string
18264 Escape a string by replacing certain special characters by a sequence of an
18267 representation. The escaped string is written to output stream @a o.
18269 @param[in] s the string to escape
18273 @complexity Linear in the length of string @a s.
18449 // continue processing the string
18473 // we finished processing the string
18484 // we finish reading, but do not accept: string was incomplete
18489 JSON_THROW(type_error::create(316, concat("incomplete UTF-8 string; last byte: 0x", hex_bytes(static_cast<std::uint8_t>(s.back() | 0))), nullptr));
18561 static std::string hex_bytes(std::uint8_t byte)
18563 std::string result = "FF";
18647 // jump to the end to generate the string from backward,
18764 @brief check whether a string is UTF-8 encoded
18766 The function checks each byte of a string whether it is UTF-8 encoded. The
18768 be called initially with state 0 (accept). State 1 means the string must
18769 be rejected, because the current byte is not allowed. If the string is
18770 completely processed, but the state is non-zero, the string ended
18859 /// string buffer
18864 /// the indentation string
19262 - If `m_type == value_t::string`, then `m_value.string != nullptr`.
19431 result["version"]["string"] =
19521 /// @brief a type for a string
19587 string | string | pointer to @ref string_t
19607 /// string (stored with pointer to save storage)
19608 string_t* string;
19647 case value_t::string:
19649 string = create<string_t>("");
19703 json_value(const string_t& value) : string(create<string_t>(value)) {}
19706 json_value(string_t&& value) : string(create<string_t>(std::move(value))) {}
19801 case value_t::string:
19804 std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
19805 std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
19854 JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr);
19895 case value_t::string:
20042 case value_t::string:
20075 // element is a string
20108 std::move(*((*element.m_value.array)[0].m_value.string)),
20219 case value_t::string:
20264 case value_t::string:
20266 m_value = *first.m_object->m_value.string;
20332 case value_t::string:
20334 m_value = *other.m_value.string;
20534 /// @brief return whether value is a string
20538 return m_type == value_t::string;
20604 /// get a pointer to the value (string)
20607 return is_string() ? m_value.string : nullptr;
20610 /// get a pointer to the value (string)
20613 return is_string() ? m_value.string : nullptr;
20761 associative containers such as `std::unordered_map<std::string\,
21026 ambiguities as these types implicitly convert to `std::string`.
21032 string is requested); see example below
21040 associative containers such as `std::unordered_map<std::string\,
21302 JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this));
21317 JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this));
21355 JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this));
21372 JSON_THROW(type_error::create(305, detail::concat("cannot use operator[] with a string argument with ", type_name()), this));
21611 case value_t::string:
21622 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
21623 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21624 m_value.string = nullptr;
21681 case value_t::string:
21693 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
21694 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21695 m_value.string = nullptr;
22097 case value_t::string:
22136 case value_t::string:
22170 case value_t::string:
22225 case value_t::string:
22227 m_value.string->clear();
22699 swap(*(m_value.string), other);
22767 case value_t::string: \
22768 return (*lhs.m_value.string) op (*rhs.m_value.string); \
23326 /// @brief return the type as string
23339 case value_t::string:
23340 return "string";
23852 const auto get_op = [](const std::string & op)
23938 case value_t::string: // LCOV_EXCL_LINE
23989 const auto get_value = [&val](const std::string & op,
23990 const std::string & member,
24002 // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
24006 // check if result is of type string
24009 // NOLINTNEXTLINE(performance-inefficient-string-concatenation)
24010 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg, " must have string member '", member, "'"), &val));
24024 const auto op = get_value("op", "op", true).template get<std::string>();
24025 const auto path = get_value(op, "path", true).template get<std::string>();
24051 const auto from_path = get_value("move", "from", true).template get<std::string>();
24068 const auto from_path = get_value("copy", "from", true).template get<std::string>();
24128 const std::string& path = "")
24238 case value_t::string:
24301 std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j)
24311 /// @brief user-defined string literal for JSON values
24319 /// @brief user-defined string literal for JSON pointer
24324 return nlohmann::json::json_pointer(std::string(s, n));