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

#include <ustring.h>

Classes

struct  TableRep
 

Public Types

using rep_t = const char *
 The underlying representation type. More...
 
using value_type = char
 
using hash_t = uint64_t
 The hash type. More...
 
using pointer = value_type *
 
using reference = value_type &
 
using const_reference = const value_type &
 
using size_type = size_t
 
using const_iterator = std::string::const_iterator
 
using const_reverse_iterator = std::string::const_reverse_iterator
 

Public Member Functions

constexpr ustring () noexcept
 Default ctr for ustring – make an empty string. More...
 
 ustring (const char *str)
 Construct a ustring from a null-terminated C string (char *). More...
 
 ustring (string_view str)
 
 ustring (const char *str, size_type pos, size_type n)
 
 ustring (const char *str, size_type n)
 Construct a ustring from the first n characters of str. More...
 
 ustring (size_type n, char c)
 Construct a ustring from n copies of character c. More...
 
 ustring (const std::string &str, size_type pos, size_type n=npos)
 Construct a ustring from an indexed substring of a std::string. More...
 
 ustring (const ustring &str) noexcept
 Copy construct a ustring from another ustring. More...
 
 ustring (const ustring &str, size_type pos, size_type n=npos)
 Construct a ustring from an indexed substring of a ustring. More...
 
 ustring (ustringhash hash)
 Construct from a known ustringhash. More...
 
 ~ustring () noexcept
 ustring destructor. More...
 
 operator string_view () const noexcept
 Conversion to an OIIO::string_view. More...
 
 operator std::string () const noexcept
 Conversion to std::string (explicit only!). More...
 
const ustringassign (const ustring &str)
 Assign a ustring to *this. More...
 
const ustringassign (const ustring &str, size_type pos, size_type n=npos)
 Assign a substring of a ustring to *this. More...
 
const ustringassign (const std::string &str)
 Assign a std::string to *this. More...
 
const ustringassign (const std::string &str, size_type pos, size_type n=npos)
 Assign a substring of a std::string to *this. More...
 
const ustringassign (const char *str)
 Assign a null-terminated C string (char*) to *this. More...
 
const ustringassign (const char *str, size_type n)
 Assign the first n characters of str to *this. More...
 
const ustringassign (size_type n, char c)
 Assign n copies of c to *this. More...
 
const ustringassign (string_view str)
 Assign a string_view to *this. More...
 
const ustringoperator= (const ustring &str)
 Assign a ustring to another ustring. More...
 
const ustringoperator= (const char *str)
 Assign a null-terminated C string (char *) to a ustring. More...
 
const ustringoperator= (const std::string &str)
 Assign a C++ std::string to a ustring. More...
 
const ustringoperator= (string_view str)
 Assign a string_view to a ustring. More...
 
const ustringoperator= (char c)
 Assign a single char to a ustring. More...
 
const char * c_str () const noexcept
 Return a C string representation of a ustring. More...
 
const char * data () const noexcept
 Return a C string representation of a ustring. More...
 
const std::string & string () const noexcept
 Return a C++ std::string representation of a ustring. More...
 
void clear () noexcept
 Reset to an empty string. More...
 
size_t length () const noexcept
 Return the number of characters in the string. More...
 
hash_t hash () const noexcept
 Return a hashed version of the string. More...
 
ustringhash uhash () const noexcept
 Return a hashed version of the string. More...
 
size_t size () const noexcept
 Return the number of characters in the string. More...
 
bool empty () const noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reference operator[] (size_type pos) const noexcept
 
size_type copy (char *s, size_type n, size_type pos=0) const
 
ustring substr (size_type pos=0, size_type n=npos) const
 
size_type find (const ustring &str, size_type pos=0) const noexcept
 
size_type find (const std::string &str, size_type pos=0) const noexcept
 
size_type find (const char *s, size_type pos, size_type n) const
 
size_type find (const char *s, size_type pos=0) const
 
size_type find (char c, size_type pos=0) const noexcept
 
size_type rfind (const ustring &str, size_type pos=npos) const noexcept
 
size_type rfind (const std::string &str, size_type pos=npos) const noexcept
 
size_type rfind (const char *s, size_type pos, size_type n) const
 
size_type rfind (const char *s, size_type pos=npos) const
 
size_type rfind (char c, size_type pos=npos) const noexcept
 
size_type find_first_of (const ustring &str, size_type pos=0) const noexcept
 
size_type find_first_of (const std::string &str, size_type pos=0) const noexcept
 
size_type find_first_of (const char *s, size_type pos, size_type n) const
 
size_type find_first_of (const char *s, size_type pos=0) const
 
size_type find_first_of (char c, size_type pos=0) const noexcept
 
size_type find_last_of (const ustring &str, size_type pos=npos) const noexcept
 
size_type find_last_of (const std::string &str, size_type pos=npos) const noexcept
 
size_type find_last_of (const char *s, size_type pos, size_type n) const
 
size_type find_last_of (const char *s, size_type pos=npos) const
 
size_type find_last_of (char c, size_type pos=npos) const noexcept
 
size_type find_first_not_of (const ustring &str, size_type pos=0) const noexcept
 
size_type find_first_not_of (const std::string &str, size_type pos=0) const noexcept
 
size_type find_first_not_of (const char *s, size_type pos, size_type n) const
 
size_type find_first_not_of (const char *s, size_type pos=0) const
 
size_type find_first_not_of (char c, size_type pos=0) const noexcept
 
size_type find_last_not_of (const ustring &str, size_type pos=npos) const noexcept
 
size_type find_last_not_of (const std::string &str, size_type pos=npos) const noexcept
 
size_type find_last_not_of (const char *s, size_type pos, size_type n) const
 
size_type find_last_not_of (const char *s, size_type pos=npos) const
 
size_type find_last_not_of (char c, size_type pos=npos) const noexcept
 
int compare (string_view str) const noexcept
 
int compare (const char *str) const noexcept
 
bool operator== (const ustring &str) const noexcept
 
bool operator!= (const ustring &str) const noexcept
 
bool operator== (const std::string &x) const noexcept
 
bool operator== (string_view x) const noexcept
 
bool operator== (const char *x) const noexcept
 Test a ustring (this) for lexicographic equality with char x. More...
 
bool operator!= (const std::string &x) const noexcept
 
bool operator!= (string_view x) const noexcept
 
bool operator!= (const char *x) const noexcept
 
bool operator< (const ustring &x) const noexcept
 

Static Public Member Functions

template<typename... Args>
static OIIO_NODISCARD ustring sprintf (const char *fmt, const Args &...args)
 
template<typename... Args>
static OIIO_NODISCARD ustring fmtformat (const char *fmt, const Args &...args)
 
template<typename... Args>
static OIIO_FORMAT_DEPRECATED
ustring 
format (const char *fmt, const Args &...args)
 
static ustring concat (string_view s, string_view t)
 
static std::string getstats (bool verbose=true)
 Return the statistics output as a string. More...
 
static size_t memory ()
 Return the amount of memory consumed by the ustring table. More...
 
static size_t total_ustrings ()
 Return the total number of ustrings in the internal table. More...
 
static size_t hash_collisions (std::vector< ustring > *collisions=nullptr)
 
static const char * make_unique (string_view str)
 
static bool is_unique (const char *str)
 
static ustring from_unique (const char *unique)
 
static OIIO_NODISCARD ustring from_hash (hash_t hash)
 

Static Public Attributes

static const size_type npos = static_cast<size_type>(-1)
 

Friends

int compare (const std::string &a, const ustring &b) noexcept
 
bool operator== (const std::string &a, const ustring &b) noexcept
 
bool operator== (string_view a, const ustring &b) noexcept
 
bool operator== (const char *a, const ustring &b) noexcept
 
bool operator!= (const std::string &a, const ustring &b) noexcept
 
bool operator!= (string_view a, const ustring &b) noexcept
 
bool operator!= (const char *a, const ustring &b) noexcept
 
std::ostream & operator<< (std::ostream &out, const ustring &str)
 Generic stream output of a ustring. More...
 

Detailed Description

A ustring is an alternative to char* or std::string for storing strings, in which the character sequence is unique (allowing many speed advantages for assignment, equality testing, and inequality testing).

The implementation is that behind the scenes there is a hash set of allocated strings, so the characters of each string are unique. A ustring itself is a pointer to the characters of one of these canonical strings. Therefore, assignment and equality testing is just a single 32- or 64-bit int operation, the only mutex is when a ustring is created from raw characters, and the only malloc is the first time each canonical ustring is created.

The internal table also contains a std::string version and the length of the string, so converting a ustring to a std::string (via ustring::string()) or querying the number of characters (via ustring::size() or ustring::length()) is extremely inexpensive, and does not involve creation/allocation of a new std::string or a call to strlen.

We try very hard to completely mimic the API of std::string, including all the constructors, comparisons, iterations, etc. Of course, the characters of a ustring are non-modifiable, so we do not replicate any of the non-const methods of std::string. But in most other ways it looks and acts like a std::string and so most templated algorithms that would work on a "const std::string &" will also work on a ustring.

Note that like a char*, but unlike a std::string, a ustring is not allowed to contain any embedded NUL ('\0') characters. When constructing ustrings from a std::string or a string_view, the contents will be truncated at the point of any NUL character. This is done to ensure that ustring::c_str() refers to the same C-style character sequence as the ustring itself or ustring::string().

Usage guidelines:

Compared to standard strings, ustrings have several advantages:

  • Each individual ustring is very small – in fact, we guarantee that a ustring is the same size and memory layout as an ordinary char*.
  • Storage is frugal, since there is only one allocated copy of each unique character sequence, throughout the lifetime of the program.
  • Assignment from one ustring to another is just copy of the pointer; no allocation, no character copying, no reference counting.
  • Equality testing (do the strings contain the same characters) is a single operation, the comparison of the pointer.
  • Memory allocation only occurs when a new ustring is constructed from raw characters the FIRST time – subsequent constructions of the same string just finds it in the canonical string set, but doesn't need to allocate new storage. Destruction of a ustring is trivial, there is no de-allocation because the canonical version stays in the set. Also, therefore, no user code mistake can lead to memory leaks.

But there are some problems, too. Canonical strings are never freed from the table. So in some sense all the strings "leak", but they only leak one copy for each unique string that the program ever comes across. Also, creation of unique strings from raw characters is more expensive than for standard strings, due to hashing, table queries, and other overhead.

On the whole, ustrings are a really great string representation

  • if you tend to have (relatively) few unique strings, but many copies of those strings;
  • if the creation of strings from raw characters is relatively rare compared to copying or comparing to existing strings;
  • if you tend to make the same strings over and over again, and if it's relatively rare that a single unique character sequence is used only once in the entire lifetime of the program;
  • if your most common string operations are assignment and equality testing and you want them to be as fast as possible;
  • if you are doing relatively little character-by-character assembly of strings, string concatenation, or other "string manipulation" (other than equality testing).

ustrings are not so hot

  • if your program tends to have very few copies of each character sequence over the entire lifetime of the program;
  • if your program tends to generate a huge variety of unique strings over its lifetime, each of which is used only a short time and then discarded, never to be needed again;
  • if you don't need to do a lot of string assignment or equality testing, but lots of more complex string manipulation.

Definition at line 126 of file ustring.h.

Member Typedef Documentation

using ustring::const_iterator = std::string::const_iterator

Definition at line 136 of file ustring.h.

Definition at line 133 of file ustring.h.

using ustring::const_reverse_iterator = std::string::const_reverse_iterator

Definition at line 137 of file ustring.h.

using ustring::hash_t = uint64_t

The hash type.

Definition at line 130 of file ustring.h.

Definition at line 131 of file ustring.h.

Definition at line 132 of file ustring.h.

using ustring::rep_t = const char*

The underlying representation type.

Definition at line 128 of file ustring.h.

using ustring::size_type = size_t

Definition at line 134 of file ustring.h.

using ustring::value_type = char

Definition at line 129 of file ustring.h.

Constructor & Destructor Documentation

constexpr ustring::ustring ( )
inlinenoexcept

Default ctr for ustring – make an empty string.

Definition at line 140 of file ustring.h.

ustring::ustring ( const char *  str)
inlineexplicit

Construct a ustring from a null-terminated C string (char *).

Definition at line 146 of file ustring.h.

ustring::ustring ( string_view  str)
inlineexplicit

Construct a ustring from a string_view, which can be auto-converted from either a null-terminated C string (char *) or a C++ std::string.

Definition at line 154 of file ustring.h.

ustring::ustring ( const char *  str,
size_type  pos,
size_type  n 
)
inline

Construct a ustring from at most n characters of str, starting at position pos.

Definition at line 161 of file ustring.h.

ustring::ustring ( const char *  str,
size_type  n 
)
inline

Construct a ustring from the first n characters of str.

Definition at line 167 of file ustring.h.

ustring::ustring ( size_type  n,
char  c 
)
inline

Construct a ustring from n copies of character c.

Definition at line 173 of file ustring.h.

ustring::ustring ( const std::string &  str,
size_type  pos,
size_type  n = npos 
)
inline

Construct a ustring from an indexed substring of a std::string.

Definition at line 179 of file ustring.h.

ustring::ustring ( const ustring str)
inlinenoexcept

Copy construct a ustring from another ustring.

Definition at line 187 of file ustring.h.

ustring::ustring ( const ustring str,
size_type  pos,
size_type  n = npos 
)
inline

Construct a ustring from an indexed substring of a ustring.

Definition at line 193 of file ustring.h.

ustring::ustring ( ustringhash  hash)
inlineexplicit

Construct from a known ustringhash.

Definition at line 1024 of file ustring.h.

ustring::~ustring ( )
inlinenoexcept

ustring destructor.

Definition at line 206 of file ustring.h.

Member Function Documentation

const ustring& ustring::assign ( const ustring str)
inline

Assign a ustring to *this.

Definition at line 215 of file ustring.h.

const ustring& ustring::assign ( const ustring str,
size_type  pos,
size_type  n = npos 
)
inline

Assign a substring of a ustring to *this.

Definition at line 222 of file ustring.h.

const ustring& ustring::assign ( const std::string &  str)
inline

Assign a std::string to *this.

Definition at line 229 of file ustring.h.

const ustring& ustring::assign ( const std::string &  str,
size_type  pos,
size_type  n = npos 
)
inline

Assign a substring of a std::string to *this.

Definition at line 236 of file ustring.h.

const ustring& ustring::assign ( const char *  str)
inline

Assign a null-terminated C string (char*) to *this.

Definition at line 244 of file ustring.h.

const ustring& ustring::assign ( const char *  str,
size_type  n 
)
inline

Assign the first n characters of str to *this.

Definition at line 251 of file ustring.h.

const ustring& ustring::assign ( size_type  n,
char  c 
)
inline

Assign n copies of c to *this.

Definition at line 258 of file ustring.h.

const ustring& ustring::assign ( string_view  str)
inline

Assign a string_view to *this.

Definition at line 265 of file ustring.h.

const_iterator ustring::begin ( void  ) const
inlinenoexcept

Return a const_iterator that references the first character of the string.

Definition at line 338 of file ustring.h.

const char* ustring::c_str ( void  ) const
inlinenoexcept

Return a C string representation of a ustring.

Definition at line 290 of file ustring.h.

void ustring::clear ( )
inlinenoexcept

Reset to an empty string.

Definition at line 306 of file ustring.h.

int ustring::compare ( string_view  str) const
inlinenoexcept

Return 0 if *this is lexicographically equal to str, -1 if *this is lexicographically earlier than str, 1 if *this is lexicographically after str.

Definition at line 540 of file ustring.h.

int ustring::compare ( const char *  str) const
inlinenoexcept

Return 0 if *this is lexicographically equal to str, -1 if *this is lexicographically earlier than str, 1 if *this is lexicographically after str.

Definition at line 548 of file ustring.h.

static ustring ustring::concat ( string_view  s,
string_view  t 
)
static

Concatenate two strings, returning a ustring, implemented carefully to not perform any redundant copies or allocations.

size_type ustring::copy ( char *  s,
size_type  n,
size_type  pos = 0 
) const
inline

Dump into character array s the characters of this ustring, beginning with position pos and copying at most n characters.

Definition at line 362 of file ustring.h.

const char* ustring::data ( ) const
inlinenoexcept

Return a C string representation of a ustring.

Definition at line 293 of file ustring.h.

bool ustring::empty ( void  ) const
inlinenoexcept

Is the string empty – i.e., is it nullptr or does it point to an empty string?

Definition at line 334 of file ustring.h.

const_iterator ustring::end ( void  ) const
inlinenoexcept

Return a const_iterator that references the end of a traversal of the characters of the string.

Definition at line 342 of file ustring.h.

size_type ustring::find ( const ustring str,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 379 of file ustring.h.

size_type ustring::find ( const std::string &  str,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 384 of file ustring.h.

size_type ustring::find ( const char *  s,
size_type  pos,
size_type  n 
) const
inline

Definition at line 389 of file ustring.h.

size_type ustring::find ( const char *  s,
size_type  pos = 0 
) const
inline

Definition at line 394 of file ustring.h.

size_type ustring::find ( char  c,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 399 of file ustring.h.

size_type ustring::find_first_not_of ( const ustring str,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 483 of file ustring.h.

size_type ustring::find_first_not_of ( const std::string &  str,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 489 of file ustring.h.

size_type ustring::find_first_not_of ( const char *  s,
size_type  pos,
size_type  n 
) const
inline

Definition at line 495 of file ustring.h.

size_type ustring::find_first_not_of ( const char *  s,
size_type  pos = 0 
) const
inline

Definition at line 500 of file ustring.h.

size_type ustring::find_first_not_of ( char  c,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 505 of file ustring.h.

size_type ustring::find_first_of ( const ustring str,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 429 of file ustring.h.

size_type ustring::find_first_of ( const std::string &  str,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 435 of file ustring.h.

size_type ustring::find_first_of ( const char *  s,
size_type  pos,
size_type  n 
) const
inline

Definition at line 441 of file ustring.h.

size_type ustring::find_first_of ( const char *  s,
size_type  pos = 0 
) const
inline

Definition at line 446 of file ustring.h.

size_type ustring::find_first_of ( char  c,
size_type  pos = 0 
) const
inlinenoexcept

Definition at line 451 of file ustring.h.

size_type ustring::find_last_not_of ( const ustring str,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 510 of file ustring.h.

size_type ustring::find_last_not_of ( const std::string &  str,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 516 of file ustring.h.

size_type ustring::find_last_not_of ( const char *  s,
size_type  pos,
size_type  n 
) const
inline

Definition at line 522 of file ustring.h.

size_type ustring::find_last_not_of ( const char *  s,
size_type  pos = npos 
) const
inline

Definition at line 527 of file ustring.h.

size_type ustring::find_last_not_of ( char  c,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 532 of file ustring.h.

size_type ustring::find_last_of ( const ustring str,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 456 of file ustring.h.

size_type ustring::find_last_of ( const std::string &  str,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 462 of file ustring.h.

size_type ustring::find_last_of ( const char *  s,
size_type  pos,
size_type  n 
) const
inline

Definition at line 468 of file ustring.h.

size_type ustring::find_last_of ( const char *  s,
size_type  pos = npos 
) const
inline

Definition at line 473 of file ustring.h.

size_type ustring::find_last_of ( char  c,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 478 of file ustring.h.

template<typename... Args>
static OIIO_NODISCARD ustring ustring::fmtformat ( const char *  fmt,
const Args &...  args 
)
inlinestatic

Construct a ustring in a fmt::format-like fashion. In other words, something like: ustring s = ustring::fmtformat("blah {} {}", (int)foo, (float)bar); The argument list is fully typesafe. The formatting of the string will always use the classic "C" locale conventions (in particular, '.' as decimal separator for float values).

Definition at line 673 of file ustring.h.

template<typename... Args>
static OIIO_FORMAT_DEPRECATED ustring ustring::format ( const char *  fmt,
const Args &...  args 
)
inlinestatic

NOTE: Semi-DEPRECATED! This will someday switch to behave like fmt::format (or future std::format) but for now, it is back compatible and equivalent to sprintf.

Definition at line 683 of file ustring.h.

static OIIO_NODISCARD ustring ustring::from_hash ( hash_t  hash)
static

Return the ustring corresponding to the given hash, or the empty ustring() if there is no registered ustring with that hash. Note that if there are multiple ustrings with the same hash, this will return the first one it finds in the table.

static ustring ustring::from_unique ( const char *  unique)
inlinestatic

Create a ustring from characters guaranteed to already be ustring-clean, without having to run through the hash yet again. Use with extreme caution!!!

Definition at line 733 of file ustring.h.

static std::string ustring::getstats ( bool  verbose = true)
static

Return the statistics output as a string.

hash_t ustring::hash ( ) const
inlinenoexcept

Return a hashed version of the string.

Definition at line 318 of file ustring.h.

static size_t ustring::hash_collisions ( std::vector< ustring > *  collisions = nullptr)
static

Return the total number ustrings that have the exact hash as another ustring. If collisions is passed, store all the colliding ustrings in the vector.

static bool ustring::is_unique ( const char *  str)
inlinestatic

Is this character pointer a unique ustring representation of those characters? Useful for diagnostics and debugging.

Definition at line 725 of file ustring.h.

size_t ustring::length ( void  ) const
inlinenoexcept

Return the number of characters in the string.

Definition at line 309 of file ustring.h.

static const char* ustring::make_unique ( string_view  str)
static

Given a string_view, return a pointer to the unique version kept in the internal table (creating a new table entry if we haven't seen this sequence of characters before). N.B.: this is equivalent to ustring(str).c_str(). It's also the routine that is used directly by ustring's internals to generate the canonical unique copy of the characters.

static size_t ustring::memory ( )
static

Return the amount of memory consumed by the ustring table.

ustring::operator std::string ( ) const
inlineexplicitnoexcept

Conversion to std::string (explicit only!).

Definition at line 212 of file ustring.h.

ustring::operator string_view ( ) const
inlinenoexcept

Conversion to an OIIO::string_view.

Definition at line 209 of file ustring.h.

bool ustring::operator!= ( const ustring str) const
inlinenoexcept

Test two ustrings for inequality – are they comprised of different sequences of characters. Note that because ustrings are unique, this is a trivial pointer comparison, not a char-by-char loop as would be the case with a char* or a std::string.

Definition at line 574 of file ustring.h.

bool ustring::operator!= ( const std::string &  x) const
inlinenoexcept

Test a ustring (*this) for lexicographic inequality with std::string x.

Definition at line 616 of file ustring.h.

bool ustring::operator!= ( string_view  x) const
inlinenoexcept

Test a ustring (*this) for lexicographic inequality with string_view x.

Definition at line 623 of file ustring.h.

bool ustring::operator!= ( const char *  x) const
inlinenoexcept

Test a ustring (this) for lexicographic inequality with char x.

Definition at line 627 of file ustring.h.

bool ustring::operator< ( const ustring x) const
inlinenoexcept

Test for lexicographic 'less', comes in handy for lots of STL containers and algorithms.

Definition at line 652 of file ustring.h.

const ustring& ustring::operator= ( const ustring str)
inline

Assign a ustring to another ustring.

Definition at line 272 of file ustring.h.

const ustring& ustring::operator= ( const char *  str)
inline

Assign a null-terminated C string (char *) to a ustring.

Definition at line 275 of file ustring.h.

const ustring& ustring::operator= ( const std::string &  str)
inline

Assign a C++ std::string to a ustring.

Definition at line 278 of file ustring.h.

const ustring& ustring::operator= ( string_view  str)
inline

Assign a string_view to a ustring.

Definition at line 281 of file ustring.h.

const ustring& ustring::operator= ( char  c)
inline

Assign a single char to a ustring.

Definition at line 284 of file ustring.h.

bool ustring::operator== ( const ustring str) const
inlinenoexcept

Test two ustrings for equality – are they comprised of the same sequence of characters. Note that because ustrings are unique, this is a trivial pointer comparison, not a char-by-char loop as would be the case with a char* or a std::string.

Definition at line 565 of file ustring.h.

bool ustring::operator== ( const std::string &  x) const
inlinenoexcept

Test a ustring (*this) for lexicographic equality with std::string x.

Definition at line 581 of file ustring.h.

bool ustring::operator== ( string_view  x) const
inlinenoexcept

Test a ustring (*this) for lexicographic equality with string_view x.

Definition at line 588 of file ustring.h.

bool ustring::operator== ( const char *  x) const
inlinenoexcept

Test a ustring (this) for lexicographic equality with char x.

Definition at line 591 of file ustring.h.

const_reference ustring::operator[] ( size_type  pos) const
inlinenoexcept

Return a reference to the character at the given position. Note that it's up to the caller to be sure pos is within the size of the string.

Definition at line 355 of file ustring.h.

const_reverse_iterator ustring::rbegin ( ) const
inlinenoexcept

Return a const_reverse_iterator that references the last character of the string.

Definition at line 346 of file ustring.h.

const_reverse_iterator ustring::rend ( ) const
inlinenoexcept

Return a const_reverse_iterator that references the end of a reverse traversal of the characters of the string.

Definition at line 350 of file ustring.h.

size_type ustring::rfind ( const ustring str,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 404 of file ustring.h.

size_type ustring::rfind ( const std::string &  str,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 409 of file ustring.h.

size_type ustring::rfind ( const char *  s,
size_type  pos,
size_type  n 
) const
inline

Definition at line 414 of file ustring.h.

size_type ustring::rfind ( const char *  s,
size_type  pos = npos 
) const
inline

Definition at line 419 of file ustring.h.

size_type ustring::rfind ( char  c,
size_type  pos = npos 
) const
inlinenoexcept

Definition at line 424 of file ustring.h.

size_t ustring::size ( void  ) const
inlinenoexcept

Return the number of characters in the string.

Definition at line 330 of file ustring.h.

template<typename... Args>
static OIIO_NODISCARD ustring ustring::sprintf ( const char *  fmt,
const Args &...  args 
)
inlinestatic

Construct a ustring in a printf-like fashion. In other words, something like: ustring s = ustring::sprintf("blah %d %g", (int)foo, (float)bar); The argument list is fully typesafe. The formatting of the string will always use the classic "C" locale conventions (in particular, '.' as decimal separator for float values).

Definition at line 661 of file ustring.h.

const std::string& ustring::string ( void  ) const
inlinenoexcept

Return a C++ std::string representation of a ustring.

Definition at line 296 of file ustring.h.

ustring ustring::substr ( size_type  pos = 0,
size_type  n = npos 
) const
inline

Returns a substring of the ustring object consisting of n characters starting at position pos.

Definition at line 374 of file ustring.h.

static size_t ustring::total_ustrings ( )
static

Return the total number of ustrings in the internal table.

ustringhash ustring::uhash ( ) const
inlinenoexcept

Return a hashed version of the string.

Definition at line 1016 of file ustring.h.

Friends And Related Function Documentation

int compare ( const std::string &  a,
const ustring b 
)
friend

Return 0 if a is lexicographically equal to b, -1 if a is lexicographically earlier than b, 1 if a is lexicographically after b.

Definition at line 556 of file ustring.h.

bool operator!= ( const std::string &  a,
const ustring b 
)
friend

Test for lexicographic inequality between std::string a and ustring b.

Definition at line 631 of file ustring.h.

bool operator!= ( string_view  a,
const ustring b 
)
friend

Test for lexicographic inequality between string_view a and ustring b.

Definition at line 638 of file ustring.h.

bool operator!= ( const char *  a,
const ustring b 
)
friend

Test for lexicographic inequality between char* a and ustring b.

Definition at line 645 of file ustring.h.

std::ostream& operator<< ( std::ostream &  out,
const ustring str 
)
friend

Generic stream output of a ustring.

Definition at line 694 of file ustring.h.

bool operator== ( const std::string &  a,
const ustring b 
)
friend

Test for lexicographic equality between std::string a and ustring b.

Definition at line 595 of file ustring.h.

bool operator== ( string_view  a,
const ustring b 
)
friend

Test for lexicographic equality between string_view a and ustring b.

Definition at line 602 of file ustring.h.

bool operator== ( const char *  a,
const ustring b 
)
friend

Test for lexicographic equality between char* a and ustring b.

Definition at line 609 of file ustring.h.

Member Data Documentation

const size_type ustring::npos = static_cast<size_type>(-1)
static

Definition at line 135 of file ustring.h.


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