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

#include <UT_StringHolder.h>

+ Inheritance diagram for UT_StringRef:

Classes

class  Holder
 
struct  NumberedCompare
 

Public Types

enum  StorageMode { STORE_EXTERNAL, STORE_NEW, STORE_MALLOC, STORE_INLINE }
 
typedef char value_type
 
typedef const char * const_iterator
 Iterators. More...
 

Public Member Functions

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
 

Static Public Member Functions

static SYS_FORCE_INLINE unsigned hash_string (const char *str, exint len)
 
static bool verifyStringLit ()
 

Friends

class UT_StringHolder
 
void swap (UT_StringRef &a, UT_StringRef &b)
 Friend specialization of std::swap() to use UT_StringRef::swap() More...
 
UT_API std::ostream & operator<< (std::ostream &os, const UT_StringRef &d)
 
UT_API UT_OStreamoperator<< (UT_OStream &os, const UT_StringRef &d)
 
enum  UT_StringSentinelType { SENTINEL }
 
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 ()
 

Detailed Description

A holder for a string, which stores the length and caches the hash value. A UT_StringRef does not necessarily own the string, and it is therefore not safe to e.g. store a UT_StringRef in a container or member variable.

See Also
UT_StringHolder
UTmakeUnsafeRef
Examples:
karma_procedurals/BRAY_HdBox.C, karma_procedurals/BRAY_HdSphere.C, packedshareddata/GU_PackedSharedData.C, packedsphere/GU_PackedSphere.C, and SOP/SOP_BouncyAgent.C.

Definition at line 188 of file UT_StringHolder.h.

Member Typedef Documentation

Iterators.

Definition at line 578 of file UT_StringHolder.h.

Definition at line 191 of file UT_StringHolder.h.

Member Enumeration Documentation

Enumerator
STORE_EXTERNAL 
STORE_NEW 
STORE_MALLOC 
STORE_INLINE 

Definition at line 193 of file UT_StringHolder.h.

Special sentinel value support

Enumerator
SENTINEL 

Definition at line 349 of file UT_StringHolder.h.

Constructor & Destructor Documentation

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( )
inline

Definition at line 270 of file UT_StringHolder.h.

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

Will make a shallow reference.

Definition at line 279 of file UT_StringHolder.h.

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

Will make a shallow reference. This is NOT a string view, the string must actually null terminate

Definition at line 289 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( const UT_StringLit lit)
inlineexplicit

Construct from string literal.

Definition at line 297 of file UT_StringHolder.h.

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

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

Definition at line 304 of file UT_StringHolder.h.

UT_StringRef::UT_StringRef ( const UT_WorkBuffer str)

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

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( const UT_String str)
inline

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

Definition at line 314 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( const UT_StringRef s)
inlinenoexcept

Shares a reference with the source.

Definition at line 321 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( UT_StringRef &&  s)
inlinenoexcept

Move constructor. Steals the working data from the original.

Definition at line 331 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::~UT_StringRef ( )
inline

Definition at line 342 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( UT_StringSentinelType  )
inlineexplicit

Special sentinel value support

Definition at line 352 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::UT_StringRef ( UT_StringSentinelType  ,
const char *  str 
)
inline

str==nullptr turns into sentinel, otherwise act like UT_StringRef(str)

Definition at line 361 of file UT_StringHolder.h.

Member Function Documentation

void UT_StringRef::adoptFromCharArray ( UT_Array< char > &  data)
void UT_StringRef::adoptFromMalloc ( const char *  str,
exint  length 
)
void UT_StringRef::adoptFromNew ( const char *  str,
exint  length 
)
void UT_StringRef::adoptFromString ( UT_String str)
inline

Definition at line 834 of file UT_StringHolder.h.

SYS_FORCE_INLINE const_iterator UT_StringRef::begin ( void  ) const
inline

Definition at line 581 of file UT_StringHolder.h.

SYS_FORCE_INLINE const char* UT_StringRef::buffer ( ) const
inline
Examples:
SOP/SOP_BouncyAgent.C.

Definition at line 570 of file UT_StringHolder.h.

SYS_FORCE_INLINE const char* UT_StringRef::c_str ( void  ) const
inline
Examples:
RAY/RAY_DemoFile.C, and VOP/VOP_CustomContext.C.

Definition at line 721 of file UT_StringHolder.h.

SYS_FORCE_INLINE void UT_StringRef::clear ( void  )
inline

Definition at line 712 of file UT_StringHolder.h.

int UT_StringRef::compare ( const UT_StringRef str,
bool  ignore_case = false 
) const
inline

Definition at line 491 of file UT_StringHolder.h.

bool UT_StringRef::contains ( const char *  pattern,
bool  case_sensitive = true 
) const
inline

Definition at line 517 of file UT_StringHolder.h.

SYS_FORCE_INLINE exint UT_StringRef::countChar ( char  c) const
inline

Count the number of times the character c occurs.

Definition at line 706 of file UT_StringHolder.h.

SYS_FORCE_INLINE const char* UT_StringRef::data ( ) const
inline

Definition at line 744 of file UT_StringHolder.h.

bool UT_StringRef::empty ( void  ) const
inline

method name that maches std::string

Definition at line 615 of file UT_StringHolder.h.

SYS_FORCE_INLINE const_iterator UT_StringRef::end ( void  ) const
inline

Definition at line 584 of file UT_StringHolder.h.

bool UT_StringRef::endsWith ( const UT_StringView suffix,
bool  case_sense = true 
) const
inline

Definition at line 510 of file UT_StringHolder.h.

bool UT_StringRef::equal ( const UT_StringRef str,
bool  ignore_case = false 
) const
inline

Definition at line 497 of file UT_StringHolder.h.

void UT_StringRef::fastReferenceWithStrlen ( const char *  src,
exint  length 
)
inline

old name of method:

Definition at line 780 of file UT_StringHolder.h.

const char* UT_StringRef::fcontain ( const char *  pattern,
bool  case_sensitive = true 
) const
inline
Examples:
mocapstream/MocapStreamRokokoHDK.C.

Definition at line 519 of file UT_StringHolder.h.

SYS_FORCE_INLINE exint UT_StringRef::findCharIndex ( char  c) const
inline

Find the location of the character (or -1 if not found)

Definition at line 632 of file UT_StringHolder.h.

SYS_FORCE_INLINE exint UT_StringRef::findCharIndex ( const char *  str) const
inline

Find the first location of any of the characters in the str passed in.

Definition at line 642 of file UT_StringHolder.h.

SYS_FORCE_INLINE exint UT_StringRef::findCharIndex ( char  c,
exint  start_offset 
) const
inline

Find the location of the character (or -1 if not found)

Definition at line 657 of file UT_StringHolder.h.

SYS_FORCE_INLINE exint UT_StringRef::findCharIndex ( const char *  str,
exint  start_offset 
) const
inline

Find the first location of any of the characters in the str passed in.

Definition at line 673 of file UT_StringHolder.h.

const char* UT_StringRef::findWord ( const char *  word) const
inline

Definition at line 521 of file UT_StringHolder.h.

SYS_NO_DISCARD_RESULT UT_StringRef UT_StringRef::forceValidVariableName ( const char *  safechars = nullptr) const

Convert the string into a valid C style variable name. All non-alpha numerics will be converted to _. If the first letter is a digit, it is prefixed with an _. If the string is already valid, the string itself is returned. Note that this does NOT force the name to be non-zero in length. The safechars parameter is a string containing extra characters that should be considered safe. These characters are not converted to underscores.

int64 UT_StringRef::getMemoryUsage ( bool  inclusive) const
inline
Examples:
SOP/SOP_BouncyAgent.C.

Definition at line 785 of file UT_StringHolder.h.

void UT_StringRef::harden ( const char *  src)
inline

Often people reflexively use this from UT_String days so this increases code compataibility.

Definition at line 824 of file UT_StringHolder.h.

unsigned UT_StringRef::hash ( void  ) const
inline

Definition at line 759 of file UT_StringHolder.h.

static SYS_FORCE_INLINE unsigned UT_StringRef::hash_string ( const char *  str,
exint  len 
)
inlinestatic

Definition at line 796 of file UT_StringHolder.h.

SYS_FORCE_INLINE bool UT_StringRef::hasNonSpace ( ) const
inline

Definition at line 620 of file UT_StringHolder.h.

bool UT_StringRef::isEmpty ( ) const
inline

Same as !isstring()

Definition at line 611 of file UT_StringHolder.h.

bool UT_StringRef::isFloat ( bool  skip_spaces = false,
bool  loose = false 
) const
inline

Determine if string can be seen as a single floating point number.

Definition at line 559 of file UT_StringHolder.h.

bool UT_StringRef::isInteger ( bool  skip_spaces = false) const
inline

Determine if string can be seen as a single integer number.

Definition at line 562 of file UT_StringHolder.h.

SYS_FORCE_INLINE bool UT_StringRef::isSentinel ( ) const
inline

Special sentinel value support

Definition at line 371 of file UT_StringHolder.h.

SYS_FORCE_INLINE bool UT_StringRef::isstring ( ) const
inline

Equivalent to (length() != 0) Returns false for isSentinel()

Examples:
RAY/RAY_DemoFile.C, and RAY/RAY_DemoSprite.C.

Definition at line 607 of file UT_StringHolder.h.

bool UT_StringRef::isUnique ( ) const
inline

Returns true this object is the sole owner of the underlying string.

Definition at line 387 of file UT_StringHolder.h.

SYS_FORCE_INLINE exint UT_StringRef::lastCharIndex ( char  c,
int  occurrence_number = 1 
) const
inline

Definition at line 687 of file UT_StringHolder.h.

exint UT_StringRef::length ( void  ) const
inline
Examples:
SIM/GAS_NetVDBSliceExchange.C, and VOP/VOP_CustomContext.C.

Definition at line 749 of file UT_StringHolder.h.

SYS_FORCE_INLINE void UT_StringRef::makeSentinel ( )
inline

Special sentinel value support

Definition at line 377 of file UT_StringHolder.h.

bool UT_StringRef::match ( const char *  pattern,
bool  case_sensitive = true 
) const
inline

Definition at line 514 of file UT_StringHolder.h.

bool UT_StringRef::matchRegex ( const char *  expr) const

Returns true if the entire string matches the provided regular expression, false otherwise. See UT_Regex.

bool UT_StringRef::multiMatch ( const char *  pattern,
bool  case_sensitive,
char  separator 
) const
inline

Definition at line 524 of file UT_StringHolder.h.

bool UT_StringRef::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
inline

Definition at line 530 of file UT_StringHolder.h.

bool UT_StringRef::multiMatch ( const UT_StringMMPattern pattern,
bool *  explicitly_excluded = 0,
int match_index = 0,
ut_PatternRecord *  pattern_record = nullptr 
) const
inline

Definition at line 540 of file UT_StringHolder.h.

SYS_FORCE_INLINE const char* UT_StringRef::nonNullBuffer ( ) const
inline

Definition at line 574 of file UT_StringHolder.h.

SYS_FORCE_INLINE SYS_SAFE_BOOL UT_StringRef::operator bool ( ) const
inline

Test whether the string is defined or not.

Definition at line 503 of file UT_StringHolder.h.

SYS_FORCE_INLINE UT_StringRef::operator const char * ( ) const
inline

Definition at line 566 of file UT_StringHolder.h.

bool UT_StringRef::operator!= ( const UT_StringRef s) const
inline

Definition at line 456 of file UT_StringHolder.h.

bool UT_StringRef::operator!= ( const char *  s) const
inline

Definition at line 458 of file UT_StringHolder.h.

bool UT_StringRef::operator!= ( const UT_String s) const
inline

Definition at line 460 of file UT_StringHolder.h.

bool UT_StringRef::operator< ( const UT_StringRef k) const
inline

Definition at line 483 of file UT_StringHolder.h.

bool UT_StringRef::operator<= ( const UT_StringRef k) const
inline

Definition at line 485 of file UT_StringHolder.h.

UT_StringRef& UT_StringRef::operator= ( const UT_StringRef s)
inline

Shares a reference with the source.

Definition at line 393 of file UT_StringHolder.h.

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

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

Definition at line 406 of file UT_StringHolder.h.

bool UT_StringRef::operator== ( const UT_StringRef s) const
inline

Definition at line 413 of file UT_StringHolder.h.

bool UT_StringRef::operator== ( const char *  s) const
inline

Definition at line 436 of file UT_StringHolder.h.

bool UT_StringRef::operator== ( const UT_String s) const
inline

Definition at line 453 of file UT_StringHolder.h.

bool UT_StringRef::operator> ( const UT_StringRef k) const
inline

Definition at line 487 of file UT_StringHolder.h.

bool UT_StringRef::operator>= ( const UT_StringRef k) const
inline

Definition at line 489 of file UT_StringHolder.h.

void UT_StringRef::reference ( const char *  src)
inline

Make a light weight reference to the source. Caller must make sure src lives for the duration of this object, and any objects value copied from this!

Definition at line 769 of file UT_StringHolder.h.

void UT_StringRef::reference ( const char *  str,
exint  length 
)

Fast reference that takes the length of the string. This is NOT a string view, the string must actually null terminate at the given length or later functions will be confused.

void UT_StringRef::saveAscii ( std::ostream &  os) const
inline

Save string to ASCII stream. This will add double quotes and escape to the stream if necessary (empty string or contains spaces).

Definition at line 881 of file UT_StringHolder.h.

void UT_StringRef::saveBinary ( std::ostream &  os) const
inline

Save string to binary stream.

Definition at line 876 of file UT_StringHolder.h.

int UT_StringRef::spaceship ( const UT_StringRef k) const
inline

Spaceship comparison returns:

  • < 0 if *this < k
  • == 0 if *this == k
  • > 0 if *this > k

Definition at line 467 of file UT_StringHolder.h.

bool UT_StringRef::startsWith ( const UT_StringView pfx,
bool  case_sense = true 
) const
inline

Imported from UT_String.

Definition at line 506 of file UT_StringHolder.h.

char* UT_StringRef::stealAsMalloc ( )
SYS_FORCE_INLINE void UT_StringRef::swap ( UT_StringRef other)
inline

Definition at line 594 of file UT_StringHolder.h.

fpreal UT_StringRef::toFloat ( ) const
inline

Definition at line 555 of file UT_StringHolder.h.

int UT_StringRef::toInt ( ) const
inline

Definition at line 553 of file UT_StringHolder.h.

SYS_NO_DISCARD_RESULT UT_StringRef UT_StringRef::toLower ( ) const

Convert to lower case. If the string is already lower case, the string itself is returned.

std::string UT_StringRef::toStdString ( ) const
inline

Converts the contents of this UT_String to a std::string. Since we are never null this is easy

Definition at line 590 of file UT_StringHolder.h.

SYS_NO_DISCARD_RESULT UT_StringRef UT_StringRef::toUpper ( ) const

Convert to upper case. If the string is already upper case, the string itsef is returned.

static bool UT_StringRef::verifyStringLit ( )
static

Friends And Related Function Documentation

UT_API std::ostream& operator<< ( std::ostream &  os,
const UT_StringRef d 
)
friend

This operator saves the string to the stream via the string's saveAscii() method, protecting any whitespace (by adding quotes), backslashes or quotes in the string.

UT_API UT_OStream& operator<< ( UT_OStream os,
const UT_StringRef d 
)
friend
void swap ( UT_StringRef a,
UT_StringRef b 
)
friend

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

Definition at line 602 of file UT_StringHolder.h.

friend class UT_StringHolder
friend

Definition at line 938 of file UT_StringHolder.h.

Member Data Documentation

const void* UT_StringRef::myData

Definition at line 922 of file UT_StringHolder.h.

const char* UT_StringRef::myDataIfChars

Definition at line 923 of file UT_StringHolder.h.

Holder* UT_StringRef::myDataIfHolder

Definition at line 924 of file UT_StringHolder.h.


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