OpenASIP  2.0
Classes | Public Member Functions | Static Public Member Functions | List of all members
TCEString Class Reference

#include <TCEString.hh>

Inheritance diagram for TCEString:
Inheritance graph
Collaboration diagram for TCEString:
Collaboration graph

Classes

struct  ICLess
 

Public Member Functions

 TCEString ()
 
 TCEString (const char *text)
 
 TCEString (const std::string &text)
 
 TCEString (const char c)
 
virtual ~TCEString ()
 
TCEStringreplaceString (const std::string &old, const std::string &newString)
 
bool startsWith (const std::string &str) const
 
bool endsWith (const std::string &str) const
 
bool ciEqual (const TCEString &other) const
 
std::vector< TCEStringsplit (const std::string &delim) const
 
TCEStringappendIf (bool expression, stringCRef ifTrue)
 
TCEString lower () const
 
TCEString upper () const
 
TCEString capitalize () const
 
TCEString operator+ (int val) const
 
TCEString operator+ (char c) const
 
TCEStringoperator<< (const TCEString &rhs)
 
TCEStringoperator<< (const char *rhs)
 
TCEStringoperator<< (const int rhs)
 

Static Public Member Functions

static TCEString toUpper (const TCEString &str, const std::locale &loc=std::locale())
 
static std::string toUpper (const std::string &str, const std::locale &loc=std::locale())
 
static TCEStringtoUpper (TCEString &str, const std::locale &loc=std::locale())
 
static std::string & toUpper (std::string &str, const std::locale &loc=std::locale())
 
static std::string toLower (const std::string &str, const std::locale &loc=std::locale())
 
static std::string & appendToNonEmpty (std::string &toAppend, stringCRef appender)
 
static std::string appendToNonEmpty (stringCRef toAppend, stringCRef appender)
 
static std::string applyIf (bool expression, stringCRef ifTrue, stringCRef ifFalse)
 
static std::string applyIf (bool expression, stringCRef ifTrue)
 
template<typename IntegerType >
static std::string & appendInteger (std::string &toAppend, const IntegerType &appender)
 
template<typename IntegerType >
static std::string appendInteger (stringCRef toAppend, const IntegerType &appender)
 
template<typename IterableContainer >
static std::string makeString (const IterableContainer &container, const std::string &separator=", ")
 
static unsigned replace (std::string &str, const std::string &oldPattern, const std::string &newPattern)
 
static std::string filterDigits (const std::string &str)
 

Detailed Description

A simple wrapper around std::string to make forward declarations possible.

Also provides additional string helpers.

Definition at line 53 of file TCEString.hh.

Constructor & Destructor Documentation

◆ TCEString() [1/4]

TCEString::TCEString ( )

Definition at line 40 of file TCEString.cc.

40  : std::string() {
41 }

Referenced by operator+(), and operator<<().

◆ TCEString() [2/4]

TCEString::TCEString ( const char *  text)

Definition at line 43 of file TCEString.cc.

43  : std::string(text) {
44 }

◆ TCEString() [3/4]

TCEString::TCEString ( const std::string &  text)

Definition at line 46 of file TCEString.cc.

46  : std::string(text) {
47 }

◆ TCEString() [4/4]

TCEString::TCEString ( const char  c)

Definition at line 49 of file TCEString.cc.

49  : std::string(std::string("") + c) {
50 }

◆ ~TCEString()

TCEString::~TCEString ( )
virtual

Definition at line 52 of file TCEString.cc.

52  {
53 }

Member Function Documentation

◆ appendIf()

TCEString & TCEString::appendIf ( bool  expression,
stringCRef  ifTrue 
)

Definition at line 119 of file TCEString.cc.

119  {
120  if (expression) {
121  append(ifTrue);
122  }
123  return *this;
124 }

◆ appendInteger() [1/2]

template<typename IntegerType >
static std::string& TCEString::appendInteger ( std::string &  toAppend,
const IntegerType &  appender 
)
static

◆ appendInteger() [2/2]

template<typename IntegerType >
static std::string TCEString::appendInteger ( stringCRef  toAppend,
const IntegerType &  appender 
)
static

◆ appendToNonEmpty() [1/2]

std::string & TCEString::appendToNonEmpty ( std::string &  toAppend,
stringCRef  appender 
)
static

Appends a string if the target string is not empty.

Parameters
toAppendThe target string.
appenderThe string to append with.
Returns
Reference to original possibly appended with appender.

Definition at line 201 of file TCEString.cc.

202  {
203  if (!toAppend.empty()) {
204  return toAppend += appender;
205  } else {
206  return toAppend;
207  }
208 }

Referenced by appendToNonEmpty(), and DefaultDecoderGenerator::writeSquashSignalGenerationProcess().

◆ appendToNonEmpty() [2/2]

std::string TCEString::appendToNonEmpty ( stringCRef  toAppend,
stringCRef  appender 
)
static

Returns string of target string appended with another string if the target string is not empty.

Parameters
toAppendThe target string.
appenderThe string to append with.
Returns
String initialized with toAppend and possibly appended with appender.

Definition at line 219 of file TCEString.cc.

220  {
221  std::string tmp(toAppend);
222  return appendToNonEmpty(tmp, appender);
223 }

References appendToNonEmpty().

Here is the call graph for this function:

◆ applyIf() [1/2]

std::string TCEString::applyIf ( bool  expression,
stringCRef  ifTrue 
)
static

Returns string if "expression" is true. Otherwise return empty string.

Definition at line 241 of file TCEString.cc.

241  {
242  return applyIf(expression, ifTrue, "");
243 }

References applyIf().

Here is the call graph for this function:

◆ applyIf() [2/2]

std::string TCEString::applyIf ( bool  expression,
stringCRef  ifTrue,
stringCRef  ifFalse 
)
static

Returns first string if "expression" is true. Otherwise return second.

Definition at line 229 of file TCEString.cc.

229  {
230  if (expression) {
231  return ifTrue;
232  } else {
233  return ifFalse;
234  }
235 }

Referenced by applyIf(), and ProGe::NetlistVisualization::printBlockTree().

◆ capitalize()

TCEString TCEString::capitalize ( ) const

Return a copy of the string with its first character in upper case and the rest in lower case.

Definition at line 106 of file TCEString.cc.

106  {
107  if (size() == 0) return "";
108  if (size() == 1) return upper();
109  return StringTools::stringToUpper(substr(0, 1)) +
110  StringTools::stringToLower(substr(1, size() - 1));
111 }

References StringTools::stringToLower(), StringTools::stringToUpper(), and upper().

Here is the call graph for this function:

◆ ciEqual()

bool TCEString::ciEqual ( const TCEString other) const

Returns true if two strings are equal if the case is not taken into account.

Parameters
aA string.
bAnother string.
Returns
True if strings equal case-insensitively.

Definition at line 63 of file TCEString.cc.

63  {
64  unsigned int len = length();
65  if (len != other.length()) return false;
66  for (unsigned int i = 0; i < len; i++) {
67  if (tolower((*this)[i]) != tolower(other[i])) {
68  return false;
69  }
70  }
71  return true;
72 }

Referenced by OperationIndex::effectiveOperation(), ControlFlowGraph::findLLVMTargetInstrDesc(), OperationIndex::moduleOf(), and OperationDAGSelector::CaseInsensitiveCmp::operator()().

◆ endsWith()

bool TCEString::endsWith ( const std::string &  str) const

◆ filterDigits()

std::string TCEString::filterDigits ( const std::string &  str)
static

Returns string in which all non-digit characters have been removed.

Definition at line 278 of file TCEString.cc.

278  {
279  std::string result;
280  result.reserve(str.size());
281  for (auto c : str) {
282  if (std::isdigit(c)) result += c;
283  }
284  return result;
285 }

◆ lower()

TCEString TCEString::lower ( ) const

◆ makeString()

template<typename IterableContainer >
static std::string TCEString::makeString ( const IterableContainer &  container,
const std::string &  separator = ", " 
)
static

◆ operator+() [1/2]

TCEString TCEString::operator+ ( char  c) const

Definition at line 151 of file TCEString.cc.

151  {
152  return *this + TCEString(c);
153 }

References TCEString().

Here is the call graph for this function:

◆ operator+() [2/2]

TCEString TCEString::operator+ ( int  val) const

Definition at line 146 of file TCEString.cc.

146  {
147  return TCEString(*this) += Conversion::toString(val);
148 }

References TCEString(), and Conversion::toString().

Here is the call graph for this function:

◆ operator<<() [1/3]

TCEString & TCEString::operator<< ( const char *  rhs)

Definition at line 134 of file TCEString.cc.

134  {
135  *this += TCEString(rhs);
136  return *this;
137 }

References TCEString().

Here is the call graph for this function:

◆ operator<<() [2/3]

TCEString & TCEString::operator<< ( const int  rhs)

Definition at line 140 of file TCEString.cc.

140  {
141  *this += Conversion::toString(rhs);
142  return *this;
143 }

References Conversion::toString().

Here is the call graph for this function:

◆ operator<<() [3/3]

TCEString & TCEString::operator<< ( const TCEString rhs)

Definition at line 128 of file TCEString.cc.

128  {
129  *this += rhs;
130  return *this;
131 }

◆ replace()

unsigned TCEString::replace ( std::string &  str,
const std::string &  oldPattern,
const std::string &  newPattern 
)
static

Replaces all occurrences of oldPattern in str with newPattern.

Returns
Number of made replacements.

Definition at line 251 of file TCEString.cc.

254  {
255 
256  unsigned replacementCount = 0;
257 
258  std::string::size_type location = str.find(oldPattern);
259  while (location != std::string::npos) {
260  str.replace(
261  str.begin() + location,
262  str.begin() + location + oldPattern.length(),
263  newPattern.c_str());
264  replacementCount++;
265  // Avoid infinite recursion if replacing with a string
266  // that also contains the searched string. This happens
267  // when escaping reserved characters such as '_' -> '\\_'.
268  location = str.find(oldPattern, location + newPattern.length());
269  }
270  return replacementCount;
271 }

Referenced by ProGe::NetlistGenerator::addBaseRFToNetlist(), ProGe::NetlistGenerator::addFUExternalPortsToNetlist(), replaceString(), and OperationDAGDialog::updateDAG().

◆ replaceString()

TCEString & TCEString::replaceString ( const std::string &  old,
const std::string &  newString 
)

◆ split()

std::vector< TCEString > TCEString::split ( const std::string &  delim) const

Definition at line 114 of file TCEString.cc.

114  {
115  return StringTools::chopString(*this, delim);
116 }

References StringTools::chopString().

Referenced by ControlFlowGraph::buildMBBFromBB(), llvm::LLVMTCEPOMBuilder::createFUTerminal(), main(), and PRegionMarkerAnalyzer::parsePregionID().

Here is the call graph for this function:

◆ startsWith()

bool TCEString::startsWith ( const std::string &  str) const

◆ toLower()

std::string TCEString::toLower ( const std::string &  str,
const std::locale &  loc = std::locale() 
)
static

Definition at line 184 of file TCEString.cc.

185  {
186  std::string result(str);
187  for (size_t i = 0; i < result.size(); i++) {
188  result.at(i) = std::tolower(result.at(i), loc);
189  }
190  return result;
191 }

◆ toUpper() [1/4]

std::string TCEString::toUpper ( const std::string &  str,
const std::locale &  loc = std::locale() 
)
static

Definition at line 162 of file TCEString.cc.

162  {
163  std::string newStr(str);
164  return toUpper(newStr, loc);
165 }

References toUpper().

Here is the call graph for this function:

◆ toUpper() [2/4]

TCEString TCEString::toUpper ( const TCEString str,
const std::locale &  loc = std::locale() 
)
static

Definition at line 156 of file TCEString.cc.

156  {
157  TCEString newStr(str);
158  return toUpper(newStr, loc);
159 }

Referenced by ImmediateAnalyzer::analyzeImmediateCapabilitiesForOperation(), and toUpper().

◆ toUpper() [3/4]

std::string & TCEString::toUpper ( std::string &  str,
const std::locale &  loc = std::locale() 
)
static

Definition at line 176 of file TCEString.cc.

176  {
177  for (size_t i = 0; i < str.size(); i++) {
178  str.at(i) = std::toupper(str.at(i), loc);
179  }
180  return str;
181 }

◆ toUpper() [4/4]

TCEString & TCEString::toUpper ( TCEString str,
const std::locale &  loc = std::locale() 
)
static

Definition at line 168 of file TCEString.cc.

168  {
169  for (size_t i = 0; i < str.size(); i++) {
170  str.at(i) = std::toupper(str.at(i), loc);
171  }
172  return str;
173 }

◆ upper()

TCEString TCEString::upper ( ) const

Turns the string to uppercase.

Definition at line 86 of file TCEString.cc.

86  {
87  return StringTools::stringToUpper(*this);
88 }

References StringTools::stringToUpper().

Referenced by capitalize(), Operation::isBaseOffsetMemOperation(), ImmInfo::key(), MIDDGNode::osalOperationName(), MachineInfo::supportsOperation(), TDGen::writeOperationDefs(), and TDGen::writePortGuardedJumpDefPair().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
TCEString::TCEString
TCEString()
Definition: TCEString.cc:40
TCEString::applyIf
static std::string applyIf(bool expression, stringCRef ifTrue, stringCRef ifFalse)
Definition: TCEString.cc:229
TCEString::replace
static unsigned replace(std::string &str, const std::string &oldPattern, const std::string &newPattern)
Definition: TCEString.cc:251
TCEString::upper
TCEString upper() const
Definition: TCEString.cc:86
Conversion::toString
static std::string toString(const T &source)
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
TCEString::appendToNonEmpty
static std::string & appendToNonEmpty(std::string &toAppend, stringCRef appender)
Definition: TCEString.cc:201
TCEString
Definition: TCEString.hh:53
StringTools::chopString
static std::vector< TCEString > chopString(const std::string &source, const std::string &delimiters)
Definition: StringTools.cc:181
TCEString::toUpper
static TCEString toUpper(const TCEString &str, const std::locale &loc=std::locale())
Definition: TCEString.cc:156
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160