MeVisLab Toolbox Reference
ml::ReleaseToolsString Namespace Reference

Collection of some string tools. More...

Typedefs

typedef std::vector< std::string > StringVector
 Define often used string vector type.
 
typedef std::vector< StringVectorStringVectorVector
 Define often used vector of string vector type.
 

Functions

MLRELEASE_TOOLS_EXPORT std::string replaceAllChars (const std::string &str, char ch1, char ch2)
 Replaces all ch1 characters in str with ch2.
 
MLRELEASE_TOOLS_EXPORT std::string escapeString (const std::string &str)
 Replaces all spaces with '?'s.
 
MLRELEASE_TOOLS_EXPORT std::string unescapeString (const std::string &str)
 Replaces all '?'s with spaces.
 
MLRELEASE_TOOLS_EXPORT void replaceAllStr1ByStr2InStr (std::string &inStr, const std::string &str1, const std::string &str2)
 Replaces all occurrences of str1 in inStr by str2.
 
MLRELEASE_TOOLS_EXPORT std::string replaceAllStr1ByStr2 (const std::string &inStr, const std::string &str1, const std::string &str2)
 Same as replaceAllStr1ByStr2InStr with the difference that the changed string is returned and inStr remains unchanged.
 
MLRELEASE_TOOLS_EXPORT std::string replaceNewLinesByBrs (const std::string &inStr)
 Replaces all '
's with "<br>"s.
 
MLRELEASE_TOOLS_EXPORT std::string replaceBrsByNewLines (const std::string &inStr)
 Replaces all "<br>"s with '
's.
 
MLRELEASE_TOOLS_EXPORT bool endsWith (const std::string &str, const std::string &endStr)
 Returns true if str ends with endStr, otherwise false.
 
MLRELEASE_TOOLS_EXPORT std::string terminateWithSingleEndString (const std::string &inStr, const std::string &endStr)
 Returns inStr+endStr if endStr is still not at the end of inStr, otherwise it returns inStr.
 
MLRELEASE_TOOLS_EXPORT std::string terminateWithSingleEndString (const std::string &inStr, const std::string &endStr, const std::string &endStr2)
 Returns inStr + endStr if inStr does not end neither with endStr nor with endStr2, otherwise it returns inStr.
 
MLRELEASE_TOOLS_EXPORT std::string makeSingleNewlineTerminated (const std::string &inStr)
 Returns inStr + "\n" if inStr does not end neither with "\n" nor with "<br>", otherwise it returns inStr.
 
MLRELEASE_TOOLS_EXPORT std::string convertLineEndingsToNewLinesOnly (const std::string &inStr)
 Returns a converted inStr where 1) all appearances of "\r\n" and then 2) all appearances of "\r" are replaced with "\n" such that the string is line-ending platform independent and only uses
's.
 
MLRELEASE_TOOLS_EXPORT StringVector split (const std::string &value, const std::string &sep)
 Subdivides value at all positions of sep and returns all values in the vector.
 
MLRELEASE_TOOLS_EXPORT StringVector splitAtLineBreaks (const std::string &value)
 Subdivides value at all positions which seem to be a line ending, technically it returns split(convertLineEndingsToNewLinesOnly(value), "\n").
 
MLRELEASE_TOOLS_EXPORT void removeElements (StringVector &strVec, const std::string &str=std::string())
 Removes all entries from strVec which equal to str; default is an empty string to remove all empty entries.
 
MLRELEASE_TOOLS_EXPORT std::vector< size_tcreateIndexList (size_t numIndexes, std::string idxExp, std::string &resultInfo)
 Creates a list of indexes by parsing the string expression idxExp.
 
MLRELEASE_TOOLS_EXPORT void removeDuplicates (std::string &strToShrink, char ch=' ')
 Multiple occurrences of ch in strToShrink are reduced to single ones in O(n).
 
MLRELEASE_TOOLS_EXPORT std::string replaceValuePlaceholders (const std::string &taggedStr, const PagedImage *inImg=nullptr, const std::vector< std::string > &inputValues=std::vector< std::string >(), const std::string &defaultTagContent="", const std::string &fileType="", size_t idx=0, size_t padSize=5)
 Replaces a number of tags of one of the following formats , $(0IDX), , $(0IMGEXTX), , $(0IMGEXTY), , $(0IMGEXTZ), , $(0IMGEXTC), , $(0IMGEXTT), , $(0IMGEXTU), , $(0IMGEXT), , , (input00), ... ,.
 
Conversion of numbers to std::string.
MLRELEASE_TOOLS_EXPORT std::string toIntStr (int val, signed char fieldWidth=-1, bool padWithZeros=false)
 Tool function to convert an integer to a string.
 
MLRELEASE_TOOLS_EXPORT std::string toMLIntStr (MLint val, signed char fieldWidth=-1, bool padWithZeros=false)
 Tool function to convert an MLint to a string.
 
MLRELEASE_TOOLS_EXPORT std::string toMLUIntStr (MLuint val, signed char fieldWidth=-1, bool padWithZeros=false)
 Tool function to convert an MLuint to a string.
 
MLRELEASE_TOOLS_EXPORT std::string toSize_tStr (size_t val, signed char fieldWidth=-1, bool padWithZeros=false)
 Tool function to convert a size_t to a string.
 
MLRELEASE_TOOLS_EXPORT std::string toDblStr (MLdouble val, signed char fieldWidth=-1, signed char numDecimalPlaces=-1, bool padWithZeros=false, bool considerValAsFloat=false)
 Tool function to print an MLdouble value to a std::string.
 

Variables

MLRELEASE_TOOLS_EXPORT const std::string DefaultLineSeparator
 The default line separator used for line endings when converting the internal string vector to a string with the default getString() or operator>>.
 

Detailed Description

Collection of some string tools.

Typedef Documentation

◆ StringVector

typedef std::vector< std::string > ml::ReleaseToolsString::StringVector

Define often used string vector type.

Definition at line 36 of file mlReleaseToolsString.h.

◆ StringVectorVector

Define often used vector of string vector type.

Definition at line 39 of file mlReleaseToolsString.h.

Function Documentation

◆ convertLineEndingsToNewLinesOnly()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::convertLineEndingsToNewLinesOnly ( const std::string & inStr)

Returns a converted inStr where 1) all appearances of "\r\n" and then 2) all appearances of "\r" are replaced with "\n" such that the string is line-ending platform independent and only uses
's.

References convertLineEndingsToNewLinesOnly().

Referenced by convertLineEndingsToNewLinesOnly().

◆ createIndexList()

MLRELEASE_TOOLS_EXPORT std::vector< size_t > ml::ReleaseToolsString::createIndexList ( size_t numIndexes,
std::string idxExp,
std::string & resultInfo )

Creates a list of indexes by parsing the string expression idxExp.

In idxExp the following separators are allowed to separate numbers from each other: "\t", "\n", "\r" and spaces. There is no difference between their meaning.

The following separators can be used to separate different subexpressions: ',' and ';'. There is no difference between there meaning.

All numeric index values used in idxExp must be positive integer-like values (including 0) from within the range [0, numIndexes] or the expression is considered invalid, which means that numIndexes=3 and idxExp"0-5" will be considered invalid.

Parameters
numIndexesDescribes the maximum value of any index in idxExp, larger index values are handled as error. It is also the maximum value for open range specifications such as "3-" which adds the indexes [3, ..., numIndexes] to the result vector.
idxExpAn expression containing index numbers. Examples: "1 7 2" -> 1, 7, 2 "-3" -> 0, 1, 2, 3 "1-4" -> 1, 2, 3, 4 "2-4,1-2" -> 2, 3, 4, 1, 2 At expression end: "3-" -> 3, ..., numIndexes. "" -> returns result vector with no values. Invalid expressions: "1-4-3", "1--3", "-"
resultInfoEmpty on a valid expression, otherwise an error describing the problem.
Returns
The found indexes as std::vector. In error cases successful evaluated subexpressions before commas are returned in the vector. The results of unsuccessfully evaluated subexpressions are undefined.

Warning: By passing a large numIndexes value and idxExp with open ranges such as "2-" the returned vector might become very large. Therefore it is recommended to use the smallest necessary numIndexes values.

References createIndexList().

Referenced by createIndexList().

◆ endsWith()

MLRELEASE_TOOLS_EXPORT bool ml::ReleaseToolsString::endsWith ( const std::string & str,
const std::string & endStr )

Returns true if str ends with endStr, otherwise false.

References endsWith().

Referenced by endsWith().

◆ escapeString()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::escapeString ( const std::string & str)

Replaces all spaces with '?'s.

References escapeString().

Referenced by escapeString().

◆ makeSingleNewlineTerminated()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::makeSingleNewlineTerminated ( const std::string & inStr)

Returns inStr + "\n" if inStr does not end neither with "\n" nor with "<br>", otherwise it returns inStr.

References makeSingleNewlineTerminated().

Referenced by makeSingleNewlineTerminated().

◆ removeDuplicates()

MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsString::removeDuplicates ( std::string & strToShrink,
char ch = ' ' )

Multiple occurrences of ch in strToShrink are reduced to single ones in O(n).

Parameters
strToShrinkThe string whose multiple occurrences of ch are condensed to single ones.
chThe character which is searched in strToShrink and whose multiple occurrences are shrunk to single ones.

References removeDuplicates().

Referenced by removeDuplicates().

◆ removeElements()

MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsString::removeElements ( StringVector & strVec,
const std::string & str = std::string() )

Removes all entries from strVec which equal to str; default is an empty string to remove all empty entries.

References removeElements().

Referenced by removeElements().

◆ replaceAllChars()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::replaceAllChars ( const std::string & str,
char ch1,
char ch2 )

Replaces all ch1 characters in str with ch2.

References replaceAllChars().

Referenced by replaceAllChars().

◆ replaceAllStr1ByStr2()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::replaceAllStr1ByStr2 ( const std::string & inStr,
const std::string & str1,
const std::string & str2 )

Same as replaceAllStr1ByStr2InStr with the difference that the changed string is returned and inStr remains unchanged.

References replaceAllStr1ByStr2().

Referenced by replaceAllStr1ByStr2().

◆ replaceAllStr1ByStr2InStr()

MLRELEASE_TOOLS_EXPORT void ml::ReleaseToolsString::replaceAllStr1ByStr2InStr ( std::string & inStr,
const std::string & str1,
const std::string & str2 )

Replaces all occurrences of str1 in inStr by str2.

str1 can contain str2 safely; inserted versions of str2 are not replaced recursively.

References replaceAllStr1ByStr2InStr().

Referenced by replaceAllStr1ByStr2InStr().

◆ replaceBrsByNewLines()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::replaceBrsByNewLines ( const std::string & inStr)

Replaces all "<br>"s with '
's.

References replaceBrsByNewLines().

Referenced by replaceBrsByNewLines().

◆ replaceNewLinesByBrs()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::replaceNewLinesByBrs ( const std::string & inStr)

Replaces all '
's with "<br>"s.

References replaceNewLinesByBrs().

Referenced by replaceNewLinesByBrs().

◆ replaceValuePlaceholders()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::replaceValuePlaceholders ( const std::string & taggedStr,
const PagedImage * inImg = nullptr,
const std::vector< std::string > & inputValues = std::vector< std::string >(),
const std::string & defaultTagContent = "",
const std::string & fileType = "",
size_t idx = 0,
size_t padSize = 5 )

Replaces a number of tags of one of the following formats , $(0IDX), , $(0IMGEXTX), , $(0IMGEXTY), , $(0IMGEXTZ), , $(0IMGEXTC), , $(0IMGEXTT), , $(0IMGEXTU), , $(0IMGEXT), , , (input00), ... ,.

with corresponding values retrieved from inImg. Note that no updating is performed on inImg.

Parameters
taggedStrThe string whose tags are to be replaced.
inImgThe ML paged image from which the information is retrieved to replace the tag values if its pointer is non nullptr and valid; otherwise for the corresponding values defaultTagContent will be used.
inputValuesA vector with a number of strings which are used to replace the placeholders , ... ,; not available vector entries are harmless; defaultTagContent will be used instead.
defaultTagContentIf the value of a tag value cannot be determined then this value will be used instead.
fileTypeA string containing the type of the file (if available); the default is empty.
idxThe index of the image if there is any; the defaults is 0.
padSizeDetermines the width of the padded values; defaults to 5.
Returns
The string with replaced tag values.

References replaceValuePlaceholders().

Referenced by replaceValuePlaceholders().

◆ split()

MLRELEASE_TOOLS_EXPORT StringVector ml::ReleaseToolsString::split ( const std::string & value,
const std::string & sep )

Subdivides value at all positions of sep and returns all values in the vector.

Parameters
valueThe string to be subdivided.
sepThe character sequence used to separate string segments.
Returns
The vector of sep-separated strings; if sep is empty value is returned in a vector containing one element.

◆ splitAtLineBreaks()

MLRELEASE_TOOLS_EXPORT StringVector ml::ReleaseToolsString::splitAtLineBreaks ( const std::string & value)

Subdivides value at all positions which seem to be a line ending, technically it returns split(convertLineEndingsToNewLinesOnly(value), "\n").

Parameters
valueThe string to be subdivided at line-breaks.
Returns
The vector of all at-any-line-break-separated strings; if value does not contain any line-break(s) then a one-element vector with value is returned.

References splitAtLineBreaks().

Referenced by splitAtLineBreaks().

◆ terminateWithSingleEndString() [1/2]

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::terminateWithSingleEndString ( const std::string & inStr,
const std::string & endStr )

Returns inStr+endStr if endStr is still not at the end of inStr, otherwise it returns inStr.

References terminateWithSingleEndString().

Referenced by terminateWithSingleEndString(), and terminateWithSingleEndString().

◆ terminateWithSingleEndString() [2/2]

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::terminateWithSingleEndString ( const std::string & inStr,
const std::string & endStr,
const std::string & endStr2 )

Returns inStr + endStr if inStr does not end neither with endStr nor with endStr2, otherwise it returns inStr.

References terminateWithSingleEndString().

◆ toDblStr()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::toDblStr ( MLdouble val,
signed char fieldWidth = -1,
signed char numDecimalPlaces = -1,
bool padWithZeros = false,
bool considerValAsFloat = false )

Tool function to print an MLdouble value to a std::string.

If numDecimalPlaces > 0 then it is taken as the number of printed digits after the comma (if necessary "0"s are appended). If numDecimalPlaces == 0 then the number is printed without digits after the decimal point and without the decimal point itself. If numDecimalPlaces < 0 the number is printed up to the last available non zero precision digit which can be represented by the data type. If fieldWidth is > 0 then it defines the minimum space provided for the entire string (if necessary then it is left padded with spaces if padWithZeros is false and padded with zeros if padWithZeros), otherwise (if fieldWidth is <=0) it is ignored. If it is necessary to make the number + decimal point + numDecimalPlaces fit into the string the fieldWidth is overridden and implicitly extended. Examples: toDblStr( 3.141500001) -> "3.141500001" toDblStr( 123456789101) -> "123456789101" toDblStr( 333, 3, 5) -> "333.00000" toDblStr(1987321.78, 2, 8) -> "1987321.78000000" toDblStr( 2.6789, 5, 2) -> " 2.68" toDblStr( -17,10, 0) -> " -17" If considerValAsFloat is true then val is handled as if it was a float value instead of a double, thus internally used default digit numbers are not DBL_DIG (15) but FLT_DIG (6).

References toDblStr().

Referenced by toDblStr().

◆ toIntStr()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::toIntStr ( int val,
signed char fieldWidth = -1,
bool padWithZeros = false )

Tool function to convert an integer to a string.

If fieldWidth is > 0 and larger than the size of the created number string then the returned string is left padded with spaces if padWithZeros is false and padded with zeros if padWithZeros is true until it reaches the length fieldWidth. If fieldWidth is smaller 0 then the created number string will not have leading spaces nor leading zeros.

References toIntStr().

Referenced by toIntStr().

◆ toMLIntStr()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::toMLIntStr ( MLint val,
signed char fieldWidth = -1,
bool padWithZeros = false )

Tool function to convert an MLint to a string.

If fieldWidth is > 0 and larger than the size of the created number string then the returned string is left padded with spaces if padWithZeros is false and padded with zeros if padWithZeros is true until it reaches the length fieldWidth. If fieldWidth is smaller 0 then the created number string will not have leading spaces nor leading zeros.

References toMLIntStr().

Referenced by toMLIntStr().

◆ toMLUIntStr()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::toMLUIntStr ( MLuint val,
signed char fieldWidth = -1,
bool padWithZeros = false )

Tool function to convert an MLuint to a string.

If fieldWidth is > 0 and larger than the size of the created number string then the returned string is left padded with spaces if padWithZeros is false and padded with zeros if padWithZeros is true until it reaches the length fieldWidth. If fieldWidth is smaller 0 then the created number string will not have leading spaces nor leading zeros.

References toMLUIntStr().

Referenced by toMLUIntStr().

◆ toSize_tStr()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::toSize_tStr ( size_t val,
signed char fieldWidth = -1,
bool padWithZeros = false )

Tool function to convert a size_t to a string.

If fieldWidth is > 0 and larger than the size of the created number string then the returned string is left padded with spaces if padWithZeros is false and padded with zeros if padWithZeros is true until it reaches the length fieldWidth. If fieldWidth is smaller 0 then the created number string will not have leading spaces nor leading zeros.

References toSize_tStr().

Referenced by toSize_tStr().

◆ unescapeString()

MLRELEASE_TOOLS_EXPORT std::string ml::ReleaseToolsString::unescapeString ( const std::string & str)

Replaces all '?'s with spaces.

References unescapeString().

Referenced by unescapeString().

Variable Documentation

◆ DefaultLineSeparator

MLRELEASE_TOOLS_EXPORT const std::string ml::ReleaseToolsString::DefaultLineSeparator
extern

The default line separator used for line endings when converting the internal string vector to a string with the default getString() or operator>>.

"\r\n" on windows and "\n" on non windows systems.