VCV Rack API v2
Loading...
Searching...
No Matches
rack::string Namespace Reference

Supplemental std::string functions. More...

Classes

struct  CaseInsensitiveCompare
 
struct  Version
 Structured version string, for comparison. More...
 

Functions

__attribute__((format(printf, 1, 2))) std std::string fV (const char *format, va_list args)
 Converts a printf() format string and optional arguments into a std::string.
 
std::string lowercase (const std::string &s)
 Replaces all characters to lowercase letters.
 
std::string uppercase (const std::string &s)
 Replaces all characters to uppercase letters.
 
std::string trim (const std::string &s)
 Removes whitespace from beginning and end of string.
 
std::string ellipsize (const std::string &s, size_t len)
 Truncates and adds "..." to the end of a string, not exceeding len characters.
 
std::string ellipsizePrefix (const std::string &s, size_t len)
 Truncates and adds "..." to the beginning of a string, not exceeding len characters.
 
bool startsWith (const std::string &str, const std::string &prefix)
 Returns whether a string starts with the given substring.
 
bool endsWith (const std::string &str, const std::string &suffix)
 Returns whether a string ends with the given substring.
 
std::string toBase64 (const uint8_t *data, size_t dataLen)
 Converts a byte array to a Base64-encoded string.
 
std::string toBase64 (const std::vector< uint8_t > &data)
 
std::vector< uint8_t > fromBase64 (const std::string &str)
 Converts a Base64-encoded string to a byte array.
 
template<typename TContainer >
std::string join (const TContainer &container, std::string seperator="")
 Joins an container (vector, list, etc) of std::strings with an optional separator string.
 
std::vector< std::string > split (const std::string &s, const std::string &seperator, size_t maxTokens=0)
 Splits a string into a vector of tokens.
 
std::string formatTime (const char *format, double timestamp)
 Formats a UNIX timestamp with a strftime() string.
 
std::string formatTimeISO (double timestamp)
 

Detailed Description

Supplemental std::string functions.

Function Documentation

◆ fV()

__attribute__((format(printf, 1, 2))) std std::string rack::string::fV ( const char *  format,
va_list  args 
)

Converts a printf() format string and optional arguments into a std::string.

Remember that "%s" must reference a char *, so use .c_str() for std::strings, otherwise you will get binary garbage.

◆ lowercase()

std::string rack::string::lowercase ( const std::string &  s)

Replaces all characters to lowercase letters.

◆ uppercase()

std::string rack::string::uppercase ( const std::string &  s)

Replaces all characters to uppercase letters.

◆ trim()

std::string rack::string::trim ( const std::string &  s)

Removes whitespace from beginning and end of string.

◆ ellipsize()

std::string rack::string::ellipsize ( const std::string &  s,
size_t  len 
)

Truncates and adds "..." to the end of a string, not exceeding len characters.

◆ ellipsizePrefix()

std::string rack::string::ellipsizePrefix ( const std::string &  s,
size_t  len 
)

Truncates and adds "..." to the beginning of a string, not exceeding len characters.

◆ startsWith()

bool rack::string::startsWith ( const std::string &  str,
const std::string &  prefix 
)

Returns whether a string starts with the given substring.

◆ endsWith()

bool rack::string::endsWith ( const std::string &  str,
const std::string &  suffix 
)

Returns whether a string ends with the given substring.

◆ toBase64() [1/2]

std::string rack::string::toBase64 ( const uint8_t *  data,
size_t  dataLen 
)

Converts a byte array to a Base64-encoded string.

https://en.wikipedia.org/wiki/Base64

◆ toBase64() [2/2]

std::string rack::string::toBase64 ( const std::vector< uint8_t > &  data)

◆ fromBase64()

std::vector< uint8_t > rack::string::fromBase64 ( const std::string &  str)

Converts a Base64-encoded string to a byte array.

Throws std::runtime_error if string is invalid.

◆ join()

template<typename TContainer >
std::string rack::string::join ( const TContainer &  container,
std::string  seperator = "" 
)

Joins an container (vector, list, etc) of std::strings with an optional separator string.

◆ split()

std::vector< std::string > rack::string::split ( const std::string &  s,
const std::string &  seperator,
size_t  maxTokens = 0 
)

Splits a string into a vector of tokens.

If maxTokens > 0, limits the number of tokens. Tokens do not include the separator string. Examples: split("a+b+c", "+") // {"a", "b", "c"} split("abc", "+") // {"abc"} split("a++c", "+") // {"a", "", "c"} split("", "+") // {} split("abc", "") // throws rack::Exception

◆ formatTime()

std::string rack::string::formatTime ( const char *  format,
double  timestamp 
)

Formats a UNIX timestamp with a strftime() string.

◆ formatTimeISO()

std::string rack::string::formatTimeISO ( double  timestamp)