String iterators are regular `char` pointers.
@note `string` member functions do not validate
- any UTF-8 byte sequences passed to them.
+ any UTF-8 byte sequences passed to them.
@par Thread Safety
@par Exception Safety
No-throw guarantee.
*/
- ~string()
+ ~string() noexcept
{
impl_.destroy(sp_);
}
This is more efficient than move construction, when
it is known that the moved-from object will be
immediately destroyed afterwards.
-
+
@par Complexity
Constant.
using move semantics. Ownership of the underlying
memory is transferred.
The container acquires shared ownership of the
- @ref memory_resource used by `other`. After construction,
+ @ref memory_resource used by `other`. After construction,
the moved-from string behaves as if newly
constructed with its current memory resource.
-
+
@par Complexity
Constant.
storage_ptr sp);
/** Constructor.
-
+
Construct the contents with those of a
string view. This view can contain
null characters.
{
if(pos >= size())
detail::throw_out_of_range(
- BOOST_CURRENT_LOCATION);
+ BOOST_JSON_SOURCE_POS);
return impl_.data()[pos];
}
{
if(pos >= size())
detail::throw_out_of_range(
- BOOST_CURRENT_LOCATION);
+ BOOST_JSON_SOURCE_POS);
return impl_.data()[pos];
}
Constant.
@par Precondition
-
+
@code
pos >= size
@endcode
/** Return the underlying character array directly.
Returns a pointer to the underlying array
- serving as storage.
-
+ serving as storage.
+
@note The value returned is such that
the range `{data(), data() + size())` is always a
- valid range, even if the container is empty.
+ valid range, even if the container is empty.
The value returned from
this function is never equal to `nullptr`.
return {data(), size()};
}
+#if ! defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
+ /** Convert to a `std::string_view` referring to the string.
+
+ Returns a string view to the underlying character string. The size of
+ the view does not include the null terminator.
+
+ This overload is not defined when `BOOST_NO_CXX17_HDR_STRING_VIEW`
+ is defined.
+
+ @par Complexity
+
+ Constant.
+ */
+ operator std::string_view() const noexcept
+ {
+ return {data(), size()};
+ }
+#endif
+
//------------------------------------------------------
//
// Iterators
corresponds to the last character of the
non-reversed container.
If the container is empty, @ref rend() is returned.
-
+
@par Complexity
Constant.
corresponds to the last character of the
non-reversed container.
If the container is empty, @ref rend() is returned.
-
+
@par Complexity
Constant.
corresponds to the last character of the
non-reversed container.
If the container is empty, @ref crend() is returned.
-
+
@par Complexity
Constant.
Returns the pointed-to character that corresponds
to the character preceding the first character of
- the non-reversed container.
+ the non-reversed container.
This character acts as a placeholder, attempting
to access it results in undefined behavior.
-
+
@par Complexity
Constant.
Returns the pointed-to character that corresponds
to the character preceding the first character of
- the non-reversed container.
+ the non-reversed container.
This character acts as a placeholder, attempting
to access it results in undefined behavior.
Returns the pointed-to character that corresponds
to the character preceding the first character of
- the non-reversed container.
+ the non-reversed container.
This character acts as a placeholder, attempting
to access it results in undefined behavior.
-
+
@par Complexity
Constant.
This performs a non-binding request to reduce
@ref capacity() to @ref size(). The request may
- or may not be fulfilled.
-
+ or may not be fulfilled.
+
@par Complexity
At most, linear in @ref size().
Erases all characters from the string. After this
call, @ref size() returns zero but @ref capacity()
- is unchanged.
-
+ is unchanged.
+
@par Complexity
Linear in @ref size().
string_view sv);
/** Insert a character.
-
+
Inserts `count` copies of `ch` at the position `pos`.
@par Exception Safety
//------------------------------------------------------
/** Erase characters from the string.
-
+
Erases `num` characters from the string, starting
at `pos`. `num` is determined as the smaller of
`count` and `size() - pos`.
@param count The number of characters to erase.
The default argument for this parameter
is @ref npos.
-
+
@throw std::out_of_range `pos > size()`
*/
BOOST_JSON_DECL
std::size_t count = npos);
/** Erase a character from the string.
-
+
Erases the character at `pos`.
@par Precondition
//------------------------------------------------------
/** Append a character.
-
+
Appends a character to the end of the string.
@par Exception Safety
Strong guarantee.
-
+
@param ch The character to append.
-
+
@throw std::length_error `size() + 1 > max_size()`
*/
BOOST_JSON_DECL
push_back(char ch);
/** Remove the last character.
-
+
Removes a character from the end of the string.
@par Precondition
//------------------------------------------------------
/** Append characters to the string.
-
+
Appends `count` copies of `ch` to the end of
the string.
//------------------------------------------------------
/** Compare a string with the string.
-
+
Let `comp` be
`std::char_traits<char>::compare(data(), sv.data(), std::min(size(), sv.size())`.
If `comp != 0`, then the result is `comp`. Otherwise,
Strong guarantee.
@note All references, pointers, or iterators
- referring to contained elements are invalidated.
+ referring to contained elements are invalidated.
Any past-the-end iterators are also invalidated.
@return `*this`
Strong guarantee.
- @return A `string_view` object referring
+ @return A `string_view` object referring
to `{data() + pos, std::min(count, size() - pos))`.
@param pos The index to being the substring at.
@param dest The string to copy to.
- @param pos The index to begin copying from. The
+ @param pos The index to begin copying from. The
default argument for this parameter is `0`.
@throw std::out_of_range `pos > max_size()`
//------------------------------------------------------
/** Change the size of the string.
-
+
Resizes the string to contain `count` characters.
If `count > size()`, characters with the value `0`
are appended. Otherwise, `size()` is reduced
the contents are logically swapped by making a copy,
which can throw. In this case all iterators and
references are invalidated.
-
+
@par Effects
@code
lhs.swap( rhs );
//------------------------------------------------------
/** Find the first occurrence of a string within the string.
-
+
Returns the lowest index `idx` greater than or equal
to `pos` where each element of `sv` is equal to
that of `{begin() + idx, begin() + idx + sv.size())`
}
/** Find the first occurrence of a character within the string.
-
+
Returns the index corrosponding to the first
occurrence of `ch` within `{begin() + pos, end())`
if it exists, and @ref npos otherwise.
Linear.
- @return The first occurrence of `ch` within the
+ @return The first occurrence of `ch` within the
string starting at the index `pos`, or @ref npos
if none exists.
Linear.
- @return The last occurrence of any of the
+ @return The last occurrence of any of the
characters within `sv` within the string starting
before or at the index `pos`, or @ref npos if
none exists.
Linear.
- @return The last occurrence of a character that
+ @return The last occurrence of a character that
is not equal to `ch` before or at the index `pos`,
or @ref npos if none exists.
operator()(::boost::json::string const& js) const noexcept
{
return ::boost::json::detail::digest(
- js.data(), js.size(), salt_);
+ js.begin(), js.end(), salt_);
}
private: