File MIES_Utilities_Strings.ipf

utility functions for string handling

Functions

string ExtractStringFromPair(string str, string key, string keySep = defaultValue, string listSep = defaultValue)

Same functionality as GetStringFromWaveNote() but accepts a string.

string PossiblyUnquoteName(string name, string quote)

Remove the surrounding quotes from the string if they are present.

string LineBreakingIntoPar(string str, variable minimumWidth = defaultValue)

Break a string into multiple lines.

All spaces and tabs which are not followed by numbers are replace by carriage returns (\r) if the minimum width was reached.

A generic solution would either implement the real deal

Knuth, Donald E.; Plass, Michael F. (1981), Breaking paragraphs into lines Software: Practice and Experience 11 (11): 1119-1184, doi:10.1002/spe.4380111102.

or translate 1 from C++ to Igor Pro.

Parameters:
  • str – string to break into lines

  • minimumWidth – [optional, defaults to zero] Each line, except the last one, will have at least this length

string RemovePrefix(string str, string start = defaultValue, variable regExp = defaultValue)

Remove a prefix from a string.

Same semantics as the RemoveEnding builtin for regExp == 0.

UTF_NOINSTRUMENTATION

Parameters:
  • str – string to potentially remove something from its beginning

  • start – [optional, defaults to the first character] Remove this from the begin of str

  • regExp – [optional, defaults to false] If start is a simple string (false) or a regular expression (true)

string RemoveEndingRegExp(string str, string endingRegExp)

Remove the given reguluar expression from the end of the string.

In case the regular expression does not match, the string is returned unaltered.

See also DisplayHelpTopic "Regular Expressions".

variable SearchWordInString(string str, string word, string *prefix = defaultValue, string *suffix = defaultValue)

Search for a Word inside a String.

example of the usage of SearchStringBase (basically the same as WM GrepString())

Function SearchString(str, substring)
    string str, substring

    ASSERT(!IsEmpty(substring), "supplied substring is empty")
    WAVE/Z/T wv = SearchStringBase(str, "(.*)\\Q" + substring + "\\E(.*)")

    return WaveExists(wv)
End

Parameters:
  • str[in] input text in which word should be searched

  • word[in] searchpattern (non-regex-sensitive)

  • prefix[out] (optional) string preceding word. (”” for unmatched pattern)

  • suffix[out] (optional) string succeeding word.

Returns:

1 if word was found in str and word was not “”. 0 if not.

static std::tuple<variable, string, string> SearchRegexInString(string str, string regex)
wave SearchStringBase(string str, string regex)

More advanced version of SplitString.

supports 6 subpatterns, specified by curly brackets in regex

Returns:

text wave containing subpatterns of regex call

variable CountSubstrings(string str, string pattern)

Search for the occurence of pattern in string.

Returns:

number of occurences

variable ParseUnit(string unitWithPrefix, string *prefix, variable *numPrefix, string *unit)

Parses a simple unit with prefix into its prefix and unit.

Note: The currently allowed units are the SI base units [1] and other common derived units. And in accordance to SI definitions, “kg” is a base unit.

Parameters:
  • unitWithPrefix[in] string to parse, examples are “ms” or “kHz”

  • prefix[out] symbol of decimal multipler of the unit, see below or [1] chapter 3 for the full list

  • numPrefix[out] numerical value of the decimal multiplier

  • unit[out] unit

variable GetDecimalMultiplierValue(string prefix)

Return the numerical value of a SI decimal multiplier.

See also

ParseUnit

string ReplaceWordInString(string word, string str, string replacement)
string ReplaceRegexInString(string regex, string str, string replacement)

Replaces all occurences of the regular expression regex in str with replacement

string NormalizeToEOL(string str, string eol)

Normalize the line endings in the given string to either classic Mac OS/Igor Pro EOLs (\r) or Unix EOLs (\n)

UTF_NOINSTRUMENTATION

string ElideText(string str, variable returnLength)

Elide the given string to the requested length.

variable NumBytesInUTF8Character(string str, variable byteOffset)

Returns the number of bytes in the UTF-8 character that starts byteOffset bytes from the start of str. NOTE: If byteOffset is invalid this routine returns 0. Also, if str is not valid UTF-8 text, this routine return 1.

From DisplayHelpTopic “Character-by-Character Operations”

variable UTF8CharactersInString(string str)

Returns the number of UTF8 characters in a string.

From DisplayHelpTopic “Character-by-Character Operations”

string UTF8CharacterAtPosition(string str, variable charPos)

Returns the UTF8 characters in a string at position charPos.

From DisplayHelpTopic “Character-by-Character Operations”

string UpperCaseFirstChar(string str)

Upper case the first character in an ASCII string.