Vuo  2.0.0
Static Public Member Functions | Static Public Attributes | List of all members
VuoStringUtilities Class Reference

Description

Functions for dealing with strings.

Definition at line 18 of file VuoStringUtilities.hh.

Static Public Member Functions

static bool beginsWith (string wholeString, string beginning)
 Returns true if wholeString begins with beginning. More...
 
static bool endsWith (string wholeString, string ending)
 Returns true if wholeString ends with ending. More...
 
static string substrAfter (string wholeString, string beginning)
 Returns the substring of wholeString that follows beginning, or an empty string if wholeString does not begin with beginning. More...
 
static string substrBefore (string wholeString, string ending)
 Returns the substring of wholeString that precedes ending, or an empty string if wholeString does not end with ending. More...
 
static string replaceAll (string wholeString, char originalChar, char replacementChar)
 Returns a string constructed by replacing all instances of originalChar with replacementChar in wholeString. More...
 
static size_t replaceAll (string &wholeString, string originalSubstring, string replacementSubstring)
 Replaces all instances of originalSubstring with replacementSubstring in wholeString. More...
 
static vector< string > split (const string &wholeString, char delimiter)
 Splits wholeString into parts, as separated by delimiter. More...
 
static string join (vector< string > partialStrings, char delimiter)
 Combines partialStrings, separated by delimiter, into one string. More...
 
static string join (vector< string > partialStrings, string delimiter)
 Combines partialStrings, separated by delimiter, into one string. More...
 
static string join (set< string > partialStrings, string delimiter)
 Combines partialStrings, separated by delimiter, into one string. More...
 
static string trim (string originalString)
 Returns a new string with the whitespace removed from the beginning and end. More...
 
static string buildCompositionIdentifier (const string &parentCompositionIdentifier, const string &nodeIdentifier)
 Returns a string that starts with parentCompositionIdentifier and ends with nodeIdentifier. More...
 
static string buildPortIdentifier (const string &nodeIdentifier, const string &portName)
 Returns a string that starts with nodeIdentifier and ends with portName. More...
 
static string prefixSymbolName (string symbolName, string moduleKey)
 Returns a string that starts with moduleKey and ends with symbolName. More...
 
static bool isValidCharInIdentifier (char ch)
 Check whether a character is valid for an identifier, i.e., matches [A-Za-z0-9_]. More...
 
static string transcodeToIdentifier (string str)
 Transforms a string into a valid identifier: More...
 
static string transcodeToGraphvizIdentifier (const string &originalString)
 Escapes backslashes, quotes, curly braces, angle brackets, and pipes in the string, making it a valid identifier in the Graphviz DOT language. More...
 
static string transcodeFromGraphvizIdentifier (const string &graphvizIdentifier)
 Removes escapes for backslashes, quotes, curly braces, angle brackets, and pipes in the Graphviz identifier, making it a normal string. More...
 
static string formUniqueIdentifier (set< string > &takenIdentifiers, const string &preferredIdentifier, const string &identifierPrefix="")
 Returns preferredIdentifier if it's available (not already in usedIdentifiers), otherwise creates an identifier that is available by adding a suffix to identifierPrefix (if provided) or preferredIdentifier. More...
 
static string formUniqueIdentifier (std::function< bool(const string &)> isIdentifierAvailable, const string &preferredIdentifier, const string &identifierPrefix="")
 Returns preferredIdentifier if it's available (according to isIdentifierAvailable), otherwise creates an identifier that is available by adding a suffix to identifierPrefix (if provided) or preferredIdentifier. More...
 
static string generateHtmlFromMarkdown (const string &markdownString)
 Converts markdownString (a Markdown document) to HTML. More...
 
static string generateHtmlFromMarkdownLine (const string &markdownString)
 Converts markdownString (a single line of Markdown text) to HTML. More...
 
static string convertToCamelCase (const string &originalString, bool capitalizeFirstLetter, bool forceFirstLetterToLower, bool forceInterveningLettersToLower, bool allowSeparatorDots=false)
 Collapses a string into camel case by removing non-alphanumeric characters and adjusting capitalization. More...
 
static string expandCamelCase (string camelCaseString)
 Inserts spaces at CamelCase transitions within the input camelCaseString, capitalizes the first letter of the string, and returns the result. More...
 
static string makeRandomHash (int length)
 Returns a random sequence of alphanumeric characters. More...
 
static long hash (const string &s)
 Generates an integer hash value for the string. More...
 

Static Public Attributes

static const std::locale locale
 For hashing strings. More...
 
static const std::collate< char > & collate = std::use_facet<std::collate<char> >(VuoStringUtilities::locale)
 For hashing strings. More...
 

Member Function Documentation

◆ beginsWith()

bool VuoStringUtilities::beginsWith ( string  wholeString,
string  beginning 
)
static

Returns true if wholeString begins with beginning.

Definition at line 21 of file VuoStringUtilities.cc.

◆ buildCompositionIdentifier()

string VuoStringUtilities::buildCompositionIdentifier ( const string &  parentCompositionIdentifier,
const string &  nodeIdentifier 
)
static

Returns a string that starts with parentCompositionIdentifier and ends with nodeIdentifier.

The glue between them is a non-identifier character so that the string can be unambiguously split later.

This needs to be kept in sync with VuoCompilerNode::generateSubcompositionIdentifierValue().

Definition at line 173 of file VuoStringUtilities.cc.

◆ buildPortIdentifier()

string VuoStringUtilities::buildPortIdentifier ( const string &  nodeIdentifier,
const string &  portName 
)
static

Returns a string that starts with nodeIdentifier and ends with portName.

The glue between them is a non-identifier character so that the string can be unambiguously split later.

Definition at line 182 of file VuoStringUtilities.cc.

◆ convertToCamelCase()

string VuoStringUtilities::convertToCamelCase ( const string &  originalString,
bool  forceFirstLetterToUpper,
bool  forceFirstLetterToLower,
bool  forceInterveningLettersToLower,
bool  allowSeparatorDots = false 
)
static

Collapses a string into camel case by removing non-alphanumeric characters and adjusting capitalization.

Also removes non-alpha leading characters.

Parameters
originalStringThe input.
forceFirstLetterToUpperIf true, make the string UpperCamelCase. Otherwise, leave the first letter as-is.
forceFirstLetterToLowerIf true, make the string lowerCamelCase. Otherwise, leave the first letter as-is.
forceInterveningLettersToLowerIf true, make letters within words lowercase. Otherwise, leave them as-is.
allowSeparatorDotsIf true, intermediate dots (.) are preserved. Leading, consecutive intermediate, and trailing dots are omitted. Letters following dots are not forced to uppercase.

Definition at line 422 of file VuoStringUtilities.cc.

◆ endsWith()

bool VuoStringUtilities::endsWith ( string  wholeString,
string  ending 
)
static

Returns true if wholeString ends with ending.

Definition at line 29 of file VuoStringUtilities.cc.

◆ expandCamelCase()

string VuoStringUtilities::expandCamelCase ( string  camelCaseString)
static

Inserts spaces at CamelCase transitions within the input camelCaseString, capitalizes the first letter of the string, and returns the result.

Also renders standalone variable names (e.g., "x") and some common abbreviations (e.g., "rgb") in all-caps.

Definition at line 476 of file VuoStringUtilities.cc.

◆ formUniqueIdentifier() [1/2]

string VuoStringUtilities::formUniqueIdentifier ( set< string > &  takenIdentifiers,
const string &  preferredIdentifier,
const string &  identifierPrefix = "" 
)
static

Returns preferredIdentifier if it's available (not already in usedIdentifiers), otherwise creates an identifier that is available by adding a suffix to identifierPrefix (if provided) or preferredIdentifier.

The returned identifier is added to usedIdentifiers.

Definition at line 335 of file VuoStringUtilities.cc.

◆ formUniqueIdentifier() [2/2]

string VuoStringUtilities::formUniqueIdentifier ( std::function< bool(const string &)>  isIdentifierAvailable,
const string &  preferredIdentifier,
const string &  identifierPrefix = "" 
)
static

Returns preferredIdentifier if it's available (according to isIdentifierAvailable), otherwise creates an identifier that is available by adding a suffix to identifierPrefix (if provided) or preferredIdentifier.

Definition at line 353 of file VuoStringUtilities.cc.

◆ generateHtmlFromMarkdown()

string VuoStringUtilities::generateHtmlFromMarkdown ( const string &  markdownString)
static

Converts markdownString (a Markdown document) to HTML.

The returned HTML includes a paragraph wrapper around each line of text.

Definition at line 375 of file VuoStringUtilities.cc.

◆ generateHtmlFromMarkdownLine()

string VuoStringUtilities::generateHtmlFromMarkdownLine ( const string &  markdownString)
static

Converts markdownString (a single line of Markdown text) to HTML.

The returned HTML does not include a paragraph wrapper.

Definition at line 396 of file VuoStringUtilities.cc.

◆ hash()

static long VuoStringUtilities::hash ( const string &  s)
inlinestatic

Generates an integer hash value for the string.

Definition at line 55 of file VuoStringUtilities.hh.

◆ isValidCharInIdentifier()

bool VuoStringUtilities::isValidCharInIdentifier ( char  ch)
static

Check whether a character is valid for an identifier, i.e., matches [A-Za-z0-9_].

Definition at line 273 of file VuoStringUtilities.cc.

◆ join() [1/3]

string VuoStringUtilities::join ( set< string >  partialStrings,
string  delimiter 
)
static

Combines partialStrings, separated by delimiter, into one string.

Definition at line 135 of file VuoStringUtilities.cc.

◆ join() [2/3]

string VuoStringUtilities::join ( vector< string >  partialStrings,
char  delimiter 
)
static

Combines partialStrings, separated by delimiter, into one string.

Definition at line 111 of file VuoStringUtilities.cc.

◆ join() [3/3]

string VuoStringUtilities::join ( vector< string >  partialStrings,
string  delimiter 
)
static

Combines partialStrings, separated by delimiter, into one string.

Definition at line 120 of file VuoStringUtilities.cc.

◆ makeRandomHash()

string VuoStringUtilities::makeRandomHash ( int  length)
static

Returns a random sequence of alphanumeric characters.

Definition at line 545 of file VuoStringUtilities.cc.

◆ prefixSymbolName()

string VuoStringUtilities::prefixSymbolName ( string  symbolName,
string  moduleKey 
)
static

Returns a string that starts with moduleKey and ends with symbolName.

Useful for adding a unique prefix to a symbol name.

Definition at line 191 of file VuoStringUtilities.cc.

◆ replaceAll() [1/2]

size_t VuoStringUtilities::replaceAll ( string &  wholeString,
string  originalSubstring,
string  replacementSubstring 
)
static

Replaces all instances of originalSubstring with replacementSubstring in wholeString.

Returns the number of instances replaced.

Definition at line 82 of file VuoStringUtilities.cc.

◆ replaceAll() [2/2]

string VuoStringUtilities::replaceAll ( string  wholeString,
char  originalChar,
char  replacementChar 
)
static

Returns a string constructed by replacing all instances of originalChar with replacementChar in wholeString.

Definition at line 65 of file VuoStringUtilities.cc.

◆ split()

vector< string > VuoStringUtilities::split ( const string &  wholeString,
char  delimiter 
)
static

Splits wholeString into parts, as separated by delimiter.

Definition at line 98 of file VuoStringUtilities.cc.

◆ substrAfter()

string VuoStringUtilities::substrAfter ( string  wholeString,
string  beginning 
)
static

Returns the substring of wholeString that follows beginning, or an empty string if wholeString does not begin with beginning.

Definition at line 41 of file VuoStringUtilities.cc.

◆ substrBefore()

string VuoStringUtilities::substrBefore ( string  wholeString,
string  ending 
)
static

Returns the substring of wholeString that precedes ending, or an empty string if wholeString does not end with ending.

Definition at line 53 of file VuoStringUtilities.cc.

◆ transcodeFromGraphvizIdentifier()

string VuoStringUtilities::transcodeFromGraphvizIdentifier ( const string &  graphvizIdentifier)
static

Removes escapes for backslashes, quotes, curly braces, angle brackets, and pipes in the Graphviz identifier, making it a normal string.

Definition at line 306 of file VuoStringUtilities.cc.

◆ transcodeToGraphvizIdentifier()

string VuoStringUtilities::transcodeToGraphvizIdentifier ( const string &  originalString)
static

Escapes backslashes, quotes, curly braces, angle brackets, and pipes in the string, making it a valid identifier in the Graphviz DOT language.

Definition at line 281 of file VuoStringUtilities.cc.

◆ transcodeToIdentifier()

string VuoStringUtilities::transcodeToIdentifier ( string  str)
static

Transforms a string into a valid identifier:

  • Replaces whitespace and '.'s with '_'s
  • Replaces '/'s and ':'s with '__'s
  • Strips out characters not in [A-Za-z0-9_]

Definition at line 202 of file VuoStringUtilities.cc.

◆ trim()

string VuoStringUtilities::trim ( string  originalString)
static

Returns a new string with the whitespace removed from the beginning and end.

This function trims ASCII spaces, tabs, and linebreaks, but not other Unicode whitespace characters.

See also
VuoText_trim

Definition at line 154 of file VuoStringUtilities.cc.

Member Data Documentation

◆ collate

const std::collate< char > & VuoStringUtilities::collate = std::use_facet<std::collate<char> >(VuoStringUtilities::locale)
static

For hashing strings.

Definition at line 61 of file VuoStringUtilities.hh.

◆ locale

const std::locale VuoStringUtilities::locale
static

For hashing strings.

Definition at line 60 of file VuoStringUtilities.hh.


The documentation for this class was generated from the following files: