retdec
Namespaces | Functions
string.cpp File Reference

String utilities. More...

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstddef>
#include <functional>
#include <regex>
#include <sstream>
#include "retdec/utils/conversion.h"
#include "retdec/utils/string.h"

Namespaces

 retdec
 
 retdec::utils
 

Functions

bool retdec::utils::hasOnlyDecimalDigits (const std::string &str)
 Returns true if the given string is formed only by decimal digits. More...
 
bool retdec::utils::hasOnlyHexadecimalDigits (const std::string &str)
 Returns true if the given string is formed only by hexadecimal digits. More...
 
bool retdec::utils::hasNonprintableChars (const std::string &str)
 Returns true if the given string contains at least one non-printable character. More...
 
bool retdec::utils::hasNonasciiChars (const std::string &str)
 Returns true if the given string contains at least one non-ASCII character. More...
 
bool retdec::utils::isLowerThanCaseInsensitive (const std::string &str1, const std::string &str2)
 Checks if str1 < str2 (case-insensitively). More...
 
bool retdec::utils::areEqualCaseInsensitive (const std::string &str1, const std::string &str2)
 Checks if str1 == str2 (case-insensitively). More...
 
bool retdec::utils::isShorterPrefixOfCaseInsensitive (const std::string &str1, const std::string &str2)
 Checks if the shorter string of str1 and str2 is a case-insensitive prefix of the longer string. More...
 
bool retdec::utils::contains (const std::string &str, const std::string &sub)
 Checks if str contains sub. More...
 
bool retdec::utils::containsAny (const std::string &str, const std::vector< std::string > &subs)
 Check if at least one string from subs is contained in str. More...
 
bool retdec::utils::containsCaseInsensitive (const std::string &str, const std::string &sub)
 Find out if string contains another string, no matter the case. More...
 
bool retdec::utils::containsAnyOfChars (const std::string &str, const std::string &chars)
 Returns true if str contains at least one character from chars, false otherwise. More...
 
bool retdec::utils::containsAnyOfChars (const std::string &str, std::string::value_type c)
 Returns true if str contains c, false otherwise. More...
 
std::string retdec::utils::toLower (std::string str)
 Converts all characters in str to lower case. More...
 
std::string retdec::utils::toUpper (std::string str)
 Converts all characters in str to upper case. More...
 
std::string retdec::utils::toWide (const std::string &str, std::string::size_type length)
 Converts str to wide string. More...
 
std::string retdec::utils::unicodeToAscii (const std::uint8_t *bytes, std::size_t nBytes)
 Converts unicode bytes to ASCII string. More...
 
std::string retdec::utils::unicodeToAscii (const std::uint8_t *bytes, std::size_t nBytes, std::size_t &nRead)
 Converts unicode bytes to ASCII string. More...
 
std::string retdec::utils::readNullTerminatedAscii (const std::uint8_t *bytes, std::size_t bytesLen, std::size_t offset, std::size_t maxBytes, bool failOnExceed)
 Read up to maxBytes bytes as ASCII string. More...
 
std::string retdec::utils::trim (std::string str, const std::string &toTrim)
 Trims the given string. More...
 
std::vector< std::string > retdec::utils::split (const std::string &str, char sep, bool trimWhitespace)
 Splits the given string by a separator. More...
 
std::string retdec::utils::unifyLineEnds (const std::string &str)
 Unifies line ends in the given string to LF. More...
 
std::string retdec::utils::addSlashes (const std::string &str, const std::string &toBackslash)
 Returns str with backslashes before characters that need to be quoted, specified in toBackslash. More...
 
std::string retdec::utils::replaceCharsWithStrings (const std::string &str, char what, const std::string &withWhat)
 Replaces all occurrences of what with withWhat in str and returns the resulting string. More...
 
bool retdec::utils::endsWith (const std::string &str, const std::string &withWhat)
 Retruns true if str ends with the suffix withWhat, false otherwise. More...
 
bool retdec::utils::endsWith (const std::string &str, char withWhat)
 Retruns true if str ends with the suffix withWhat, false otherwise. More...
 
bool retdec::utils::endsWith (const std::string &str, const std::set< std::string > &withWhat)
 
bool retdec::utils::hasSubstringOnPosition (const std::string &str, const std::string &withWhat, std::string::size_type position)
 Returns true if str has substring withWhat on index position. More...
 
bool retdec::utils::hasSubstringInArea (const std::string &str, const std::string &withWhat, std::string::size_type start, std::string::size_type stop)
 Returns true if str has substring withWhat in area bordered by offsets start and stop. More...
 
bool retdec::utils::isComposedOnlyOfChars (const std::string &str, const std::string &chars)
 Returns true if str is composed solely of chars in chars, false otherwise. More...
 
bool retdec::utils::isComposedOnlyOfChars (const std::string &str, std::string::value_type c)
 Returns true if str is composed solely of char c, false otherwise. More...
 
bool retdec::utils::isComposedOnlyOfStrings (const std::string &str, const std::string &ss)
 Returns true if str is composed solely of strings ss, false otherwise. More...
 
std::string retdec::utils::stripDirs (const std::string &path)
 Strips all directories from the given path. More...
 
std::string retdec::utils::replaceAll (const std::string &str, const std::string &from, const std::string &to)
 Replaces all occurrences of from in str with to and returns the string obtained in this way. More...
 
std::string retdec::utils::replaceNonprintableChars (const std::string &str)
 Replaces non-printable characters in str with their hexadecimal values. More...
 
std::string retdec::utils::replaceNonasciiChars (const std::string &str)
 Replaces non-ASCII characters in str with their hexadecimal values. More...
 
std::string retdec::utils::replaceNonalnumCharsWith (const std::string &str, std::string::value_type c)
 Replaces non-alphanumeric characters in str with c. More...
 
std::string retdec::utils::removeWhitespace (std::string s)
 Removes all whitespace from the given string. More...
 
std::pair< std::size_t, std::size_t > retdec::utils::getLineAndColumnFromPosition (const std::string &json, std::size_t position)
 Transform position in json into line and column location. More...
 
bool retdec::utils::isNumber (const std::string &str)
 Checks if the string is a number. More...
 
bool retdec::utils::isIdentifier (const std::string &str)
 Checks if the string is a valid C language identifier. More...
 
bool retdec::utils::isPrintable (const std::string &str)
 Checks if the string is printable. More...
 
std::string retdec::utils::removeLeadingCharacter (const std::string &s, char leading, std::size_t n)
 Removes n leading characters from the given string s and returns the result. More...
 
bool retdec::utils::isContolCharacter (char c)
 
bool retdec::utils::isNiceCharacter (unsigned char c)
 
bool retdec::utils::isNiceString (const std::string &str, double minRatio)
 Does the provided string seem nice, i.e ratio of printable characters and escape sequences in the string is at least minRatio. More...
 
bool retdec::utils::isNiceAsciiWideCharacter (unsigned long long c)
 
bool retdec::utils::isNiceAsciiWideString (const std::vector< unsigned long long > &str, double minRatio)
 Does the provided wide string consist only from ASCII characters and is nice? Nice string have ration of printable characters and escape sequences in the string is at least minRatio. Empty string is never nice. More...
 
std::string retdec::utils::getIndentation (std::size_t count, char c)
 Returns an indentation string containing the specified number of characters. More...
 
void retdec::utils::appendHex (std::string &n, const long long a)
 Appends hexadecimal address to string (typically object name). More...
 
void retdec::utils::appendDec (std::string &n, const long long a)
 Appends hexadecimal address to string (typically object name). More...
 
std::string retdec::utils::appendHexRet (const std::string &n, const long long a)
 Appends hexadecimal address to string and return new string. More...
 
std::string retdec::utils::appendDecRet (const std::string &n, const long long a)
 Appends hexadecimal address to string and return new string. More...
 
void retdec::utils::removeSuffix (std::string &n, const std::string &suffix)
 Finds the last occurrence of the specified suffix and removes everything from its start to the end. More...
 
std::string retdec::utils::removeSuffixRet (const std::string &n, const std::string &suffix)
 Finds the last occurrence of the specified suffix and removes everything from its start to the end. More...
 
std::string retdec::utils::normalizeName (const std::string &name)
 Replaces all special symbols by their normalized equivalent. More...
 
std::string retdec::utils::normalizeNamePrefix (const std::string &name)
 
bool retdec::utils::findFirstInEmbeddedLists (std::size_t &pos, const std::string &str, char c, const std::vector< std::pair< char, char >> &pairs)
 Finds the first occurrence of c character in string str that is outside of embedded lists delimited by pairs. More...
 
std::string retdec::utils::removeConsecutiveSpaces (const std::string &str)
 
std::string retdec::utils::asEscapedCString (const WideStringType &value, std::size_t charSize)
 Returns the constant's value as an escaped C string. More...
 
std::string retdec::utils::removeComments (const std::string &str, char commentChar)
 
std::string retdec::utils::extractVersion (const std::string &input)
 

Detailed Description

String utilities.