byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
iff.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 Kristiyan Manev (University of Manchester)
3  *
4  * Licensed under the Apache License, Version 2.0(the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef STR_IFF_H
18 #define STR_IFF_H
19 
20 #include<iostream>
21 #include<string>
22 #include<sstream>
23 
24 /**************************************************************************/
29 namespace str{
30  namespace iff {
32  template<typename ... Rest> inline bool stringEndsWith(std::string checkedString)
33  {
34  return false;
35  }
37  template<typename ... Rest> inline bool stringEndsWith(std::string checkedString, std::string nextString, Rest ... restStrings)
38  {
39  if(checkedString.length() >= nextString.length())
40  if(0 == checkedString.compare (checkedString.length() - nextString.length(), nextString.length(), nextString))
41  return true;
42  return stringEndsWith(checkedString, restStrings...);
43  }
45  template<typename ... Rest> inline bool stringIs(std::string checkedString)
46  {
47  return false;
48  }
50  template<typename ... Rest> inline bool stringIs(std::string checkedString, std::string nextString, Rest ... restStrings)
51  {
52  if(checkedString == nextString)
53  return true;
54  return stringIs(checkedString, restStrings...);
55  }
57  template<typename ... Rest> inline bool stringContains(std::string checkedString)
58  {
59  return false;
60  }
62  template<typename ... Rest> inline bool stringContains(std::string checkedString, std::string nextString, Rest ... restStrings)
63  {
64  if(std::string::npos != checkedString.rfind(nextString))
65  return true;
66  return stringContains(checkedString, restStrings...);
67  }
69  template<typename ... Rest> inline bool stringBeginsWith(std::string checkedString)
70  {
71  return false;
72  }
74  template<typename ... Rest> inline bool stringBeginsWith(std::string checkedString, std::string nextString, Rest ... restStrings)
75  {
76  if(0 == checkedString.rfind(nextString, 0))
77  return true;
78  return stringBeginsWith(checkedString, restStrings...);
79  }
81  template<typename ... Rest> inline bool stringWordIs(std::string checkedString)
82  {
83  return false;
84  }
86  template<typename ... Rest> inline bool stringWordIs(std::string checkedString, std::string nextString, Rest ... restStrings)
87  {
88  if(checkedString == nextString)
89  return true;
90  return stringBeginsWith(checkedString, restStrings...);
91  }
93  template<typename ... Rest> inline bool firstStringWordIs(std::string checkedString, std::string nextString, Rest ... restStrings)
94  {
95  std::stringstream ss(checkedString);
96  std::string firstWord;
97  ss >> firstWord;
98  return stringWordIs(firstWord, nextString, restStrings...);
99  }
101  template<typename ... Rest> inline bool charIs(char checkedChar)
102  {
103  return false;
104  }
106  template<typename ... Rest> inline bool charIs(char checkedChar, char nextChar, Rest ... restChars)
107  {
108  if(checkedChar == nextChar)
109  return true;
110  return charIs(checkedChar, restChars...);
111  }
112  }
113 }
114 #endif //STR_IFF_H
bool charIs(char checkedChar)
Returns false. End of recursion for template.
Definition: iff.h:101
bool stringBeginsWith(std::string checkedString)
Returns false. End of recursion for template.
Definition: iff.h:69
bool stringIs(std::string checkedString)
Returns false. End of recursion for template.
Definition: iff.h:45
bool stringEndsWith(std::string checkedString)
Returns false. End of recursion for template.
Definition: iff.h:32
bool firstStringWordIs(std::string checkedString, std::string nextString, Rest ... restStrings)
Returns true if string checkedString's first word matches fully any of strings nextString or restStri...
Definition: iff.h:93
bool stringContains(std::string checkedString)
Returns false. End of recursion for template.
Definition: iff.h:57
bool stringWordIs(std::string checkedString)
Returns false. End of recursion for template.
Definition: iff.h:81
Definition: iff.h:29