Class utils#
Defined in File utils.h
Nested Relationships#
Nested Types#
Class Documentation#
-
class utils#
Class containing useful static functions.
A class containing useful static functions unrelated to other classes.
Public Static Functions
-
static unsigned int textDistance(const std::string &strA, const std::string &strB)#
Compute the Levenshtein distance between two strings. Can be useful for spell checking and typo detection.
-
static std::vector<std::string> tokenize(std::string_view str)#
Tokenize provided string_view into a vector of strings, using the same logic as bash.
Split by spaces unless between quotes
Split by quoted section and remove the quotes
Supported quotes are: ‘”`
Use escaped \ quotes, spaces and escape to add them verbatim
Comments are supported with
#
, any characters after are ignoredUse escaped # to add it verbatim
Other escaped characters are also added verbatim Throw a tokenize_exception if a quoted section is not closed or if finishing with an escape
Examples:
set scene.up.direction +Z
->set
scene.up.direction
+Z
set render.hdri.file "/path/to/file with spaces.png"
->set
,render.hdri.file
,/path/to/file with spaces.png
set render.hdri.file /path/to/file with spaces.png’->
set,
render.hdri.file<tt>,/path/to/file with spaces.png<tt> set render.hdri.file “/path/to/file’with’quotes.png”->
set,
render.hdri.file<tt>,/path/to/file’with’quotes.png<tt> set render.hdri.file /path/to/file\ spaces\ 'quotes”.png` -> `set`, `render.hdri.file`, `/path/to/file spaces ‘quotes”.png,
render.hdri.file<tt>,C:\path\to\windows\file.png->
set,
scene.up.direction<tt>,+Z->
set,
scene.up.direction<tt>,+Z-> tokenize_exception
set scene.up.direction +Z` -> tokenize_exception
-
class string_template#
String template allowing substitution of variables enclosed in curly braces.
string_template("{greeting} {name}!") .substitute({ { "greeting", "hello" }, { "name", "World" } }) .str() == "hello World!"
Public Functions
-
inline explicit string_template(const std::string &templateString)#
-
template<typename F>
string_template &substitute(F lookup)# Substitute variables based on a
std::string(const std::string&)
function. Variables for which the function throws astring_template::lookup_error
exception are left untouched.
-
inline string_template &substitute(const std::map<std::string, std::string> &lookup)#
Substitute variables based on a map. Variables for which the map does not contain a key are left untouched.
-
inline std::string str() const#
Return a string representation of the string template
-
inline std::vector<std::string> variables() const#
List the remaining un-substituted variables.
-
template<typename F>
utils::string_template &substitute(F lookup)#
-
inline explicit string_template(const std::string &templateString)#
-
static unsigned int textDistance(const std::string &strA, const std::string &strB)#