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

#include <UT_StringHolder.h>

+ Inheritance diagram for UT_StringHolder:

Public Types

enum  UT_StringReferenceType { REFERENCE }
 
- Public Types inherited from UT_StringRef
enum  StorageMode { STORE_EXTERNAL, STORE_NEW, STORE_MALLOC, STORE_INLINE }
 
typedef char value_type
 
typedef const char * const_iterator
 Iterators. More...
 
enum  UT_StringSentinelType { SENTINEL }
 

Public Member Functions

SYS_FORCE_INLINE UT_StringHolder ()
 
SYS_FORCE_INLINE UT_StringHolder (const char *str)
 Will make a copy of the provided string. More...
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringReferenceType, const char *str)
 Will make a shallow reference. More...
 
SYS_FORCE_INLINE UT_StringHolder (const char *data, exint length)
 Will make a copy of the provided string. More...
 
 UT_StringHolder (const char *data, bool bad)=delete
 
SYS_FORCE_INLINE UT_StringHolder (const char *data, int32 length)
 
SYS_FORCE_INLINE UT_StringHolder (const char *data, uint32 length)
 
SYS_FORCE_INLINE UT_StringHolder (const char *data, uint64 length)
 
SYS_FORCE_INLINE UT_StringHolder (const std::string &str)
 Will make a copy of the provided string. More...
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringReferenceType, const std::string &str)
 This will make a shallow reference to the contents of the string. More...
 
 UT_StringHolder (const UT_WorkBuffer &str)
 Will make a copy of the provided string. More...
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringReferenceType, const UT_WorkBuffer &str)
 This will make a shallow reference to the contents of the string. More...
 
SYS_FORCE_INLINE UT_StringHolder (const UT_String &str)
 Will make a copy of the provided string. More...
 
 UT_StringHolder (UT_String &&str)
 Attempts to steal the string's buffer. More...
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringReferenceType, const UT_String &str)
 This will make a shallow reference to the contents of the string. More...
 
 UT_StringHolder (const UT_StringView &sv)
 Will make a copy of the provided string. More...
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringReferenceType, const UT_StringRef &ref)
 Makes a shallow reference to the contents of the UT_StringRef. More...
 
 UT_StringHolder (const UT_StringRef &ref)
 
 UT_StringHolder (UT_StringRef &&ref)
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringSentinelType sentinel)
 Construct as a sentinel value. More...
 
SYS_FORCE_INLINE UT_StringHolder (const UT_StringHolder &str)
 Makes a copy of the provided string. More...
 
SYS_FORCE_INLINE UT_StringHolder (UT_StringHolder &&a) noexcept
 Move constructor. Steals the working data from the original. More...
 
 UT_StringHolder (UT_WorkBuffer &&buf) noexcept
 Move constructor. Steals the data from the work buffer. More...
 
SYS_FORCE_INLINE UT_StringHolderoperator= (const UT_StringHolder &s)
 Makes a bit-wise copy of the string and adjust the reference count. More...
 
SYS_FORCE_INLINE UT_StringHolderoperator= (UT_StringHolder &&s)
 
UT_StringHolderoperator= (UT_WorkBuffer &&buf)
 Move the contents buffer into this string holder. More...
 
SYS_FORCE_INLINE void swap (UT_StringHolder &other)
 
SYS_FORCE_INLINE void swap (UT_StringRef &other)
 
template<typename... Args>
size_t format (const char *fmt, const Args &...args)
 Format a string using the same formatting codes as UTformat. More...
 
size_t format (const char *fmt, std::initializer_list< UT::Format::ArgValue > args)
 
template<typename... Args>
size_t sprintf (const char *fmt, const Args &...args)
 Format a string using the same formatting codes as UTprintf. More...
 
size_t sprintf (const char *fmt, std::initializer_list< UT::Format::ArgValue > args)
 
int substitute (const char *find, const char *replacement, int count=-1)
 
int substitute (const char *find, const char *replacement, bool all)
 Convenience version of substitute() for all or single occurrence. More...
 
int strip (const char *chars)
 
bool load (UT_IStream &is)
 Load string from stream. Use is.eof() to check eof status. More...
 
UT_StringHolderoperator+= (const UT_StringRef &src)
 
bool trimBoundingSpace ()
 
bool trimSpace (bool leave_single_space_between_words=false)
 
void prepend (const UT_StringRef &prefix)
 Prepend a string. More...
 
- Public Member Functions inherited from UT_StringRef
SYS_FORCE_INLINE UT_StringRef ()
 
SYS_FORCE_INLINE UT_StringRef (const char *str)
 Will make a shallow reference. More...
 
SYS_FORCE_INLINE UT_StringRef (const char *data, exint length)
 
SYS_FORCE_INLINE UT_StringRef (const UT_StringLit &lit)
 Construct from string literal. More...
 
SYS_FORCE_INLINE UT_StringRef (const std::string &str)
 This will make a shallow reference to the contents of the string. More...
 
 UT_StringRef (const UT_WorkBuffer &str)
 This will make a shallow reference to the contents of the string. More...
 
SYS_FORCE_INLINE UT_StringRef (const UT_String &str)
 This will make a shallow reference to the contents of the string. More...
 
SYS_FORCE_INLINE UT_StringRef (const UT_StringRef &s) noexcept
 Shares a reference with the source. More...
 
SYS_FORCE_INLINE UT_StringRef (UT_StringRef &&s) noexcept
 Move constructor. Steals the working data from the original. More...
 
SYS_FORCE_INLINE ~UT_StringRef ()
 
bool isUnique () const
 Returns true this object is the sole owner of the underlying string. More...
 
UT_StringRefoperator= (const UT_StringRef &s)
 Shares a reference with the source. More...
 
SYS_FORCE_INLINE UT_StringRefoperator= (UT_StringRef &&s)
 
bool operator== (const UT_StringRef &s) const
 
bool operator== (const char *s) const
 
bool operator== (const UT_String &s) const
 
bool operator!= (const UT_StringRef &s) const
 
bool operator!= (const char *s) const
 
bool operator!= (const UT_String &s) const
 
int spaceship (const UT_StringRef &k) const
 
bool operator< (const UT_StringRef &k) const
 
bool operator<= (const UT_StringRef &k) const
 
bool operator> (const UT_StringRef &k) const
 
bool operator>= (const UT_StringRef &k) const
 
int compare (const UT_StringRef &str, bool ignore_case=false) const
 
bool equal (const UT_StringRef &str, bool ignore_case=false) const
 
SYS_FORCE_INLINE SYS_SAFE_BOOL operator bool () const
 Test whether the string is defined or not. More...
 
bool startsWith (const UT_StringView &pfx, bool case_sense=true) const
 Imported from UT_String. More...
 
bool endsWith (const UT_StringView &suffix, bool case_sense=true) const
 
bool match (const char *pattern, bool case_sensitive=true) const
 
bool contains (const char *pattern, bool case_sensitive=true) const
 
const char * fcontain (const char *pattern, bool case_sensitive=true) const
 
const char * findWord (const char *word) const
 
bool multiMatch (const char *pattern, bool case_sensitive, char separator) const
 
bool multiMatch (const char *pattern, bool case_sensitive=true, const char *separators=", ", bool *explicitly_excluded=0, int *match_index=0, ut_PatternRecord *pattern_record=nullptr) const
 
bool multiMatch (const UT_StringMMPattern &pattern, bool *explicitly_excluded=0, int *match_index=0, ut_PatternRecord *pattern_record=nullptr) const
 
bool matchRegex (const char *expr) const
 
int toInt () const
 
fpreal toFloat () const
 
bool isFloat (bool skip_spaces=false, bool loose=false) const
 Determine if string can be seen as a single floating point number. More...
 
bool isInteger (bool skip_spaces=false) const
 Determine if string can be seen as a single integer number. More...
 
SYS_FORCE_INLINE operator const char * () const
 
SYS_FORCE_INLINE const char * buffer () const
 
SYS_FORCE_INLINE const char * nonNullBuffer () const
 
SYS_FORCE_INLINE const_iterator begin () const
 
SYS_FORCE_INLINE const_iterator end () const
 
std::string toStdString () const
 
SYS_FORCE_INLINE void swap (UT_StringRef &other)
 
SYS_FORCE_INLINE bool isstring () const
 
bool isEmpty () const
 Same as !isstring() More...
 
bool empty () const
 method name that maches std::string More...
 
SYS_FORCE_INLINE bool hasNonSpace () const
 
SYS_FORCE_INLINE exint findCharIndex (char c) const
 Find the location of the character (or -1 if not found) More...
 
SYS_FORCE_INLINE exint findCharIndex (const char *str) const
 Find the first location of any of the characters in the str passed in. More...
 
SYS_FORCE_INLINE exint findCharIndex (char c, exint start_offset) const
 Find the location of the character (or -1 if not found) More...
 
SYS_FORCE_INLINE exint findCharIndex (const char *str, exint start_offset) const
 Find the first location of any of the characters in the str passed in. More...
 
SYS_FORCE_INLINE exint lastCharIndex (char c, int occurrence_number=1) const
 
SYS_FORCE_INLINE exint countChar (char c) const
 Count the number of times the character c occurs. More...
 
SYS_FORCE_INLINE void clear ()
 
SYS_FORCE_INLINE const char * c_str () const
 
SYS_FORCE_INLINE const char * data () const
 
exint length () const
 
unsigned hash () const
 
void reference (const char *src)
 
void reference (const char *str, exint length)
 
void fastReferenceWithStrlen (const char *src, exint length)
 old name of method: More...
 
int64 getMemoryUsage (bool inclusive) const
 
SYS_NO_DISCARD_RESULT UT_StringRef forceValidVariableName (const char *safechars=nullptr) const
 
SYS_NO_DISCARD_RESULT UT_StringRef toLower () const
 
SYS_NO_DISCARD_RESULT UT_StringRef toUpper () const
 
void harden (const char *src)
 
void adoptFromMalloc (const char *str, exint length)
 
void adoptFromNew (const char *str, exint length)
 
void adoptFromString (UT_String &str)
 
void adoptFromCharArray (UT_Array< char > &data)
 
char * stealAsMalloc ()
 
void saveBinary (std::ostream &os) const
 Save string to binary stream. More...
 
void saveAscii (std::ostream &os) const
 
SYS_FORCE_INLINE UT_StringRef (UT_StringSentinelType)
 
SYS_FORCE_INLINE UT_StringRef (UT_StringSentinelType, const char *str)
 str==nullptr turns into sentinel, otherwise act like UT_StringRef(str) More...
 
SYS_FORCE_INLINE bool isSentinel () const
 
SYS_FORCE_INLINE void makeSentinel ()
 

Static Public Attributes

static const UT_StringHolder theEmptyString
 
static const UT_StringHolder theSentinel
 

Protected Types

enum  UT_StringLiteralType { LITERAL }
 A marker enum to use this constructor. More...
 

Protected Member Functions

SYS_FORCE_INLINE UT_StringHolder (UT_StringLiteralType, const char *str, size_t length)
 

Friends

UT_StringHolder UT::Literal::operator""_sh (const char *s, std::size_t const length)
 
UT_StringHolder operator""_UTsh (const char *s, std::size_t const length)
 
UT_API std::istream & operator>> (std::istream &is, UT_StringHolder &s)
 
void swap (UT_StringHolder &a, UT_StringRef &b)
 
void swap (UT_StringHolder &a, UT_StringHolder &b)
 

Additional Inherited Members

- Static Public Member Functions inherited from UT_StringRef
static SYS_FORCE_INLINE unsigned hash_string (const char *str, exint len)
 
static bool verifyStringLit ()
 

Detailed Description

Member Enumeration Documentation

A marker enum to use this constructor.

Enumerator
LITERAL 

Definition at line 1278 of file UT_StringHolder.h.

UT_StringHolder can be constructed with UT_StringHolder::REFERENCE to create a shallow reference to the const char *.

Enumerator
REFERENCE 

Definition at line 1004 of file UT_StringHolder.h.

Constructor & Destructor Documentation

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( )
inline

Definition at line 1007 of file UT_StringHolder.h.

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

Will make a copy of the provided string.

Definition at line 1014 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringReferenceType  ,
const char *  str 
)
inline

Will make a shallow reference.

Definition at line 1021 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const char *  data,
exint  length 
)
inline

Will make a copy of the provided string.

Definition at line 1028 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( const char *  data,
bool  bad 
)
delete
SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const char *  data,
int32  length 
)
inline

Definition at line 1039 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const char *  data,
uint32  length 
)
inline

Definition at line 1042 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const char *  data,
uint64  length 
)
inline

Definition at line 1045 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const std::string str)
inline

Will make a copy of the provided string.

Definition at line 1058 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringReferenceType  ,
const std::string str 
)
inline

This will make a shallow reference to the contents of the string.

Definition at line 1065 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( const UT_WorkBuffer str)

Will make a copy of the provided string.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringReferenceType  ,
const UT_WorkBuffer str 
)
inline

This will make a shallow reference to the contents of the string.

Definition at line 1075 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const UT_String str)
inline

Will make a copy of the provided string.

Definition at line 1082 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( UT_String &&  str)
inline

Attempts to steal the string's buffer.

Definition at line 1088 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringReferenceType  ,
const UT_String str 
)
inline

This will make a shallow reference to the contents of the string.

Definition at line 1096 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( const UT_StringView sv)

Will make a copy of the provided string.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringReferenceType  ,
const UT_StringRef ref 
)
inline

Makes a shallow reference to the contents of the UT_StringRef.

Definition at line 1106 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( const UT_StringRef ref)
inline

Makes a deep copy of the provided UT_StringRef. This constructor is not marked explicit since we often want this conversion (e.g. when inserting a UT_StringRef into a UT_StringMap, as with the const char* constructor).

Definition at line 1115 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( UT_StringRef &&  ref)
inline

Definition at line 1121 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringSentinelType  sentinel)
inlineexplicit

Construct as a sentinel value.

Definition at line 1129 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( const UT_StringHolder str)
inline

Makes a copy of the provided string.

Definition at line 1136 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringHolder &&  a)
inlinenoexcept

Move constructor. Steals the working data from the original.

Definition at line 1143 of file UT_StringHolder.h.

UT_StringHolder::UT_StringHolder ( UT_WorkBuffer &&  buf)
noexcept

Move constructor. Steals the data from the work buffer.

SYS_FORCE_INLINE UT_StringHolder::UT_StringHolder ( UT_StringLiteralType  ,
const char *  str,
size_t  length 
)
inlineprotected

Only accepts string literals. Since there's no way to guarantee that a const char * argument is a string literal, we do this through the use of user-defined literal and only provide this constructor to our user-defined literal operator.

Definition at line 1284 of file UT_StringHolder.h.

Member Function Documentation

template<typename... Args>
size_t UT_StringHolder::format ( const char *  fmt,
const Args &...  args 
)
inline

Format a string using the same formatting codes as UTformat.

Examples:
SOP/SOP_BouncyAgent.C.

Definition at line 1202 of file UT_StringHolder.h.

size_t UT_StringHolder::format ( const char *  fmt,
std::initializer_list< UT::Format::ArgValue args 
)
bool UT_StringHolder::load ( UT_IStream is)
inline

Load string from stream. Use is.eof() to check eof status.

Definition at line 1247 of file UT_StringHolder.h.

UT_StringHolder& UT_StringHolder::operator+= ( const UT_StringRef src)
SYS_FORCE_INLINE UT_StringHolder& UT_StringHolder::operator= ( const UT_StringHolder s)
inline

Makes a bit-wise copy of the string and adjust the reference count.

Definition at line 1153 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringHolder& UT_StringHolder::operator= ( UT_StringHolder &&  s)
inline

Move the contents of about-to-be-destructed string s to this string.

Definition at line 1162 of file UT_StringHolder.h.

UT_StringHolder& UT_StringHolder::operator= ( UT_WorkBuffer &&  buf)

Move the contents buffer into this string holder.

void UT_StringHolder::prepend ( const UT_StringRef prefix)

Prepend a string.

template<typename... Args>
size_t UT_StringHolder::sprintf ( const char *  fmt,
const Args &...  args 
)
inline

Format a string using the same formatting codes as UTprintf.

Definition at line 1211 of file UT_StringHolder.h.

size_t UT_StringHolder::sprintf ( const char *  fmt,
std::initializer_list< UT::Format::ArgValue args 
)
int UT_StringHolder::strip ( const char *  chars)

Strips out all characters found in 'chars'. The string length will be reduced by the number of characters removed. The number of characters removed is returned.

int UT_StringHolder::substitute ( const char *  find,
const char *  replacement,
int  count = -1 
)
inline

Replaces up to 'count' occurrences of 'find' with 'replacement', and returns the number of substitutions that occurred. If 'count' <= 0, all occurrences will be replaced.

Examples:
mocapstream/MocapStreamRokokoHDK.C.

Definition at line 1220 of file UT_StringHolder.h.

int UT_StringHolder::substitute ( const char *  find,
const char *  replacement,
bool  all 
)
inline

Convenience version of substitute() for all or single occurrence.

Definition at line 1231 of file UT_StringHolder.h.

SYS_FORCE_INLINE void UT_StringHolder::swap ( UT_StringHolder other)
inline

Definition at line 1172 of file UT_StringHolder.h.

SYS_FORCE_INLINE void UT_StringHolder::swap ( UT_StringRef other)
inline

Definition at line 1178 of file UT_StringHolder.h.

bool UT_StringHolder::trimBoundingSpace ( )

A version of trimSpace() that only removes leading and following spaces from a string, leaving any between words intact.

bool UT_StringHolder::trimSpace ( bool  leave_single_space_between_words = false)

trimSpace() will remove all space characters (leading and following) from a string. If the string consists of multiple words, the words will be collapsed. To keep a single space between words, pass in true. The function returns true if space was trimmed.

Friends And Related Function Documentation

UT_StringHolder operator""_UTsh ( const char *  s,
std::size_t const  length 
)
friend

A user-defined literal in the global namespace. Uglier, but allows the use of UT_StringHolder UDLs in headers.

Definition at line 1354 of file UT_StringHolder.h.

UT_API std::istream& operator>> ( std::istream &  is,
UT_StringHolder s 
)
friend
void swap ( UT_StringHolder a,
UT_StringRef b 
)
friend

Friend specialization of std::swap() to use UT_StringHolder::swap()

Definition at line 1187 of file UT_StringHolder.h.

void swap ( UT_StringHolder a,
UT_StringHolder b 
)
friend

Friend specialization of std::swap() to use UT_StringHolder::swap()

Definition at line 1188 of file UT_StringHolder.h.

UT_StringHolder UT::Literal::operator""_sh ( const char *  s,
std::size_t const  length 
)
friend

Member Data Documentation

const UT_StringHolder UT_StringHolder::theEmptyString
static

In some functions it's nice to be able to return a const-reference to a UT_StringHolder. However, in error cases, you likely want to return an empty string. This would mean that you'd have to return a real UT_StringHolder (not a const reference). This static lets you return a reference to an empty string.

Examples:
tetprim/GEO_PrimTetra.C.

Definition at line 1196 of file UT_StringHolder.h.

const UT_StringHolder UT_StringHolder::theSentinel
static

Definition at line 1198 of file UT_StringHolder.h.


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