Class utils#

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

  • 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.pngset 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”.pngset render.hdri.file C:\path\to\windows\file.png<tt>-> set,render.hdri.file<tt>,C:\path\to\windows\file.pngset scene.up.direction +\Z->set, scene.up.direction<tt>,+Zset scene.up.direction “+Z-> tokenize_exceptionset scene.up.direction +Z` -> tokenize_exception

struct tokenize_exception : public f3d::exception#

An exception that can be thrown by tokenize

Public Functions

explicit tokenize_exception(const std::string &what = "")#