VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stringy.h
Go to the documentation of this file.
1 /*
2 * stringy.h
3 *
4 * Copyright 2008 - 2016 Brenton Ross
5 *
6 * This file is part of VICI.
7 *
8 * VICI is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * VICI is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with VICI. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22 
28 #ifndef CFI_STRINGY_H
29 #define CFI_STRINGY_H
30 
31 #include <string>
32 #include <vector>
33 
35 typedef const std::string & csr;
36 
37 namespace VICI
38 {
39 
40 // convenience functions
41 
43 
46 void trim( std::string &s);
47 
49 
54 int split( csr text, std::vector< std::string > & result );
55 
57 
61 std::string expandMacros( csr s );
62 
64 
68 std::string clean( csr s );
69 
71 
74 class Path : public std::string
75 {
76 private:
77  // std::string mPath; // the actual value
78  std::string::size_type lastSlash() const;
79  static bool spacePolicy;
80 
81  // removes surplus /'s
82  void normalise();
83 
84 public:
86  explicit Path();
87 
89 
94  explicit Path( csr path );
95 
97 
101  Path &append( csr name );
102 
104 
108  Path &appendExt( csr ext );
109 
111 
114  Path &up();
115 
119  bool absolute() const;
120 
124  std::string base() const;
125 
129  std::string dir() const;
130 
134  std::string ext() const;
135 
139  std::string name() const;
140 
144  std::string noExt() const;
145 
147 
150  void split( std::vector< std::string > &dirs ) const;
151 
153  bool operator == ( const Path &x ) const;
154 
156  // bool operator == ( const std::string &x ) const;
157 
159  // bool operator == ( const char *x ) const;
160 
162  bool isChildOf( const Path &p ) const;
163 
165  Path & operator = ( const char * );
166 
168  Path & operator = ( const std::string & );
169 
171  operator const char * () const;
172  // operator const std::string & () const;
173 
175  // const std::string & toString() const;
176 
178  bool defined() const;
179 
181  static bool check( const std::string &path );
182 
184  static void setSpacePolicy( bool allowSpaces = false );
185 };
186 
187 
188 } // namespace VICI
189 
190 
191 
192 #endif /* STRINGY_H_ */
static bool check(const std::string &path)
checks for valid string
Definition: stringy.cpp:241
bool operator==(const Path &x) const
test for equality
std::string dir() const
Definition: stringy.cpp:485
std::string base() const
Definition: stringy.cpp:464
bool defined() const
type conversion
Definition: stringy.cpp:428
bool absolute() const
Definition: stringy.cpp:363
Path()
Constructor.
Definition: stringy.cpp:188
std::string name() const
Definition: stringy.cpp:518
Path & up()
shorten this by a level
Definition: stringy.cpp:316
std::string ext() const
Definition: stringy.cpp:501
std::string noExt() const
Definition: stringy.cpp:538
static void setSpacePolicy(bool allowSpaces=false)
set policy for spaces in file names
Definition: stringy.cpp:232
Path & operator=(const char *)
assignment
Definition: stringy.cpp:404
Manipulate path strings.
Definition: stringy.h:74
bool isChildOf(const Path &p) const
test for equality
Definition: stringy.cpp:387
std::string clean(csr s)
Remove everything except alpha, digit, space, dot, hyphen and underscore.
Definition: stringy.cpp:169
std::string expandMacros(csr s)
expand a string containing $ macros
Definition: stringy.cpp:110
int split(csr text, std::vector< std::string > &result)
split a string into sub-strings at spaces
Definition: stringy.cpp:54
void trim(std::string &s)
rip off leading and trailing white spaces
Definition: stringy.cpp:37
Path & appendExt(csr ext)
Append an extension to this.
Definition: stringy.cpp:301
const std::string & csr
short cut for string constants
Definition: vici.h:80
const std::string & csr
Save some time typing and shorten parameter lines.
Definition: stringy.h:35
void split(std::vector< std::string > &dirs) const
break into separate dirs
Definition: stringy.cpp:344
Path & append(csr name)
Append aname to a path.
Definition: stringy.cpp:286