Vuo 2.4.4
Loading...
Searching...
No Matches
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 (const string &wholeString, const string &beginning)
 Returns true if wholeString begins with beginning.
 
static bool beginsWith (const char *wholeString, const char *beginning)
 Returns true if wholeString begins with beginning.
 
static bool endsWith (const string &wholeString, const string &ending)
 Returns true if wholeString ends with ending.
 
static string substrAfter (const string &wholeString, const string &beginning)
 Returns the substring of wholeString that follows beginning, or an empty string if wholeString does not begin with beginning.
 
static string substrBefore (const string &wholeString, const string &ending)
 Returns the substring of wholeString that precedes ending, or an empty string if wholeString does not end with ending.
 
static string replaceAll (const string &wholeString, char originalChar, char replacementChar)
 Returns a string constructed by replacing all instances of originalChar with replacementChar in wholeString.
 
static size_t replaceAll (string &wholeString, const string &originalSubstring, const string &replacementSubstring)
 Replaces all instances of originalSubstring with replacementSubstring in wholeString.
 
static vector< stringsplit (const string &wholeString, char delimiter)
 Splits wholeString into parts, as separated by delimiter.
 
static string join (const vector< string > &partialStrings, char delimiter)
 Combines partialStrings, separated by delimiter, into one string.
 
static string join (const vector< string > &partialStrings, const string &delimiter)
 Combines partialStrings, separated by delimiter, into one string.
 
static string join (const set< string > &partialStrings, const string &delimiter)
 Combines partialStrings, separated by delimiter, into one string.
 
static string trim (const string &originalString)
 Returns a new string with the whitespace removed from the beginning and end.
 
static void doForEachLine (const string &multiLineString, std::function< void(const char *)> doForLine)
 Iiterates through the lines in multiLineString and calls doForLine for each one.
 
static string buildCompositionIdentifier (const string &parentCompositionIdentifier, const string &nodeIdentifier)
 Returns a string that starts with parentCompositionIdentifier and ends with nodeIdentifier.
 
static string buildPortIdentifier (const string &nodeIdentifier, const string &portName)
 Returns a string that starts with nodeIdentifier and ends with portName.
 
static string prefixSymbolName (const string &symbolName, const string &moduleKey)
 Returns a string that starts with moduleKey and ends with symbolName.
 
static bool isValidCharInIdentifier (char ch)
 Check whether a character is valid for an identifier, i.e., matches [A-Za-z0-9_].
 
static string transcodeToIdentifier (const string &str)
 Transforms a string into a valid identifier:
 
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.
 
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.
 
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.
 
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.
 
static string generateHtmlFromMarkdown (const string &markdownString)
 Converts markdownString (a Markdown document) to HTML.
 
static string generateHtmlFromMarkdownLine (const string &markdownString)
 Converts markdownString (a single line of Markdown text) to HTML.
 
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.
 
static string expandCamelCase (const string &camelCaseString)
 Inserts spaces at CamelCase transitions within the input camelCaseString, capitalizes the first letter of the string, and returns the result.
 
static string makeFromCFString (const void *cfs)
 Creates a string from a CFStringRef.
 
static string makeRandomHash (int length)
 Returns a random sequence of alphanumeric characters.
 
static long hash (const string &s)
 Generates an integer hash value for the string.
 
static string calculateSHA256 (const string &s)
 Returns the SHA-256 hash of the string s, as a string of hex digits.
 

Static Public Attributes

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

Member Function Documentation

◆ beginsWith() [1/2]

bool VuoStringUtilities::beginsWith ( const char wholeString,
const char beginning 
)
static

Returns true if wholeString begins with beginning.

Definition at line 32 of file VuoStringUtilities.cc.

◆ beginsWith() [2/2]

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

Returns true if wholeString begins with beginning.

Definition at line 24 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 220 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 229 of file VuoStringUtilities.cc.

◆ calculateSHA256()

string VuoStringUtilities::calculateSHA256 ( const string s)
static

Returns the SHA-256 hash of the string s, as a string of hex digits.

Exceptions
VuoException

Definition at line 632 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 462 of file VuoStringUtilities.cc.

◆ doForEachLine()

void VuoStringUtilities::doForEachLine ( const string multiLineString,
std::function< void(const char *)>  doForLine 
)
static

Iiterates through the lines in multiLineString and calls doForLine for each one.

Definition at line 181 of file VuoStringUtilities.cc.

◆ endsWith()

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

Returns true if wholeString ends with ending.

Definition at line 40 of file VuoStringUtilities.cc.

◆ expandCamelCase()

string VuoStringUtilities::expandCamelCase ( const 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 516 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 375 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 393 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 415 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 436 of file VuoStringUtilities.cc.

◆ hash()

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

Generates an integer hash value for the string.

Definition at line 58 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 313 of file VuoStringUtilities.cc.

◆ join() [1/3]

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

Combines partialStrings, separated by delimiter, into one string.

Definition at line 146 of file VuoStringUtilities.cc.

◆ join() [2/3]

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

Combines partialStrings, separated by delimiter, into one string.

Definition at line 122 of file VuoStringUtilities.cc.

◆ join() [3/3]

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

Combines partialStrings, separated by delimiter, into one string.

Definition at line 131 of file VuoStringUtilities.cc.

◆ makeFromCFString()

string VuoStringUtilities::makeFromCFString ( const void cfs)
static

Creates a string from a CFStringRef.

Definition at line 585 of file VuoStringUtilities.cc.

◆ makeRandomHash()

string VuoStringUtilities::makeRandomHash ( int  length)
static

Returns a random sequence of alphanumeric characters.

Definition at line 610 of file VuoStringUtilities.cc.

◆ prefixSymbolName()

string VuoStringUtilities::prefixSymbolName ( const string symbolName,
const 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 238 of file VuoStringUtilities.cc.

◆ replaceAll() [1/2]

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

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

Definition at line 76 of file VuoStringUtilities.cc.

◆ replaceAll() [2/2]

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

Replaces all instances of originalSubstring with replacementSubstring in wholeString.

Returns the number of instances replaced.

Definition at line 93 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 109 of file VuoStringUtilities.cc.

◆ substrAfter()

string VuoStringUtilities::substrAfter ( const string wholeString,
const 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 52 of file VuoStringUtilities.cc.

◆ substrBefore()

string VuoStringUtilities::substrBefore ( const string wholeString,
const 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 64 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 346 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 321 of file VuoStringUtilities.cc.

◆ transcodeToIdentifier()

string VuoStringUtilities::transcodeToIdentifier ( const 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 249 of file VuoStringUtilities.cc.

◆ trim()

string VuoStringUtilities::trim ( const 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 165 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 64 of file VuoStringUtilities.hh.

◆ locale

const std::locale VuoStringUtilities::locale
static

For hashing strings.

Definition at line 63 of file VuoStringUtilities.hh.


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