OpenASIP 2.2
Loading...
Searching...
No Matches
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
42class TCEString;
43
44// Type aliases
45typedef const std::string& stringCRef;
46typedef 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 */
53class TCEString : public std::string {
54public:
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 static std::string intToHexString(int num);
121 static std::string unsignedToHexString(unsigned num);
122
123 struct ICLess {
124 bool operator() (const TCEString& lhs, const TCEString& rhs) const;
125 };
126
127private:
128};
129
130
131
132#include "TCEString.icc"
133
134#endif
const TCEString & TCEStringCRef
Definition TCEString.hh:46
const std::string & stringCRef
Definition TCEString.hh:45
TCEString operator+(int val) const
Definition TCEString.cc:146
static unsigned replace(std::string &str, const std::string &oldPattern, const std::string &newPattern)
Definition TCEString.cc:251
TCEString lower() const
Definition TCEString.cc:78
static TCEString toUpper(const TCEString &str, const std::locale &loc=std::locale())
Definition TCEString.cc:156
TCEString upper() const
Definition TCEString.cc:86
TCEString capitalize() const
Definition TCEString.cc:106
static std::string filterDigits(const std::string &str)
Definition TCEString.cc:278
bool ciEqual(const TCEString &other) const
Definition TCEString.cc:63
bool startsWith(const std::string &str) const
static std::string & appendToNonEmpty(std::string &toAppend, stringCRef appender)
Definition TCEString.cc:201
TCEString & replaceString(const std::string &old, const std::string &newString)
Definition TCEString.cc:94
static std::string & appendInteger(std::string &toAppend, const IntegerType &appender)
bool endsWith(const std::string &str) const
TCEString & operator<<(const TCEString &rhs)
Definition TCEString.cc:128
TCEString & appendIf(bool expression, stringCRef ifTrue)
Definition TCEString.cc:119
static std::string makeString(const IterableContainer &container, const std::string &separator=", ")
std::vector< TCEString > split(const std::string &delim) const
Definition TCEString.cc:114
static std::string appendInteger(stringCRef toAppend, const IntegerType &appender)
static std::string intToHexString(int num)
Definition TCEString.cc:288
virtual ~TCEString()
Definition TCEString.cc:52
static std::string unsignedToHexString(unsigned num)
Definition TCEString.cc:295
static std::string toLower(const std::string &str, const std::locale &loc=std::locale())
Definition TCEString.cc:184
static std::string applyIf(bool expression, stringCRef ifTrue, stringCRef ifFalse)
Definition TCEString.cc:229
bool operator()(const TCEString &lhs, const TCEString &rhs) const
Definition TCEString.cc:310