ROSE 0.11.145.134
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
53std::string insertCommas(const std::string&);
54
77template<typename T>
78std::string plural(T n, const std::string &plural_phrase, const std::string &singular_phrase="") {
79 assert(!plural_phrase.empty());
80 std::string retval = insertCommas(boost::lexical_cast<std::string>(n)) + " ";
81 if (1==n) {
82 if (!singular_phrase.empty()) {
83 retval += singular_phrase;
84 } else if (boost::ends_with(plural_phrase, "vertices")) {
85 retval += boost::replace_tail_copy(plural_phrase, 8, "vertex");
86 } else if (boost::ends_with(plural_phrase, "indices")) {
87 retval += boost::replace_tail_copy(plural_phrase, 7, "index");
88 } else if (boost::ends_with(plural_phrase, "ies") && plural_phrase.size() > 3) {
89 // string ends with "ies", as in "parties", so emit "party" instead
90 retval += boost::replace_tail_copy(plural_phrase, 3, "y");
91 } else if (boost::ends_with(plural_phrase, "sses") || boost::ends_with(plural_phrase, "indexes")) {
92 // Sometimes we need to drop an "es" rather than just the "s"
93 retval += boost::erase_tail_copy(plural_phrase, 2);
94 } else if (boost::ends_with(plural_phrase, "s") && plural_phrase.size() > 1) {
95 // strings ends with "s", as in "runners", so drop the final "s" to get "runner"
96 retval += boost::erase_tail_copy(plural_phrase, 1);
97 } else {
98 // I give up. Use the plural and risk being grammatically incorrect.
99 retval += plural_phrase;
100 }
101 } else {
102 retval += plural_phrase;
103 }
104 return retval;
105}
106
107// demangledName is defined in rose_support.cpp
113std::string demangledName(std::string);
114
115} // namespace
116} // namespace
117
118#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.