OpenASIP  2.0
TCEString.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2011 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file TCEString.hh
26  *
27  * Declaration of TCEString class.
28  *
29  * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-tut.fi)
30  * @author Pekka Jääskeläinen 2011
31  * @note rating: red
32  */
33 
34 #ifndef TCE_STRING_HH
35 #define TCE_STRING_HH
36 
37 #include <string>
38 #include <vector>
39 #include <locale>
40 
41 
42 class TCEString;
43 
44 // Type aliases
45 typedef const std::string& stringCRef;
46 typedef const TCEString& TCEStringCRef;
47 
48 /**
49  * A simple wrapper around std::string to make forward declarations possible.
50  *
51  * Also provides additional string helpers.
52  */
53 class TCEString : public std::string {
54 public:
55  TCEString();
56  TCEString(const char* text);
57  TCEString(const std::string& text);
58  TCEString(const char c);
59  virtual ~TCEString();
60 
62  const std::string& old, const std::string& newString);
63  bool startsWith(const std::string& str) const;
64  bool endsWith(const std::string& str) const;
65  bool ciEqual(const TCEString& other) const;
66  std::vector<TCEString> split(const std::string& delim) const;
67  TCEString& appendIf(bool expression, stringCRef ifTrue);
68 
69  TCEString lower() const;
70  TCEString upper() const;
71  TCEString capitalize() const;
72 
73  TCEString operator+(int val) const;
74  TCEString operator+(char c) const;
75 
76  TCEString& operator<<(const TCEString& rhs);
77  TCEString& operator<<(const char* rhs);
78  TCEString& operator<<(const int rhs);
79 
80  static TCEString toUpper(
81  const TCEString& str, const std::locale& loc = std::locale());
82  static std::string toUpper(
83  const std::string& str, const std::locale& loc = std::locale());
84  static TCEString& toUpper(
85  TCEString& str, const std::locale& loc = std::locale());
86  static std::string& toUpper(
87  std::string& str, const std::locale& loc = std::locale());
88  static std::string toLower(
89  const std::string& str, const std::locale& loc = std::locale());
90 
91  static std::string& appendToNonEmpty(
92  std::string& toAppend, stringCRef appender);
93  static std::string appendToNonEmpty(
94  stringCRef toAppend, stringCRef appender);
95  static std::string applyIf(
96  bool expression, stringCRef ifTrue, stringCRef ifFalse);
97  static std::string applyIf(
98  bool expression, stringCRef ifTrue);
99  template<typename IntegerType>
100  static std::string& appendInteger(
101  std::string& toAppend,
102  const IntegerType& appender);
103  template<typename IntegerType>
104  static std::string appendInteger(
105  stringCRef toAppend,
106  const IntegerType& appender);
107 
108  template<typename IterableContainer>
109  static std::string makeString(
110  const IterableContainer& container,
111  const std::string& separator = ", ");
112 
113  static unsigned replace(
114  std::string& str,
115  const std::string& oldPattern,
116  const std::string& newPattern);
117 
118  static std::string filterDigits(const std::string& str);
119 
120  struct ICLess {
121  bool operator() (const TCEString& lhs, const TCEString& rhs) const;
122  };
123 
124 private:
125 };
126 
127 
128 
129 #include "TCEString.icc"
130 
131 #endif
TCEString::appendIf
TCEString & appendIf(bool expression, stringCRef ifTrue)
Definition: TCEString.cc:119
TCEString::TCEString
TCEString()
Definition: TCEString.cc:40
TCEString::lower
TCEString lower() const
Definition: TCEString.cc:78
TCEString::split
std::vector< TCEString > split(const std::string &delim) const
Definition: TCEString.cc:114
TCEString::startsWith
bool startsWith(const std::string &str) const
TCEString::applyIf
static std::string applyIf(bool expression, stringCRef ifTrue, stringCRef ifFalse)
Definition: TCEString.cc:229
TCEString::appendInteger
static std::string & appendInteger(std::string &toAppend, const IntegerType &appender)
TCEString.icc
TCEString::replace
static unsigned replace(std::string &str, const std::string &oldPattern, const std::string &newPattern)
Definition: TCEString.cc:251
TCEString::capitalize
TCEString capitalize() const
Definition: TCEString.cc:106
TCEString::upper
TCEString upper() const
Definition: TCEString.cc:86
stringCRef
const typedef std::string & stringCRef
Definition: TCEString.hh:42
TCEString::ciEqual
bool ciEqual(const TCEString &other) const
Definition: TCEString.cc:63
TCEString::ICLess
Definition: TCEString.hh:120
TCEString::~TCEString
virtual ~TCEString()
Definition: TCEString.cc:52
TCEString::endsWith
bool endsWith(const std::string &str) const
TCEString::filterDigits
static std::string filterDigits(const std::string &str)
Definition: TCEString.cc:278
TCEString::replaceString
TCEString & replaceString(const std::string &old, const std::string &newString)
Definition: TCEString.cc:94
TCEString::ICLess::operator()
bool operator()(const TCEString &lhs, const TCEString &rhs) const
Definition: TCEString.cc:296
TCEString::appendToNonEmpty
static std::string & appendToNonEmpty(std::string &toAppend, stringCRef appender)
Definition: TCEString.cc:201
TCEString
Definition: TCEString.hh:53
TCEString::operator<<
TCEString & operator<<(const TCEString &rhs)
Definition: TCEString.cc:128
TCEString::makeString
static std::string makeString(const IterableContainer &container, const std::string &separator=", ")
TCEString::operator+
TCEString operator+(int val) const
Definition: TCEString.cc:146
TCEString::toLower
static std::string toLower(const std::string &str, const std::locale &loc=std::locale())
Definition: TCEString.cc:184
TCEString::toUpper
static TCEString toUpper(const TCEString &str, const std::locale &loc=std::locale())
Definition: TCEString.cc:156
TCEStringCRef
const typedef TCEString & TCEStringCRef
Definition: TCEString.hh:46