ROSE  0.11.145.0
StringUtility/Diagnostics.h
1 #ifndef ROSE_StringUtility_Diagnostics_H
2 #define ROSE_StringUtility_Diagnostics_H
3 
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 
13 namespace Rose {
14 namespace StringUtility {
15 
17 // Functions related to diagnostic messages
19 
21 ROSE_UTIL_API std::string indentMultilineString(const std::string& inputString, int statementColumnNumber);
22 
24 ROSE_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 
42 ROSE_UTIL_API std::string appendAsmComment(const std::string &s, const std::string &comment);
43 
66 template<typename T>
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) + " ";
70  if (1==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) {
78  // string ends with "ies", as in "parties", so emit "party" instead
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")) {
81  // Sometimes we need to drop an "es" rather than just the "s"
82  retval += boost::erase_tail_copy(plural_phrase, 2);
83  } else if (boost::ends_with(plural_phrase, "s") && plural_phrase.size() > 1) {
84  // strings ends with "s", as in "runners", so drop the final "s" to get "runner"
85  retval += boost::erase_tail_copy(plural_phrase, 1);
86  } else {
87  // I give up. Use the plural and risk being grammatically incorrect.
88  retval += plural_phrase;
89  }
90  } else {
91  retval += plural_phrase;
92  }
93  return retval;
94 }
95 
96 // demangledName is defined in rose_support.cpp
102 std::string demangledName(std::string);
103 
104 } // namespace
105 } // namespace
106 
107 #endif
std::string demangledName(std::string)
Compute demangled version of mangled name.
std::string plural(T n, const std::string &plural_phrase, const std::string &singular_phrase="")
Helpful way to print singular or plural words.
Main namespace for the ROSE library.
ROSE_UTIL_API std::string appendAsmComment(const std::string &s, const std::string &comment)
Append an assembly comment to a string.
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 indentMultilineString(const std::string &inputString, int statementColumnNumber)
Formatting support for generated code strings.