VCV Rack API  v1
rack::string Namespace Reference

Supplemental std::string functions. More...

Classes

struct  CaseInsensitiveCompare
 

Functions

std::string fromWstring (const std::wstring &s)
 Converts a UTF-16/32 string (depending on the size of wchar_t) to a UTF-8 string. More...
 
std::wstring toWstring (const std::string &s)
 
std::string f (const char *format,...)
 Converts a printf() format string and optional arguments into a std::string. More...
 
std::string lowercase (const std::string &s)
 Replaces all characters to lowercase letters. More...
 
std::string uppercase (const std::string &s)
 Replaces all characters to uppercase letters. More...
 
std::string trim (const std::string &s)
 Removes whitespace from beginning and end of string. More...
 
std::string ellipsize (const std::string &s, size_t len)
 Truncates and adds "..." to a string, not exceeding len characters. More...
 
std::string ellipsizePrefix (const std::string &s, size_t len)
 
bool startsWith (const std::string &str, const std::string &prefix)
 
bool endsWith (const std::string &str, const std::string &suffix)
 
std::string directory (const std::string &path)
 Extracts the directory of the path. More...
 
std::string filename (const std::string &path)
 Extracts the filename of the path. More...
 
std::string filenameBase (const std::string &filename)
 Extracts the portion of a filename without the extension. More...
 
std::string filenameExtension (const std::string &filename)
 Extracts the extension of a filename. More...
 
std::string absolutePath (const std::string &path)
 Returns the canonicalized absolute path pointed to by path, following symlinks. More...
 
float fuzzyScore (const std::string &s, const std::string &query)
 Scores how well a query matches a string. More...
 
std::string toBase64 (const uint8_t *data, size_t len)
 Converts a byte array to a Base64-encoded string. More...
 
uint8_t * fromBase64 (const std::string &str, size_t *outLen)
 Converts a Base64-encoded string to a byte array. More...
 

Detailed Description

Supplemental std::string functions.

Function Documentation

◆ fromWstring()

std::string rack::string::fromWstring ( const std::wstring &  s)

Converts a UTF-16/32 string (depending on the size of wchar_t) to a UTF-8 string.

◆ toWstring()

std::wstring rack::string::toWstring ( const std::string &  s)

◆ f()

std::string rack::string::f ( const char *  format,
  ... 
)

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 might 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 a string, not exceeding len characters.

◆ ellipsizePrefix()

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

◆ startsWith()

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

◆ endsWith()

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

◆ directory()

std::string rack::string::directory ( const std::string &  path)

Extracts the directory of the path.

Example: directory("dir/file.txt") // "dir" Calls POSIX dirname().

◆ filename()

std::string rack::string::filename ( const std::string &  path)

Extracts the filename of the path.

Example: directory("dir/file.txt") // "file.txt" Calls POSIX basename().

◆ filenameBase()

std::string rack::string::filenameBase ( const std::string &  filename)

Extracts the portion of a filename without the extension.

Example: filenameBase("file.txt") // "file" Note: Only works on filenames. Call filename(path) to get the filename of the path.

◆ filenameExtension()

std::string rack::string::filenameExtension ( const std::string &  filename)

Extracts the extension of a filename.

Example: filenameExtension("file.txt") // "txt" Note: Only works on filenames. Call filename(path) to get the filename of the path.

◆ absolutePath()

std::string rack::string::absolutePath ( const std::string &  path)

Returns the canonicalized absolute path pointed to by path, following symlinks.

Returns "" if the symbol is not found.

◆ fuzzyScore()

float rack::string::fuzzyScore ( const std::string &  s,
const std::string &  query 
)

Scores how well a query matches a string.

A score of 0 means no match. The score is arbitrary and is only meaningful for sorting.

◆ toBase64()

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

Converts a byte array to a Base64-encoded string.

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

◆ fromBase64()

uint8_t* rack::string::fromBase64 ( const std::string &  str,
size_t *  outLen 
)

Converts a Base64-encoded string to a byte array.

outLen is set to the length of the byte array. If non-NULL, caller must delete[] the result.