ROSE
0.9.6a
|
Classes | |
struct | StringWithLineNumber |
class | FileNameClassification |
Functions | |
ROSE_UTIL_API std::string | getAbsolutePathFromRelativePath (const std::string &relativePath, bool printErrorIfAny) |
Get the absolute path from the relative path. More... | |
std::ostream & | operator<< (std::ostream &os, const StringWithLineNumber &s) |
ROSE_UTIL_API std::string | toString (const FileWithLineNumbers &strings, const std::string &filename="<unknown>", int line=1) |
FileWithLineNumbers & | operator+= (FileWithLineNumbers &a, const FileWithLineNumbers &b) |
FileWithLineNumbers | operator+ (const FileWithLineNumbers &a, const FileWithLineNumbers &b) |
FileWithLineNumbers & | operator<< (FileWithLineNumbers &f, const std::string &str) |
FileWithLineNumbers & | operator<< (FileWithLineNumbers &f, const char *str) |
ROSE_UTIL_API void | writeFile (const std::string &outputString, const std::string &fileNameString, const std::string &directoryName) |
Generate a file. More... | |
ROSE_UTIL_API std::string | readFile (const std::string &fileName) |
Read an existing file. More... | |
ROSE_UTIL_API FileWithLineNumbers | readFileWithPos (const std::string &fileName) |
Read a file, keeping source line number information. More... | |
unsigned long | generate_checksum (std::string s) |
Simple function to generate checksum for string (can be used with get_mangled_name() to provide simpler names) More... | |
ROSE_UTIL_API std::string | convertToLowerCase (const std::string &inputString) |
Convert string to lower case (e.g. for module file name generation). More... | |
bool | popen_wrapper (const std::string &command, std::vector< std::string > &result) |
Popen wrapper to support demangling mangled functions. More... | |
std::string | demangledName (std::string s) |
Support for demangling mangled functions. More... | |
std::list< std::string > | findfile (std::string patternString, std::string pathString) |
ROSE_UTIL_API std::string | escapeNewLineCharaters (const std::string &X) |
Translates newline characters to linefeeds and escapes quotes (used to generate text for DOT nodes containing source code). More... | |
ROSE_UTIL_API OSType | getOSType () |
void | homeDir (std::string &homeDir) |
ROSE_UTIL_API FileNameClassification | classifyFileName (const std::string &fileName, const std::string &appPath) |
ROSE_UTIL_API FileNameClassification | classifyFileName (const std::string &fileName, const std::string &appPath, OSType os) |
ROSE_UTIL_API FileNameClassification | classifyFileName (const std::string &fileName, const std::string &appPath, const std::map< std::string, std::string > &libPathCollection) |
ROSE_UTIL_API FileNameClassification | classifyFileName (const std::string &fileName, const std::string &appPath, const std::map< std::string, std::string > &libPathCollection, OSType os) |
ROSE_UTIL_API const std::string | stripDotsFromHeaderFileName (const std::string &name) |
ROSE_UTIL_API int | directoryDistance (const std::string &left, const std::string &right) |
ROSE_UTIL_API std::string | htmlEscape (const std::string &s) |
ROSE_UTIL_API std::vector < std::string > | readWordsInFile (std::string filename) |
ROSE_UTIL_API std::string | appendAsmComment (const std::string &s, const std::string &comment) |
Append an assembly comment to a string. More... | |
ROSE_UTIL_API std::string | prefixLines (const std::string &lines, const std::string &prefix, bool prefixAtFront=true, bool prefixAtBack=false) |
Insert a prefix string before every line. More... | |
ROSE_UTIL_API bool | isLineTerminated (const std::string &s) |
Returns true if the string ends with line termination. More... | |
ROSE_UTIL_API std::string | fixLineTermination (const std::string &input) |
Normalizes line termination. More... | |
ROSE_UTIL_API std::string | makeOneLine (const std::string &s, std::string replacement=" ") |
Converts a multi-line string to a single line. More... | |
std::vector< uint8_t > | decode_base64 (const std::string &encoded) |
Convert base-64 to binary. More... | |
ROSE_UTIL_API std::vector < std::string > | split (const std::string &separator, const std::string &str, size_t maxparts=(size_t)(-1), bool trim_white_space=false) |
Splits strings into parts. More... | |
ROSE_UTIL_API std::vector < std::string > | split (char separator, const std::string &str, size_t maxparts=(size_t)(-1), bool trim_white_space=false) |
ROSE_UTIL_API std::string | trim (const std::string &str, const std::string &strip=" \t\r\n", bool at_beginning=true, bool at_end=true) |
Trims white space from the beginning and end of a string. More... | |
std::string | untab (const std::string &str, size_t tabstops=8, size_t firstcol=0) |
Expand horizontal tab characters. More... | |
template<typename T > | |
std::string | plural (T n, const std::string &plural_word) |
Helpful way to print singular or plural words. More... | |
New C++ string functions | |
C++ string style support. Supporting functions for string operations common within ROSE. Uses C++ string interface. | |
ROSE_UTIL_API std::string | copyEdit (const std::string &inputString, const std::string &oldToken, const std::string &newToken) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | numberToString (long long x) |
Convert a number to a string. More... | |
ROSE_UTIL_API std::string | numberToString (unsigned long long x) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | numberToString (long x) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | numberToString (unsigned long x) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | numberToString (int x) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | numberToString (unsigned int x) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | intToHex (uint64_t i) |
Convert an integer to a Hex string. More... | |
ROSE_UTIL_API std::string | numberToString (const void *x) |
Convert a unsigned integer (size_t) to a string. More... | |
ROSE_UTIL_API std::string | numberToString (double x) |
Convert a number to a string. More... | |
ROSE_UTIL_API std::string | addrToString (uint64_t x, size_t nbits=32) |
Convert an address to a string, preferring a hexadecimal representation with at least 8 digits. The second argument. More... | |
ROSE_UTIL_API std::string | indentMultilineString (const std::string &inputString, int statementColumnNumber) |
Formatting support for generated code strings. More... | |
ROSE_UTIL_API std::string | listToString (const std::list< int > &X, bool separateStrings=false) |
Generate a string from a list of ints. More... | |
ROSE_UTIL_API std::string | listToString (const std::list< std::string > &X, bool separateStrings=false) |
Generate a string from a list of strings. More... | |
ROSE_UTIL_API std::list < std::string > | stringToList (const std::string &X) |
Generate a list of strings from a string (list elements are delimited by "\n"). More... | |
ROSE_UTIL_API std::string | listToString (const std::vector< std::string > &X, bool separateStrings=false) |
Generate a string from a vector of strings. More... | |
ROSE_UTIL_API std::list < std::string > | tokenize (std::string X, char delim) |
Substring replacement function. More... | |
ROSE_UTIL_API std::string | removeRedundentSubstrings (std::string X) |
Remove redundant lines (substrings must be separated by "\n". FIXME (spelling) More... | |
ROSE_UTIL_API std::string | removePseudoRedundentSubstrings (std::string X) |
Remove redundant lines containing special substrings of form string#. FIXME (spelling) More... | |
ROSE_UTIL_API void | add_to_reason_string (std::string &result, bool isset, bool do_pad, const std::string &abbr, const std::string &full) |
Append an abbreviation or full name to a string. More... | |
Old C style string support functions | |
C style string support.
This function was used before moving to C++ strings. It remains in use in some places where the code still uses the older C style strings. | |
ROSE_UTIL_API FileWithLineNumbers | copyEdit (const FileWithLineNumbers &inputString, const std::string &oldToken, const std::string &newToken) |
A smarter string concatination function (corrects for space in the target automatically) More... | |
ROSE_UTIL_API FileWithLineNumbers | copyEdit (const FileWithLineNumbers &inputString, const std::string &oldToken, const FileWithLineNumbers &newToken) |
A smarter string concatination function (corrects for space in the target automatically) More... | |
bool | isContainedIn (const std::string &longString, const std::string &shortString) |
A smarter string concatination function (corrects for space in the target automatically) More... | |
void | splitStringIntoStrings (const std::string &inputString, char separator, std::vector< std::string > &stringList) |
A smarter string concatination function (corrects for space in the target automatically) More... | |
File name strings | |
Handling for /path/name.suffix. Namespace CommandlineProcessing also has some file name handling functions. | |
ROSE_UTIL_API std::string | stripPathFromFileName (const std::string &fileNameWithPath) |
Get name.suffix from /path/name.suffix. More... | |
ROSE_UTIL_API std::string | getPathFromFileName (const std::string &fileNameWithPath) |
Get the path from the full file name: /path/name.suffix. More... | |
ROSE_UTIL_API std::string | stripFileSuffixFromFileName (const std::string &fileNameWithSuffix) |
Get the file name without the ".suffix". More... | |
ROSE_UTIL_API std::string | fileNameSuffix (const std::string &fileName) |
Get the file name suffix (extension) without the leading dot, fileName could be either base name or name with full path. More... | |
ROSE_UTIL_API std::string | toHex2 (uint64_t value, size_t nbits, bool show_unsigned_decimal=true, bool show_signed_decimal=true, uint64_t decimal_threshold=256) |
Convert a number to a hexadecimal and decimal string. More... | |
ROSE_UTIL_API std::string | signedToHex2 (uint64_t value, size_t nbits) |
Convert a number to a hexadecimal and decimal string. More... | |
ROSE_UTIL_API std::string | unsignedToHex2 (uint64_t value, size_t nbits) |
Convert a number to a hexadecimal and decimal string. More... | |
template<typename T > | |
std::string | toHex (T value) |
Convert a number to a hexadecimal and decimal string. More... | |
template<typename T > | |
std::string | signedToHex (T value) |
Convert a number to a hexadecimal and decimal string. More... | |
template<typename T > | |
std::string | unsignedToHex (T value) |
Convert a number to a hexadecimal and decimal string. More... | |
std::string | encode_base64 (const std::vector< uint8_t > &data, bool do_pad=true) |
Convert binary data to base-64. More... | |
std::string | encode_base64 (const uint8_t *data, size_t nbytes, bool do_padd=true) |
Convert binary data to base-64. More... | |
template<class Container > | |
std::string | join (const std::string &separator, const Container &strings) |
Join individual strings to form a single string. More... | |
template<class Iterator > | |
std::string | join_range (const std::string &separator, Iterator begin, Iterator end) |
Join individual strings to form a single string. More... | |
std::string | join (const std::string &separator, char *strings[], size_t nstrings) |
Join individual strings to form a single string. More... | |
std::string | join (const std::string &separator, const char *strings[], size_t nstrings) |
Join individual strings to form a single string. More... | |
template<class Container , class Stringifier > | |
std::vector< std::string > | toStrings (const Container &numbers, const Stringifier &stringifier=numberToString) |
Converts a bunch of numbers to strings. More... | |
template<class Iterator , class Stringifier > | |
std::vector< std::string > | toStrings_range (Iterator begin, Iterator end, const Stringifier &stringifier=numberToString) |
Converts a bunch of numbers to strings. More... | |
ROSE_UTIL_API std::string StringUtility::getAbsolutePathFromRelativePath | ( | const std::string & | relativePath, |
bool | printErrorIfAny = false |
||
) |
Get the absolute path from the relative path.
|
inline |
Definition at line 60 of file string_functions.h.
References StringUtility::StringWithLineNumber::toString().
ROSE_UTIL_API std::string StringUtility::toString | ( | const FileWithLineNumbers & | strings, |
const std::string & | filename = "<unknown>" , |
||
int | line = 1 |
||
) |
|
inline |
Definition at line 67 of file string_functions.h.
|
inline |
Definition at line 72 of file string_functions.h.
|
inline |
Definition at line 85 of file string_functions.h.
|
inline |
Definition at line 95 of file string_functions.h.
ROSE_UTIL_API void StringUtility::writeFile | ( | const std::string & | outputString, |
const std::string & | fileNameString, | ||
const std::string & | directoryName | ||
) |
Generate a file.
ROSE_UTIL_API std::string StringUtility::readFile | ( | const std::string & | fileName) |
Read an existing file.
ROSE_UTIL_API FileWithLineNumbers StringUtility::readFileWithPos | ( | const std::string & | fileName) |
Read a file, keeping source line number information.
ROSE_UTIL_API std::string StringUtility::copyEdit | ( | const std::string & | inputString, |
const std::string & | oldToken, | ||
const std::string & | newToken | ||
) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::numberToString | ( | long long | x) |
Convert a number to a string.
Referenced by RegisterDictionary::dictionary_amd64(), RegisterDictionary::dictionary_arm7(), RegisterDictionary::dictionary_mips32(), RegisterDictionary::dictionary_powerpc(), DisassemblerArm::makeRegister(), DisassemblerX86::makeRegister(), Partitioner::mark_ipd_configuration(), and plural().
ROSE_UTIL_API std::string StringUtility::numberToString | ( | unsigned long long | x) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::numberToString | ( | long | x) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::numberToString | ( | unsigned long | x) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::numberToString | ( | int | x) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::numberToString | ( | unsigned int | x) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::intToHex | ( | uint64_t | i) |
Convert an integer to a Hex string.
Referenced by DisassemblerArm::decodeMediaInstruction(), and DisassemblerArm::disassemble().
ROSE_UTIL_API std::string StringUtility::numberToString | ( | const void * | x) |
Convert a unsigned integer (size_t) to a string.
Convert a pointer value to a string
ROSE_UTIL_API std::string StringUtility::numberToString | ( | double | x) |
Convert a number to a string.
ROSE_UTIL_API std::string StringUtility::addrToString | ( | uint64_t | x, |
size_t | nbits = 32 |
||
) |
Convert an address to a string, preferring a hexadecimal representation with at least 8 digits. The second argument.
Referenced by MemoryMap::dump(), SgAsmIntegerValueExpression::get_label(), SgAsmx86Instruction::get_successors(), Partitioner::mark_ipd_configuration(), SqlDatabase::AddrRenderer::operator()(), Disassembler::Exception::print(), RegisterDictionary::print(), MemoryMap::Segment::print(), MemoryMap::NotMapped::print(), Partitioner::FunctionRangeMapValue::print(), and Partitioner::DataRangeMapValue::print().
ROSE_UTIL_API std::string StringUtility::indentMultilineString | ( | const std::string & | inputString, |
int | statementColumnNumber | ||
) |
Formatting support for generated code strings.
ROSE_UTIL_API std::string StringUtility::listToString | ( | const std::list< int > & | X, |
bool | separateStrings = false |
||
) |
Generate a string from a list of ints.
ROSE_UTIL_API std::string StringUtility::listToString | ( | const std::list< std::string > & | X, |
bool | separateStrings = false |
||
) |
Generate a string from a list of strings.
ROSE_UTIL_API std::list<std::string> StringUtility::stringToList | ( | const std::string & | X) |
Generate a list of strings from a string (list elements are delimited by "\n").
ROSE_UTIL_API std::string StringUtility::listToString | ( | const std::vector< std::string > & | X, |
bool | separateStrings = false |
||
) |
Generate a string from a vector of strings.
ROSE_UTIL_API std::list<std::string> StringUtility::tokenize | ( | std::string | X, |
char | delim | ||
) |
Substring replacement function.
Replaced by equality operator in C++ string class.
ROSE_UTIL_API std::string StringUtility::removeRedundentSubstrings | ( | std::string | X) |
Remove redundant lines (substrings must be separated by "\n". FIXME (spelling)
ROSE_UTIL_API std::string StringUtility::removePseudoRedundentSubstrings | ( | std::string | X) |
Remove redundant lines containing special substrings of form string#. FIXME (spelling)
ROSE_UTIL_API void StringUtility::add_to_reason_string | ( | std::string & | result, |
bool | isset, | ||
bool | do_pad, | ||
const std::string & | abbr, | ||
const std::string & | full | ||
) |
Append an abbreviation or full name to a string.
Referenced by SgAsmFunction::reason_str(), and SgAsmBlock::reason_str().
ROSE_UTIL_API FileWithLineNumbers StringUtility::copyEdit | ( | const FileWithLineNumbers & | inputString, |
const std::string & | oldToken, | ||
const std::string & | newToken | ||
) |
A smarter string concatination function (corrects for space in the target automatically)
Support for commandline construction used for building argv and argc (I think) (written by Bobby Philip)
ROSE_UTIL_API FileWithLineNumbers StringUtility::copyEdit | ( | const FileWithLineNumbers & | inputString, |
const std::string & | oldToken, | ||
const FileWithLineNumbers & | newToken | ||
) |
A smarter string concatination function (corrects for space in the target automatically)
Support for commandline construction used for building argv and argc (I think) (written by Bobby Philip)
|
inline |
A smarter string concatination function (corrects for space in the target automatically)
Support for commandline construction used for building argv and argc (I think) (written by Bobby Philip)
Definition at line 199 of file string_functions.h.
void StringUtility::splitStringIntoStrings | ( | const std::string & | inputString, |
char | separator, | ||
std::vector< std::string > & | stringList | ||
) |
A smarter string concatination function (corrects for space in the target automatically)
Support for commandline construction used for building argv and argc (I think) (written by Bobby Philip)
unsigned long StringUtility::generate_checksum | ( | std::string | s) |
Simple function to generate checksum for string (can be used with get_mangled_name() to provide simpler names)
ROSE_UTIL_API std::string StringUtility::convertToLowerCase | ( | const std::string & | inputString) |
Convert string to lower case (e.g. for module file name generation).
bool StringUtility::popen_wrapper | ( | const std::string & | command, |
std::vector< std::string > & | result | ||
) |
Popen wrapper to support demangling mangled functions.
std::string StringUtility::demangledName | ( | std::string | s) |
Support for demangling mangled functions.
ROSE_UTIL_API std::string StringUtility::stripPathFromFileName | ( | const std::string & | fileNameWithPath) |
Get name.suffix from /path/name.suffix.
Referenced by yicesCheck().
ROSE_UTIL_API std::string StringUtility::getPathFromFileName | ( | const std::string & | fileNameWithPath) |
Get the path from the full file name: /path/name.suffix.
ROSE_UTIL_API std::string StringUtility::stripFileSuffixFromFileName | ( | const std::string & | fileNameWithSuffix) |
Get the file name without the ".suffix".
ROSE_UTIL_API std::string StringUtility::fileNameSuffix | ( | const std::string & | fileName) |
Get the file name suffix (extension) without the leading dot, fileName could be either base name or name with full path.
std::list<std::string> StringUtility::findfile | ( | std::string | patternString, |
std::string | pathString | ||
) |
ROSE_UTIL_API std::string StringUtility::escapeNewLineCharaters | ( | const std::string & | X) |
Translates newline characters to linefeeds and escapes quotes (used to generate text for DOT nodes containing source code).
ROSE_UTIL_API OSType StringUtility::getOSType | ( | ) |
void StringUtility::homeDir | ( | std::string & | homeDir) |
ROSE_UTIL_API FileNameClassification StringUtility::classifyFileName | ( | const std::string & | fileName, |
const std::string & | appPath | ||
) |
ROSE_UTIL_API FileNameClassification StringUtility::classifyFileName | ( | const std::string & | fileName, |
const std::string & | appPath, | ||
OSType | os | ||
) |
ROSE_UTIL_API FileNameClassification StringUtility::classifyFileName | ( | const std::string & | fileName, |
const std::string & | appPath, | ||
const std::map< std::string, std::string > & | libPathCollection | ||
) |
ROSE_UTIL_API FileNameClassification StringUtility::classifyFileName | ( | const std::string & | fileName, |
const std::string & | appPath, | ||
const std::map< std::string, std::string > & | libPathCollection, | ||
OSType | os | ||
) |
ROSE_UTIL_API const std::string StringUtility::stripDotsFromHeaderFileName | ( | const std::string & | name) |
ROSE_UTIL_API int StringUtility::directoryDistance | ( | const std::string & | left, |
const std::string & | right | ||
) |
ROSE_UTIL_API std::string StringUtility::htmlEscape | ( | const std::string & | s) |
ROSE_UTIL_API std::vector<std::string> StringUtility::readWordsInFile | ( | std::string | filename) |
ROSE_UTIL_API std::string StringUtility::toHex2 | ( | uint64_t | value, |
size_t | nbits, | ||
bool | show_unsigned_decimal = true , |
||
bool | show_signed_decimal = true , |
||
uint64_t | decimal_threshold = 256 |
||
) |
Convert a number to a hexadecimal and decimal string.
The returned string starts with the hexadecimal representation of the number and an optional decimal representation in angle brackets. The decimal portion will contain a signed and/or unsigned value depending on whether the value is interpretted as signed and whether the sign bit is set. The signedToHex versions print the decimal value for only the signed interpretation; the unsignedToHex versions print only the decimal unsigned interpretation, and the toHex versions print both (but not redunantly).
Referenced by toHex().
ROSE_UTIL_API std::string StringUtility::signedToHex2 | ( | uint64_t | value, |
size_t | nbits | ||
) |
Convert a number to a hexadecimal and decimal string.
The returned string starts with the hexadecimal representation of the number and an optional decimal representation in angle brackets. The decimal portion will contain a signed and/or unsigned value depending on whether the value is interpretted as signed and whether the sign bit is set. The signedToHex versions print the decimal value for only the signed interpretation; the unsignedToHex versions print only the decimal unsigned interpretation, and the toHex versions print both (but not redunantly).
Referenced by signedToHex().
ROSE_UTIL_API std::string StringUtility::unsignedToHex2 | ( | uint64_t | value, |
size_t | nbits | ||
) |
Convert a number to a hexadecimal and decimal string.
The returned string starts with the hexadecimal representation of the number and an optional decimal representation in angle brackets. The decimal portion will contain a signed and/or unsigned value depending on whether the value is interpretted as signed and whether the sign bit is set. The signedToHex versions print the decimal value for only the signed interpretation; the unsignedToHex versions print only the decimal unsigned interpretation, and the toHex versions print both (but not redunantly).
Referenced by unsignedToHex().
std::string StringUtility::toHex | ( | T | value) |
Convert a number to a hexadecimal and decimal string.
The returned string starts with the hexadecimal representation of the number and an optional decimal representation in angle brackets. The decimal portion will contain a signed and/or unsigned value depending on whether the value is interpretted as signed and whether the sign bit is set. The signedToHex versions print the decimal value for only the signed interpretation; the unsignedToHex versions print only the decimal unsigned interpretation, and the toHex versions print both (but not redunantly).
Definition at line 463 of file string_functions.h.
References toHex2().
std::string StringUtility::signedToHex | ( | T | value) |
Convert a number to a hexadecimal and decimal string.
The returned string starts with the hexadecimal representation of the number and an optional decimal representation in angle brackets. The decimal portion will contain a signed and/or unsigned value depending on whether the value is interpretted as signed and whether the sign bit is set. The signedToHex versions print the decimal value for only the signed interpretation; the unsignedToHex versions print only the decimal unsigned interpretation, and the toHex versions print both (but not redunantly).
Definition at line 464 of file string_functions.h.
References signedToHex2().
std::string StringUtility::unsignedToHex | ( | T | value) |
Convert a number to a hexadecimal and decimal string.
The returned string starts with the hexadecimal representation of the number and an optional decimal representation in angle brackets. The decimal portion will contain a signed and/or unsigned value depending on whether the value is interpretted as signed and whether the sign bit is set. The signedToHex versions print the decimal value for only the signed interpretation; the unsignedToHex versions print only the decimal unsigned interpretation, and the toHex versions print both (but not redunantly).
Definition at line 465 of file string_functions.h.
References unsignedToHex2().
Referenced by ExtentMap::dump_extents().
ROSE_UTIL_API std::string StringUtility::appendAsmComment | ( | const std::string & | s, |
const std::string & | comment | ||
) |
Append an assembly comment to a string.
Assembly comments are surrounded by "<" and ">" characters. If the string already ends with an assembly comment, then the specified comment is inserted before the final ">" and separated from the previous comment with a comma. Assembly comments are usually used for things like printing a decimal representation of a hexadecimal value, etc.
Example: after executing these statements:
The variable "s" will contain "0xff<255,-1>"
ROSE_UTIL_API std::string StringUtility::prefixLines | ( | const std::string & | lines, |
const std::string & | prefix, | ||
bool | prefixAtFront = true , |
||
bool | prefixAtBack = false |
||
) |
Insert a prefix string before every line.
This function breaks the lines
string into individual lines, inserts the prefix
string at the beginning of each line, then concatenates the lines together into a return value. If prefixAtFront
is true (the default) then the prefix is added to the first line of lines
, otherwise the first line is unchanged. An empty lines
string is considered to be a single line. If prefixAtBack
is false (the default) then the prefix is not appended to the lines
string if lines
ends with a linefeed.
ROSE_UTIL_API bool StringUtility::isLineTerminated | ( | const std::string & | s) |
Returns true if the string ends with line termination.
Only common ASCII-based line terminations are recognized: CR+LF, LF+CR, CR (only), or LF (only).
ROSE_UTIL_API std::string StringUtility::fixLineTermination | ( | const std::string & | input) |
Normalizes line termination.
Changes ASCII-based line termination conventions used by various operating systems into the LF (line-feed) termination used by Multics, Unix and Unix-like systems (GNU/Linux, Mac OS X, FreeBSD, AIX, Xenix, etc.), BeOS, Amiga, RISC OS and others. Any occurrance of CR+LF, LF+CR, or CR by itself (in that order of left-to-right matching) is replaced by a single LF character.
ROSE_UTIL_API std::string StringUtility::makeOneLine | ( | const std::string & | s, |
std::string | replacement = " " |
||
) |
Converts a multi-line string to a single line.
This function converts a multi-line string to a single line by replacing line-feeds and carriage-returns (and their surrounding white space) with a user-supplied replacement string (that defaults to a single space). Line termination (and it's surrounding white space) that appears at the front or back of the input string is removed without replacing it.
See roseTests/utilTests/stringTests.C for lots of examples.
A new string is returned.
std::string StringUtility::encode_base64 | ( | const std::vector< uint8_t > & | data, |
bool | do_pad = true |
||
) |
Convert binary data to base-64.
The base64 number system uses the characters A-Z, a-z, 0-9, +, and / (in that order). The returned string does not include linefeeds. If do_pad
is true then '=' characters may appear at the end to make the total length a multiple of four.
std::string StringUtility::encode_base64 | ( | const uint8_t * | data, |
size_t | nbytes, | ||
bool | do_padd = true |
||
) |
Convert binary data to base-64.
The base64 number system uses the characters A-Z, a-z, 0-9, +, and / (in that order). The returned string does not include linefeeds. If do_pad
is true then '=' characters may appear at the end to make the total length a multiple of four.
std::vector<uint8_t> StringUtility::decode_base64 | ( | const std::string & | encoded) |
Convert base-64 to binary.
std::string StringUtility::join | ( | const std::string & | separator, |
const Container & | strings | ||
) |
Join individual strings to form a single string.
Unlike listToString(), this function allows the caller to indicate how the strings should be separated from one another: the separator
(default SPC) is inserted between each pair of strings, but not at the beginning or end, even if strings are empty.
Definition at line 528 of file string_functions.h.
References join_range().
Referenced by SqlDatabase::in_numbers().
std::string StringUtility::join_range | ( | const std::string & | separator, |
Iterator | begin, | ||
Iterator | end | ||
) |
Join individual strings to form a single string.
Unlike listToString(), this function allows the caller to indicate how the strings should be separated from one another: the separator
(default SPC) is inserted between each pair of strings, but not at the beginning or end, even if strings are empty.
Definition at line 532 of file string_functions.h.
Referenced by join().
std::string StringUtility::join | ( | const std::string & | separator, |
char * | strings[], | ||
size_t | nstrings | ||
) |
Join individual strings to form a single string.
Unlike listToString(), this function allows the caller to indicate how the strings should be separated from one another: the separator
(default SPC) is inserted between each pair of strings, but not at the beginning or end, even if strings are empty.
std::string StringUtility::join | ( | const std::string & | separator, |
const char * | strings[], | ||
size_t | nstrings | ||
) |
Join individual strings to form a single string.
Unlike listToString(), this function allows the caller to indicate how the strings should be separated from one another: the separator
(default SPC) is inserted between each pair of strings, but not at the beginning or end, even if strings are empty.
ROSE_UTIL_API std::vector<std::string> StringUtility::split | ( | const std::string & | separator, |
const std::string & | str, | ||
size_t | maxparts = (size_t)(-1) , |
||
bool | trim_white_space = false |
||
) |
Splits strings into parts.
Unlink stringToList(), this function allows the caller to indicate where to split the string. The parts are the portions of the string on either side of the separator: if the separator appears at the beginning of the string, then the first part is empty; likewise if the separator appears at the end of the string then the last part is empty. At most maxparts
are returned, the last of which may contain occurrences of the separator. If trim_white_space
is true then white space is removed from the beginning and end of each part. Empty parts are never removed from the returned vector since the C++ library already has functions for that. The first few arguments are in the same order as for Perl's "split" operator.
ROSE_UTIL_API std::vector<std::string> StringUtility::split | ( | char | separator, |
const std::string & | str, | ||
size_t | maxparts = (size_t)(-1) , |
||
bool | trim_white_space = false |
||
) |
ROSE_UTIL_API std::string StringUtility::trim | ( | const std::string & | str, |
const std::string & | strip = " \t\r\n" , |
||
bool | at_beginning = true , |
||
bool | at_end = true |
||
) |
Trims white space from the beginning and end of a string.
Caller may specify the characters to strip and whether the stripping occurs at the begining, the end, or both.
std::string StringUtility::untab | ( | const std::string & | str, |
size_t | tabstops = 8 , |
||
size_t | firstcol = 0 |
||
) |
Expand horizontal tab characters.
std::vector<std::string> StringUtility::toStrings | ( | const Container & | numbers, |
const Stringifier & | stringifier = numberToString |
||
) |
Converts a bunch of numbers to strings.
This is convenient when one has a container of numbers and wants to call join() to turn it into a single string. For instance, here's how to convert a set of integers to a comma-separated list:
Here's how to convert a vector of addresses to space-separated hexadecimal values:
Here's how one could surround each address with angle brackets:
Definition at line 589 of file string_functions.h.
References toStrings_range().
Referenced by SqlDatabase::in_numbers().
std::vector<std::string> StringUtility::toStrings_range | ( | Iterator | begin, |
Iterator | end, | ||
const Stringifier & | stringifier = numberToString |
||
) |
Converts a bunch of numbers to strings.
This is convenient when one has a container of numbers and wants to call join() to turn it into a single string. For instance, here's how to convert a set of integers to a comma-separated list:
Here's how to convert a vector of addresses to space-separated hexadecimal values:
Here's how one could surround each address with angle brackets:
Definition at line 593 of file string_functions.h.
Referenced by toStrings().
std::string StringUtility::plural | ( | T | n, |
const std::string & | plural_word | ||
) |
Helpful way to print singular or plural words.
Definition at line 617 of file string_functions.h.
References numberToString().