1 #ifndef ROSE_STRING_UTILITY_H
2 #define ROSE_STRING_UTILITY_H
13 #include <msvc_stdint.h>
43 StringWithLineNumber(
const std::string& str,
const std::string& filename,
unsigned int line): str(str), filename(filename), line(line) {}
68 a.insert(a.end(), b.begin(), b.end());
87 if (!f.empty() && f.back().filename ==
"") {
96 f << std::string(str);
107 ROSE_UTIL_API void writeFile (
const std::string& outputString,
const std::string& fileNameString,
const std::string& directoryName );
122 ROSE_UTIL_API std::string
copyEdit (
const std::string& inputString,
const std::string & oldToken,
const std::string & newToken );
140 #if (defined(BACKEND_CXX_IS_GNU_COMPILER) && (((BACKEND_CXX_COMPILER_MAJOR_VERSION_NUMBER == 4) && (BACKEND_CXX_COMPILER_MINOR_VERSION_NUMBER > 6)) || (BACKEND_CXX_COMPILER_MAJOR_VERSION_NUMBER > 4)))
179 const std::string &abbr,
const std::string &full);
195 ROSE_UTIL_API std::string
copyEdit (
const std::string& inputString,
const std::string& oldToken,
const std::string& newToken );
199 inline bool isContainedIn (
const std::string & longString,
const std::string & shortString ) {
200 return longString.find(shortString) != std::string::npos;
208 void splitStringIntoStrings(
const std::string& inputString,
char separator, std::vector<std::string>& stringList );
221 bool popen_wrapper (
const std::string & command, std::vector<std::string> & result );
257 std::list<std::string>
findfile(std::string patternString, std::string pathString);
391 const std::string& appPath);
398 const std::string& appPath,
408 const std::string& appPath,
409 const std::map<std::string, std::string>& libPathCollection);
417 const std::string& appPath,
418 const std::map<std::string, std::string>& libPathCollection,
439 const std::string& right);
458 bool show_unsigned_decimal=
true,
bool show_signed_decimal=
true,
459 uint64_t decimal_threshold=256);
463 template<
typename T> std::string
toHex(T value) {
return toHex2((uint64_t)value, 8*
sizeof(T)); }
490 bool prefixAtFront=
true,
bool prefixAtBack=
false);
516 std::string
encode_base64(
const std::vector<uint8_t> &data,
bool do_pad=
true);
517 std::string
encode_base64(
const uint8_t *data,
size_t nbytes,
bool do_padd=
true);
521 std::vector<uint8_t>
decode_base64(
const std::string &encoded);
527 template<
class Container>
528 std::string
join(
const std::string &separator,
const Container &strings) {
529 return join_range(separator, strings.begin(), strings.end());
531 template<
class Iterator>
532 std::string
join_range(
const std::string &separator, Iterator begin, Iterator end) {
534 for (Iterator i=begin; i!=end; ++i)
535 retval += (i==begin ? std::string() : separator) + *i;
538 std::string
join(
const std::string &separator,
char *strings[],
size_t nstrings);
539 std::string
join(
const std::string &separator,
const char *strings[],
size_t nstrings);
549 ROSE_UTIL_API std::vector<std::string>
split(
const std::string &separator,
const std::string &str,
size_t maxparts=(
size_t)(-1),
550 bool trim_white_space=
false);
551 ROSE_UTIL_API std::vector<std::string>
split(
char separator,
const std::string &str,
size_t maxparts=(
size_t)(-1),
552 bool trim_white_space=
false);
556 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);
559 std::string
untab(
const std::string &str,
size_t tabstops=8,
size_t firstcol=0);
588 template<
class Container,
class Stringifier>
592 template<
class Iterator,
class Stringifier>
594 std::vector<std::string> retval;
595 for (; begin!=end; ++begin)
596 retval.push_back(stringifier(*begin));
617 std::string
plural(T n,
const std::string &plural_word) {
618 assert(!plural_word.empty());
621 if (plural_word.size()>3 && 0==plural_word.substr(plural_word.size()-3).compare(
"ies")) {
623 retval += plural_word.substr(0, plural_word.size()-3) +
"y";
624 }
else if (plural_word.size()>1 && plural_word[plural_word.size()-1]==
's') {
626 retval += plural_word.substr(0, plural_word.size()-1);
629 retval += plural_word;
632 retval += plural_word;