OpenASIP  2.0
TCEString.icc
Go to the documentation of this file.
1 /**
2  * @file TCEString.icc
3  *
4  * Inline implementations of TCEString class.
5  *
6  * @author Pekka Jääskeläinen 2008 (pekka.jaaskelainen@tut.fi)
7  * @note rating: red
8  */
9 
10 #include "StringTools.hh"
11 #include "Conversion.hh"
12 
13 /**
14  * Returns true in case the string starts with the given string.
15  */
16 inline bool
17 TCEString::startsWith(const std::string& str) const {
18  return str.size() <= size() && substr(0, str.size()) == str;
19 }
20 
21 /**
22  * Returns true in case the string ends with the given string.
23  */
24 inline bool
25 TCEString::endsWith(const std::string& str) const {
26  return str.size() <= size() && substr(size() - str.size(), size()) == str;
27 }
28 
29 /**
30  * Appends appender that is convertible to integer to string toAppend.
31  *
32  * @return returns reference toAppend with appended integer.
33  */
34 template<typename IntegerType>
35 std::string&
36 TCEString::appendInteger(
37  std::string& toAppend,
38  const IntegerType& appender) {
39 
40  toAppend += Conversion::toString(appender);
41  return toAppend;
42 }
43 
44 /**
45  * Appends appender that is convertible to integer to string toAppend.
46  *
47  * @return returns string of toAppend with appended integer.
48  */
49 template<typename IntegerType>
50 std::string
51 TCEString::appendInteger(
52  stringCRef toAppend,
53  const IntegerType& appender) {
54 
55  return std::string(toAppend + Conversion::toString(appender));
56 }
57 
58 /**
59  * Makes single string from container's elements separated by delimiter.
60  *
61  * Default delimiter is ", ".
62  *
63  */
64 template<typename IterableContainer>
65 std::string
66 TCEString::makeString(
67  const IterableContainer& container,
68  const std::string& separator) {
69 
70  std::string result;
71 
72  typename IterableContainer::const_iterator it;
73  for (it = container.begin(); it != container.end(); it++) {
74  appendToNonEmpty(result, separator);
75  result +=
76  Conversion::toString<typename IterableContainer::value_type>(*it);
77  }
78  return result;
79 }
80