nlib
|
The class for using the member functions of std::string
without constructing std::string
.
More...
#include "nn/nlib/StringView.h"
Public Types | |
typedef char | charT |
Currently a char -type specific class. | |
typedef charT | value_type |
The type for a character. | |
typedef const charT * | pointer |
The type for a character pointer. The same as const_pointer . | |
typedef const charT * | const_pointer |
The type for a character pointer. | |
typedef const charT & | reference |
A reference to a character. The same as const_reference . | |
typedef const charT & | const_reference |
A reference to a character. | |
typedef const_pointer | const_iterator |
A character string iterator. | |
typedef const_iterator | iterator |
A string iterator. The same as const_iterator . | |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
A string reverse iterator. | |
typedef const_reverse_iterator | reverse_iterator |
A string reverse iterator. The same as const_reverse_iterator . | |
typedef size_t | size_type |
A non-negative integer type, currently defined in size_t using typedef . | |
typedef ptrdiff_t | difference_type |
The type returned when you take the difference between iterators. | |
Public Member Functions | |
constexpr | StringView () noexcept |
Instantiates the object with default parameters (default constructor). Initialized as an empty string. | |
StringView (const charT *str) noexcept | |
Initialized to reference str. The string length is calculated internally. | |
StringView (const charT *str, size_type len) noexcept | |
Initializes using the specified calculated string length. | |
const_iterator | begin () const noexcept |
Returns the iterator pointing to the first character. More... | |
const_iterator | end () const noexcept |
Returns the iterator pointing to the character following the last character. More... | |
const_iterator | cbegin () const noexcept |
Returns the iterator pointing to the first character. More... | |
const_iterator | cend () const noexcept |
Returns the iterator pointing to the character following the last character. More... | |
const_reverse_iterator | rbegin () const noexcept |
Returns the reverse iterator pointing to the last character. More... | |
const_reverse_iterator | rend () const noexcept |
Returns the reverse iterator pointing to the character before the first character. More... | |
const_reverse_iterator | crbegin () const noexcept |
Returns the reverse iterator pointing to the last character. More... | |
const_reverse_iterator | crend () const noexcept |
Returns the reverse iterator pointing to the character before the first character. More... | |
size_type | size () const noexcept |
Returns the length of the string. More... | |
size_type | length () const noexcept |
Returns the length of the string. More... | |
size_type | max_size () const noexcept |
Returns the maximum value for the string length. More... | |
bool | empty () const noexcept |
Checks whether it is an empty string. More... | |
const charT & | operator[] (size_type pos) const |
Gets the nth character, where n is specified by pos. More... | |
const charT & | at (size_type pos) const |
Gets the nth character, where n is specified by pos. More... | |
const charT & | front () const |
Gets the first character. More... | |
const charT & | back () const |
Gets the last character. More... | |
const charT * | data () const noexcept |
Returns the pointer to the first character. More... | |
void | clear () noexcept |
Sets an empty string. | |
void | remove_prefix (size_type n) noexcept |
Removes the first n characters. More... | |
void | remove_suffix (size_type n) noexcept |
Removes the last n characters. More... | |
StringView | substr (size_type pos, size_type n=npos) const noexcept |
Returns a substring [pos, pos + n). More... | |
int | compare (const StringView &s) const noexcept |
Compares strings. More... | |
int | compare (const charT *s) const noexcept |
Compares strings. More... | |
bool | starts_with (const StringView &s) const noexcept |
Checks whether the string has s as its prefix. More... | |
bool | starts_with (charT c) const noexcept |
Checks whether the string begins with the character specified for c. More... | |
bool | starts_with (const charT *s) const noexcept |
Checks whether the string has s as its prefix. More... | |
bool | ends_with (const StringView &s) const noexcept |
Checks whether the string has s as its suffix. More... | |
bool | ends_with (charT c) const noexcept |
Checks whether the string ends with the character specified for c. More... | |
bool | ends_with (const charT *s) const noexcept |
Checks whether the string has s as its suffix. More... | |
bool | ToCstring (charT *str, size_type buf_size) const noexcept |
Converts to a C string. More... | |
template<size_type N> | |
bool | ToCstring (charT(&str)[N]) const noexcept |
bool | ToCstring (UniquePtr< charT[]> &str) const noexcept |
errno_t | ToInteger (int32_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (int64_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (uint32_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (uint64_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (int8_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (int16_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (uint8_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToInteger (uint16_t *v, size_type *idx=NULL, int base=10) const noexcept |
Converts a string to an integer. More... | |
errno_t | ToFloat (float *v, size_type *idx=NULL) const noexcept |
Converts a string to a double-precision floating-point number. More... | |
errno_t | ToDouble (double *v, size_type *idx=NULL) const noexcept |
Converts a string to a double-precision floating-point number. More... | |
bool | TrimLeft () noexcept |
Trims the white space from the start of the string. More... | |
bool | TrimRight () noexcept |
Trims the white space from the end of the string. More... | |
void | Trim () noexcept |
Trims the white space from the start and the end of the string. | |
StringView | GetLine () noexcept |
Gets the string from the start to the end of the line. More... | |
bool | Proceed (const StringView &kwd) noexcept |
Advances by the amount of the string length of kwd, providing that the prefix matches kwd. More... | |
bool | Proceed (const charT *kwd) noexcept |
Advances by the amount of the string length of kwd, providing that the prefix matches kwd. More... | |
bool | Proceed (charT ch) noexcept |
Checks the lead character and advances by one character if it matches. More... | |
StringView | GetName () noexcept |
Gets a string that is generally a variable name. More... | |
Static Public Attributes | |
static const size_type | npos = size_type(-1) |
Used the same way as npos of std::string . | |
The class for using the member functions of std::string
without constructing std::string
.
string_view
class proposed for C++1y. Definition at line 28 of file StringView.h.
|
inline |
Gets the nth character, where n is specified by pos.
[in] | pos | An index of a character. |
Definition at line 86 of file StringView.h.
|
inline |
|
inlinenoexcept |
Returns the iterator pointing to the first character.
Definition at line 56 of file StringView.h.
|
inlinenoexcept |
Returns the iterator pointing to the first character.
Definition at line 61 of file StringView.h.
|
inlinenoexcept |
Returns the iterator pointing to the character following the last character.
Definition at line 62 of file StringView.h.
|
noexcept |
Compares strings.
[in] | s | The string to compare with. |
std::strcmp
function.
|
inlinenoexcept |
Compares strings.
[in] | s | The string to compare with. |
std::strcmp
function. Definition at line 126 of file StringView.h.
|
inlinenoexcept |
Returns the reverse iterator pointing to the last character.
Definition at line 66 of file StringView.h.
|
inlinenoexcept |
Returns the reverse iterator pointing to the character before the first character.
Definition at line 67 of file StringView.h.
|
inlinenoexcept |
Returns the pointer to the first character.
Definition at line 92 of file StringView.h.
|
inlinenoexcept |
Checks whether it is an empty string.
true
if it is an empty string. Definition at line 79 of file StringView.h.
|
inlinenoexcept |
Returns the iterator pointing to the character following the last character.
Definition at line 60 of file StringView.h.
|
inlinenoexcept |
Checks whether the string has s as its suffix.
[in] | s | The suffix string. |
true
if it has s as its suffix. Definition at line 136 of file StringView.h.
|
inlinenoexcept |
Checks whether the string ends with the character specified for c.
[in] | c | A character. |
true
if it ends with c. Definition at line 142 of file StringView.h.
|
inlinenoexcept |
Checks whether the string has s as its suffix.
[in] | s | The suffix string. |
true
if it has s as its suffix. Definition at line 143 of file StringView.h.
|
inline |
|
noexcept |
Gets the string from the start to the end of the line.
|
inlinenoexcept |
Gets a string that is generally a variable name.
[a-zA-Z_][a-zA-Z0-9_]*
. The owned object moves beyond the obtained string. Definition at line 283 of file StringView.h.
|
inlinenoexcept |
Returns the length of the string.
Definition at line 74 of file StringView.h.
|
inlinenoexcept |
Returns the maximum value for the string length.
Definition at line 78 of file StringView.h.
|
inline |
Gets the nth character, where n is specified by pos.
[in] | pos | An index of a character. |
Definition at line 82 of file StringView.h.
|
inlinenoexcept |
Advances by the amount of the string length of kwd, providing that the prefix matches kwd.
[in] | kwd | The string to check. |
true
if the prefix matches kwd. Definition at line 178 of file StringView.h.
|
inlinenoexcept |
Advances by the amount of the string length of kwd, providing that the prefix matches kwd.
[in] | kwd | The string to check. |
true
if the prefix matches kwd. Definition at line 184 of file StringView.h.
|
inlinenoexcept |
Checks the lead character and advances by one character if it matches.
[in] | ch | The character to check. |
true
if the lead character is ch. Definition at line 273 of file StringView.h.
|
inlinenoexcept |
Returns the reverse iterator pointing to the last character.
Definition at line 64 of file StringView.h.
|
inlinenoexcept |
Removes the first n characters.
[in] | n | The number of characters to remove. |
Definition at line 99 of file StringView.h.
|
inlinenoexcept |
Removes the last n characters.
[in] | n | The number of characters to remove. |
Definition at line 108 of file StringView.h.
|
inlinenoexcept |
Returns the reverse iterator pointing to the character before the first character.
Definition at line 65 of file StringView.h.
|
inlinenoexcept |
Returns the length of the string.
Definition at line 70 of file StringView.h.
|
inlinenoexcept |
Checks whether the string has s as its prefix.
[in] | s | The prefix string. |
true
if it has s as its prefix. Definition at line 127 of file StringView.h.
|
inlinenoexcept |
Checks whether the string begins with the character specified for c.
[in] | c | A character. |
true
if it begins with c. Definition at line 132 of file StringView.h.
|
inlinenoexcept |
Checks whether the string has s as its prefix.
[in] | s | The prefix string. |
true
if it has s as its prefix. Definition at line 133 of file StringView.h.
Returns a substring [pos, pos + n).
[in] | pos | The first position of the substring. |
[in] | n | Length of the substring. |
Definition at line 117 of file StringView.h.
Converts to a C string.
[out] | str | The buffer where the C string is stored. |
[in] | buf_size | The size of the buffer (including the null character). |
true
if successful, and false
if the buffer is not large enough.
|
inlinenoexcept |
N | The size of the buffer (including the null character). |
[in] | str | The buffer where the C string is stored. |
true
if successful, and false
if the buffer is not large enough. Definition at line 146 of file StringView.h.
[out] | str | The reference to the UniquePtr where the C string is stored. |
true
if successful, and false
if the dynamic allocation of memory failed. Definition at line 152 of file StringView.h.
|
noexcept |
Converts a string to a double-precision floating-point number.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
|
noexcept |
Converts a string to a double-precision floating-point number.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
|
noexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
|
noexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
|
noexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
|
noexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
|
inlinenoexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
Definition at line 234 of file StringView.h.
|
inlinenoexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
Definition at line 244 of file StringView.h.
|
inlinenoexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
Definition at line 254 of file StringView.h.
|
inlinenoexcept |
Converts a string to an integer.
[out] | v | Pointer to where the numerical value is stored. |
[out] | idx | Pointer to where the number of read characters is stored. |
[in] | base | The number base to use. Can be 0 , 8 , 10 , or 16 . If 0 , works the same was as the std::strtol function. |
0 | Success. |
ELISEQ | Indicates that an invalid character was detected in the numerical value. |
EINVAL | v is set to NULL . |
ERANGE | Indicates an overflow or an underflow. |
ENOTSUP | Indicates that base was a value other than 0 , 8 , 10 , or 16 . |
Definition at line 264 of file StringView.h.
|
noexcept |
Trims the white space from the start of the string.
true
if white space was trimmed.
|
noexcept |
Trims the white space from the end of the string.
true
if white space was trimmed. © 2012-2017 Nintendo Co., Ltd. All rights reserved.