HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_StringView Class Reference

A utility class to do read-only operations on a subset of an existing string. More...

#include <UT_StringView.h>

Public Member Functions

SYS_FORCE_INLINE UT_StringView ()
 Default constructor. Constructs an empty non-string. More...
 
SYS_FORCE_INLINE UT_StringView (const char *str)
 Construct a string view from the entirety of a null-terminated string. More...
 
SYS_FORCE_INLINE UT_StringView (const char *str, exint len)
 Construct a string view on a string of a given length. More...
 
SYS_FORCE_INLINE UT_StringView (const char *start, const char *end)
 
SYS_FORCE_INLINE UT_StringView (const UT_StringView &o)=default
 Copy constructor. More...
 
SYS_FORCE_INLINE UT_StringViewoperator= (const UT_StringView &o)=default
 Assignment operator. More...
 
Query functions
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE exint 
length () const
 Returns the length of the string in bytes. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
isEmpty () const
 Returns true if the string is empty. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
isstring () const
 Returns true if the view points to a valid string, even an empty one. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE SYS_SAFE_BOOL 
operator bool () const
 Test whether the string is not an empty string (or nullptr) More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE int64 
getMemoryUsage (bool inclusive) const
 Returns the memory, in bytes, used by this object. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE char 
operator[] (exint i) const
 Returns the character at index i. No bounds checking is performed. More...
 
Manipulators
void clear ()
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE UT_StringView 
trim (const char *c=" \t\n\r") const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE UT_StringView 
trimLeft (const char *c=" \t\n\r") const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE UT_StringView 
trimRight (const char *c=" \t\n\r") const
 
SYS_NO_DISCARD_RESULT UT_StringView firstToken (const char *sep_chars=" \t\n\r") const
 Return the first token. More...
 
SYS_NO_DISCARD_RESULT
UT_StringViewArray 
tokenize (const char *sep_chars=" \t\n\r") const
 
SYS_NO_DISCARD_RESULT
UT_StringViewArray 
split (const char *sep_str=" ", int max_split=INT_MAX) const
 
SYS_NO_DISCARD_RESULT UT_StringView substr (exint index, exint length=SYS_EXINT_MAX) const
 
Operators
SYS_NO_DISCARD_RESULT int compare (const char *str, exint str_len, bool case_sensitive=true) const
 
SYS_NO_DISCARD_RESULT int compare (const UT_StringView &sv, bool case_sensitive=true) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
equal (const char *str, bool case_sensitive=true) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
equal (const UT_StringView &other, bool case_sensitive=true) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
operator== (const char *str) const
 Returns true if the two strings compare as being equal. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
operator== (const UT_StringView &other) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
operator!= (const char *str) const
 Returns true if the two strings compare as being not equal. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
operator!= (const UT_StringView &other) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
operator< (const char *str) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE bool 
operator< (const UT_StringView &other) const
 
const_iterator find (char c, const_iterator start) const
 Find the first instance of the given character in this string. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE
const_iterator 
find (char c) const
 
const_iterator find (const char *str, const_iterator start) const
 Find the first instance of the given substring in this string. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE
const_iterator 
find (const char *str) const
 
SYS_NO_DISCARD_RESULT
const_iterator 
rfind (char c, const_iterator pos) const
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE
const_iterator 
rfind (char c) const
 

Iterators

typedef const char * const_iterator
 The iterator type. UT_StringView only provides read-only iterators. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE
const_iterator 
begin () const
 Returns a constant iterator pointing to the beginning of the string. More...
 
SYS_NO_DISCARD_RESULT
SYS_FORCE_INLINE
const_iterator 
end () const
 Returns a constant iterator pointing to the end of the string. More...
 

Detailed Description

A utility class to do read-only operations on a subset of an existing string.

Note
This object does not take ownership over the data being looked at, so care must be taken that the owning object doesn't not go out of scope before the view object.

Definition at line 32 of file UT_StringView.h.

Member Typedef Documentation

The iterator type. UT_StringView only provides read-only iterators.

Definition at line 112 of file UT_StringView.h.

Constructor & Destructor Documentation

SYS_FORCE_INLINE UT_StringView::UT_StringView ( )
inline

Default constructor. Constructs an empty non-string.

Definition at line 37 of file UT_StringView.h.

SYS_FORCE_INLINE UT_StringView::UT_StringView ( const char *  str)
inline

Construct a string view from the entirety of a null-terminated string.

Definition at line 43 of file UT_StringView.h.

SYS_FORCE_INLINE UT_StringView::UT_StringView ( const char *  str,
exint  len 
)
inlineexplicit

Construct a string view on a string of a given length.

Definition at line 52 of file UT_StringView.h.

SYS_FORCE_INLINE UT_StringView::UT_StringView ( const char *  start,
const char *  end 
)
inlineexplicit

Construct a string view on a given string range. The end pointer should point to one past the end of the string (i.e. in the case of null terminated strings, it should point at the null character).

Definition at line 64 of file UT_StringView.h.

SYS_FORCE_INLINE UT_StringView::UT_StringView ( const UT_StringView o)
default

Copy constructor.

Member Function Documentation

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator UT_StringView::begin ( void  ) const
inline

Returns a constant iterator pointing to the beginning of the string.

Definition at line 116 of file UT_StringView.h.

void UT_StringView::clear ( void  )
inline

Clears the string. After this operation isstring will return false, and isEmpty will return true.

Definition at line 128 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT int UT_StringView::compare ( const char *  str,
exint  str_len,
bool  case_sensitive = true 
) const

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

SYS_NO_DISCARD_RESULT int UT_StringView::compare ( const UT_StringView sv,
bool  case_sensitive = true 
) const

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator UT_StringView::end ( void  ) const
inline

Returns a constant iterator pointing to the end of the string.

Definition at line 120 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::equal ( const char *  str,
bool  case_sensitive = true 
) const
inline

Returns true if the two strings compare as being equal. If case_sensitive is set to false then the strings are compared in a case-insensitive fashion.

Definition at line 195 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::equal ( const UT_StringView other,
bool  case_sensitive = true 
) const
inline

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 199 of file UT_StringView.h.

const_iterator UT_StringView::find ( char  c,
const_iterator  start 
) const

Find the first instance of the given character in this string.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator UT_StringView::find ( char  c) const
inline

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 231 of file UT_StringView.h.

const_iterator UT_StringView::find ( const char *  str,
const_iterator  start 
) const

Find the first instance of the given substring in this string.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator UT_StringView::find ( const char *  str) const
inline

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 237 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT UT_StringView UT_StringView::firstToken ( const char *  sep_chars = " \t\n\r") const

Return the first token.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE int64 UT_StringView::getMemoryUsage ( bool  inclusive) const
inline

Returns the memory, in bytes, used by this object.

Definition at line 99 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::isEmpty ( ) const
inline

Returns true if the string is empty.

Definition at line 87 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::isstring ( ) const
inline

Returns true if the view points to a valid string, even an empty one.

Definition at line 91 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE exint UT_StringView::length ( void  ) const
inline

Returns the length of the string in bytes.

Definition at line 83 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE SYS_SAFE_BOOL UT_StringView::operator bool ( ) const
inline

Test whether the string is not an empty string (or nullptr)

Definition at line 95 of file UT_StringView.h.

Returns true if the two strings compare as being not equal.

Definition at line 213 of file UT_StringView.h.

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 216 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::operator< ( const char *  str) const
inline

Returns true if this string is lexicographically less than the given string.

Definition at line 222 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::operator< ( const UT_StringView other) const
inline

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 225 of file UT_StringView.h.

SYS_FORCE_INLINE UT_StringView& UT_StringView::operator= ( const UT_StringView o)
default

Assignment operator.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::operator== ( const char *  str) const
inline

Returns true if the two strings compare as being equal.

Definition at line 205 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool UT_StringView::operator== ( const UT_StringView other) const
inline

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 208 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE char UT_StringView::operator[] ( exint  i) const
inline

Returns the character at index i. No bounds checking is performed.

Definition at line 104 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT const_iterator UT_StringView::rfind ( char  c,
const_iterator  pos 
) const

Find last instance of the given character in this string, searching backwards from 'pos'.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator UT_StringView::rfind ( char  c) const
inline

The compare function compares this string with another, and returns and integer less than, equal to, or greater than zero if this string is found to be less than, equal to, or greater than the given string, respectively. If a length is given, then the strings are compared as if they were both of that length, or smaller.

Definition at line 245 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT UT_StringViewArray UT_StringView::split ( const char *  sep_str = " ",
int  max_split = INT_MAX 
) const

Splits the string into a list of words, using sep_str as the separator string. Unlike tokenize, consecutive delimiters are not grouped together and are instead taken to delimit empty strings. If max_split is set, the string is split into at most max_sep pieces.

SYS_NO_DISCARD_RESULT UT_StringView UT_StringView::substr ( exint  index,
exint  length = SYS_EXINT_MAX 
) const

Returns a sub-string of the current string. If positive, the index parameter is relative to the start. If negative, it's relative to the end (e.g. substr(-1,1) will return the last character of the string). The empty string will be returned for out-of-range values.

SYS_NO_DISCARD_RESULT UT_StringViewArray UT_StringView::tokenize ( const char *  sep_chars = " \t\n\r") const

Splits the string into individual tokens, separated by one or more of the sep characters given.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE UT_StringView UT_StringView::trim ( const char *  c = " \t\n\r") const
inline

Trim characters from the left- and right-hand side of the string. By default this will trim the ASCII space characters.

Definition at line 133 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE UT_StringView UT_StringView::trimLeft ( const char *  c = " \t\n\r") const
inline

Trim characters from the left-hand side of the string. By default this will trim the ASCII space characters.

Definition at line 139 of file UT_StringView.h.

SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE UT_StringView UT_StringView::trimRight ( const char *  c = " \t\n\r") const
inline

Trim characters from the right-hand side of the string. By default this will trim the ASCII space characters.

Definition at line 145 of file UT_StringView.h.


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