openMSX
Classes | Enumerations | Functions
StringOp Namespace Reference

Classes

struct  casecmp
 
struct  caseless
 
struct  inv_caseless
 

Enumerations

enum class  EmptyParts { KEEP , REMOVE }
 

Functions

bool stringToBool (string_view str)
 
std::string toLower (std::string_view str)
 
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<std::integral T>
std::optional< T > stringTo (std::string_view s)
 Convert a string to an integral type 'T' (int, uint64_t, ...).
 
template<int BASE, std::integral T>
std::optional< T > stringToBase (std::string_view s)
 As above, but without dynamic base detection.
 
template<EmptyParts keepOrRemove = EmptyParts::KEEP, typename Separators >
auto split_view (std::string_view str, Separators separators)
 
bool containsCaseInsensitive (std::string_view haystack, std::string_view needle)
 

Enumeration Type Documentation

◆ EmptyParts

enum class StringOp::EmptyParts
strong
Enumerator
KEEP 
REMOVE 

Definition at line 78 of file StringOp.hh.

Function Documentation

◆ containsCaseInsensitive()

bool StringOp::containsCaseInsensitive ( std::string_view  haystack,
std::string_view  needle 
)
inline

◆ parseRange()

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

Definition at line 181 of file StringOp.cc.

Referenced by openmsx::SoundDevice::registerSound(), and TEST_CASE().

◆ split_view()

template<EmptyParts keepOrRemove = EmptyParts::KEEP, typename Separators >
auto StringOp::split_view ( std::string_view  str,
Separators  separators 
)
inline

◆ splitOnFirst() [1/2]

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

Definition at line 103 of file StringOp.cc.

◆ splitOnFirst() [2/2]

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

◆ splitOnLast() [1/2]

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

Definition at line 120 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 112 of file StringOp.cc.

◆ stringTo()

template<std::integral 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 207 of file StringOp.hh.

◆ stringToBase()

template<int BASE, std::integral 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 194 of file StringOp.hh.

◆ stringToBool()

bool StringOp::stringToBool ( string_view  str)

◆ toLower()

std::string StringOp::toLower ( std::string_view  str)

Definition at line 26 of file StringOp.cc.

References transform_in_place().

Referenced by openmsx::SymbolManager::detectType().

◆ trim() [1/2]

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

Definition at line 89 of file StringOp.cc.

References trimLeft(), and trimRight().

◆ trim() [2/2]

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

Definition at line 83 of file StringOp.cc.

References trimLeft(), and trimRight().

◆ trimLeft() [1/4]

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

Definition at line 66 of file StringOp.cc.

◆ trimLeft() [2/4]

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

Definition at line 62 of file StringOp.cc.

Referenced by trim(), and trim().

◆ trimLeft() [3/4]

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

Definition at line 76 of file StringOp.cc.

◆ trimLeft() [4/4]

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

Definition at line 70 of file StringOp.cc.

◆ trimRight() [1/4]

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

Definition at line 41 of file StringOp.cc.

◆ trimRight() [2/4]

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

Definition at line 33 of file StringOp.cc.

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

◆ trimRight() [3/4]

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

Definition at line 55 of file StringOp.cc.

◆ trimRight() [4/4]

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

Definition at line 49 of file StringOp.cc.