ROSE 0.11.145.192
StringUtility/Diagnostics.h
1#ifndef ROSE_StringUtility_Diagnostics_H
2#define ROSE_StringUtility_Diagnostics_H
3#include <RoseFirst.h>
4#include <rosedll.h>
5
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>
10#include <cassert>
11#include <string>
12
13namespace Rose {
14namespace StringUtility {
15
17// Functions related to diagnostic messages
19
21ROSE_UTIL_API std::string indentMultilineString(const std::string& inputString, int statementColumnNumber);
22
24ROSE_UTIL_API void add_to_reason_string(std::string &result, bool isset, bool do_pad,
25 const std::string &abbr, const std::string &full);
26
27
42ROSE_UTIL_API std::string appendAsmComment(const std::string &s, const std::string &comment);
43
55std::string insertCommas(const std::string&);
56
57template<class T>
58std::string insertCommas(const T &x) {
59 std::ostringstream ss;
60 ss <<x;
61 return insertCommas(ss.str());
62}
87template<typename T>
88std::string plural(T n, const std::string &plural_phrase, const std::string &singular_phrase="") {
89 assert(!plural_phrase.empty());
90 std::string retval = insertCommas(boost::lexical_cast<std::string>(n)) + " ";
91 if (1==n) {
92 if (!singular_phrase.empty()) {
93 retval += singular_phrase;
94 } else if (boost::ends_with(plural_phrase, "vertices")) {
95 retval += boost::replace_tail_copy(plural_phrase, 8, "vertex");
96 } else if (boost::ends_with(plural_phrase, "indices")) {
97 retval += boost::replace_tail_copy(plural_phrase, 7, "index");
98 } else if (boost::ends_with(plural_phrase, "ies") && plural_phrase.size() > 3) {
99 // string ends with "ies", as in "parties", so emit "party" instead
100 retval += boost::replace_tail_copy(plural_phrase, 3, "y");
101 } else if (boost::ends_with(plural_phrase, "sses") || boost::ends_with(plural_phrase, "indexes")) {
102 // Sometimes we need to drop an "es" rather than just the "s"
103 retval += boost::erase_tail_copy(plural_phrase, 2);
104 } else if (boost::ends_with(plural_phrase, "s") && plural_phrase.size() > 1) {
105 // strings ends with "s", as in "runners", so drop the final "s" to get "runner"
106 retval += boost::erase_tail_copy(plural_phrase, 1);
107 } else {
108 // I give up. Use the plural and risk being grammatically incorrect.
109 retval += plural_phrase;
110 }
111 } else {
112 retval += plural_phrase;
113 }
114 return retval;
115}
116
117// demangledName is defined in rose_support.cpp
123std::string demangledName(std::string);
124
125} // namespace
126} // namespace
127
128#endif
std::string demangledName(std::string)
Compute demangled version of mangled name.
ROSE_UTIL_API std::string indentMultilineString(const std::string &inputString, int statementColumnNumber)
Formatting support for generated code strings.
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.
ROSE_UTIL_API std::string appendAsmComment(const std::string &s, const std::string &comment)
Append an assembly comment to a string.
std::string plural(T n, const std::string &plural_phrase, const std::string &singular_phrase="")
Helpful way to print singular or plural words.
std::string insertCommas(const std::string &)
Insert commas into large integers in the specified string.
The ROSE library.