1 #ifndef ROSE_StringUtility_Diagnostics_H
2 #define ROSE_StringUtility_Diagnostics_H
6 #include <boost/algorithm/string/erase.hpp>
7 #include <boost/algorithm/string/predicate.hpp>
8 #include <boost/algorithm/string/replace.hpp>
9 #include <boost/lexical_cast.hpp>
14 namespace StringUtility {
21 ROSE_UTIL_API std::string
indentMultilineString(
const std::string& inputString,
int statementColumnNumber);
25 const std::string &abbr,
const std::string &full);
42 ROSE_UTIL_API std::string
appendAsmComment(
const std::string &s,
const std::string &comment);
67 std::string
plural(T n,
const std::string &plural_phrase,
const std::string &singular_phrase=
"") {
68 assert(!plural_phrase.empty());
69 std::string retval = boost::lexical_cast<std::string>(n) +
" ";
71 if (!singular_phrase.empty()) {
72 retval += singular_phrase;
73 }
else if (boost::ends_with(plural_phrase,
"vertices")) {
74 retval += boost::replace_tail_copy(plural_phrase, 8,
"vertex");
75 }
else if (boost::ends_with(plural_phrase,
"indices")) {
76 retval += boost::replace_tail_copy(plural_phrase, 7,
"index");
77 }
else if (boost::ends_with(plural_phrase,
"ies") && plural_phrase.size() > 3) {
79 retval += boost::replace_tail_copy(plural_phrase, 3,
"y");
80 }
else if (boost::ends_with(plural_phrase,
"sses") || boost::ends_with(plural_phrase,
"indexes")) {
82 retval += boost::erase_tail_copy(plural_phrase, 2);
83 }
else if (boost::ends_with(plural_phrase,
"s") && plural_phrase.size() > 1) {
85 retval += boost::erase_tail_copy(plural_phrase, 1);
88 retval += plural_phrase;
91 retval += plural_phrase;