openMSX
Classes | Functions
StringOp Namespace Reference

Classes

struct  caseless
 
struct  casecmp
 

Functions

bool stringToBool (string_view str)
 
bool startsWith (string_view total, string_view part)
 
bool startsWith (string_view total, char part)
 
bool endsWith (string_view total, string_view part)
 
bool endsWith (string_view total, char part)
 
void trimRight (string &str, const char *chars)
 
void trimRight (string &str, char chars)
 
void trimRight (string_view &str, string_view chars)
 
void trimRight (string_view &str, char chars)
 
void trimLeft (string &str, const char *chars)
 
void trimLeft (string &str, char chars)
 
void trimLeft (string_view &str, string_view chars)
 
void trimLeft (string_view &str, char chars)
 
void trim (string_view &str, string_view chars)
 
void trim (string_view &str, char chars)
 
std::pair< string_view, string_view > splitOnFirst (string_view str, string_view chars)
 
std::pair< string_view, string_view > splitOnFirst (string_view str, char chars)
 
std::pair< string_view, string_view > splitOnLast (string_view str, string_view chars)
 
std::pair< string_view, string_view > splitOnLast (string_view str, char chars)
 
IterableBitSet< 64 > parseRange (string_view str, unsigned min, unsigned max)
 
template<typename T >
std::optional< T > stringTo (std::string_view s)
 Convert a string to an integral type 'T' (int, uint64_t, ...). More...
 
template<int BASE, typename T >
std::optional< T > stringToBase (std::string_view s)
 As above, but without dynamic base detection. More...
 
auto split_view (std::string_view str, char c)
 

Function Documentation

◆ endsWith() [1/2]

bool StringOp::endsWith ( string_view  total,
char  part 
)

Definition at line 44 of file StringOp.cc.

◆ endsWith() [2/2]

bool StringOp::endsWith ( string_view  total,
string_view  part 
)

◆ parseRange()

IterableBitSet< 64 > StringOp::parseRange ( string_view  str,
unsigned  min,
unsigned  max 
)

Definition at line 197 of file StringOp.cc.

References gl::max(), and gl::min().

Referenced by openmsx::SoundDevice::registerSound().

◆ split_view()

auto StringOp::split_view ( std::string_view  str,
char  c 
)
inline

Definition at line 83 of file StringOp.hh.

References begin(), end(), openmsx::operator!=(), operator*(), and openmsx::operator==().

Referenced by openmsx::TTFFont::render().

◆ splitOnFirst() [1/2]

std::pair< std::string_view, std::string_view > StringOp::splitOnFirst ( string_view  str,
char  chars 
)

Definition at line 119 of file StringOp.cc.

◆ splitOnFirst() [2/2]

std::pair< std::string_view, std::string_view > StringOp::splitOnFirst ( string_view  str,
string_view  chars 
)

Definition at line 111 of file StringOp.cc.

◆ splitOnLast() [1/2]

std::pair< std::string_view, std::string_view > StringOp::splitOnLast ( string_view  str,
char  chars 
)

Definition at line 136 of file StringOp.cc.

◆ splitOnLast() [2/2]

std::pair< std::string_view, std::string_view > StringOp::splitOnLast ( string_view  str,
string_view  chars 
)

Definition at line 128 of file StringOp.cc.

◆ startsWith() [1/2]

bool StringOp::startsWith ( string_view  total,
char  part 
)

Definition at line 34 of file StringOp.cc.

◆ startsWith() [2/2]

bool StringOp::startsWith ( string_view  total,
string_view  part 
)

◆ stringTo()

template<typename T >
std::optional< T > StringOp::stringTo ( std::string_view  s)

Convert a string to an integral type 'T' (int, uint64_t, ...).

This is similar to, but not quite the same as the family of 'strtoll()' functions:

  • Leading whitespace is NOT accepted (unlike strtoll()).
  • There may NOT be any trailing character after the value (unlike strtoll()).
  • (Only) if 'T' is a signed type, the value may start with a '-' character.
  • A leading '+' character is NOT accepted.
  • It's an error if the value cannot be represented by the type 'T'.
  • This function tries to detect the base of the value by looking at the prefix. (Only) these prefixes are accepted:
    • '0x' or '0X': hexadecimal
    • '0b' or '0B': binary
    • no prefix: decimal Note that prefix '0' for octal is NOT supported.
  • The input is a 'string_view' (rather than a 'const char*'), so it is not required to be zero-terminated.

Definition at line 163 of file StringOp.hh.

References likely, gl::max(), and unlikely.

◆ stringToBase()

template<int BASE, typename T >
std::optional< T > StringOp::stringToBase ( std::string_view  s)

As above, but without dynamic base detection.

Moreover leading prefixes like '0x' for hexadecimal are seen as invalid input.

Definition at line 150 of file StringOp.hh.

◆ stringToBool()

bool StringOp::stringToBool ( string_view  str)

◆ trim() [1/2]

void StringOp::trim ( string_view &  str,
char  chars 
)

Definition at line 105 of file StringOp.cc.

References trimLeft(), and trimRight().

◆ trim() [2/2]

void StringOp::trim ( string_view &  str,
string_view  chars 
)

Definition at line 99 of file StringOp.cc.

References trimLeft(), and trimRight().

◆ trimLeft() [1/4]

void StringOp::trimLeft ( string &  str,
char  chars 
)

Definition at line 82 of file StringOp.cc.

◆ trimLeft() [2/4]

void StringOp::trimLeft ( string &  str,
const char *  chars 
)

Definition at line 78 of file StringOp.cc.

Referenced by trim().

◆ trimLeft() [3/4]

void StringOp::trimLeft ( string_view &  str,
char  chars 
)

Definition at line 92 of file StringOp.cc.

◆ trimLeft() [4/4]

void StringOp::trimLeft ( string_view &  str,
string_view  chars 
)

Definition at line 86 of file StringOp.cc.

◆ trimRight() [1/4]

void StringOp::trimRight ( string &  str,
char  chars 
)

Definition at line 57 of file StringOp.cc.

◆ trimRight() [2/4]

void StringOp::trimRight ( string &  str,
const char *  chars 
)

Definition at line 49 of file StringOp.cc.

Referenced by openmsx::TTFFont::render(), and trim().

◆ trimRight() [3/4]

void StringOp::trimRight ( string_view &  str,
char  chars 
)

Definition at line 71 of file StringOp.cc.

◆ trimRight() [4/4]

void StringOp::trimRight ( string_view &  str,
string_view  chars 
)

Definition at line 65 of file StringOp.cc.