SASSY  0.0
Software Architecture Support System
 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 - 2017 Brenton Ross
5 *
6 * This file is part of SASSY.
7 *
8 * SASSY 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 * SASSY 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 SASSY. 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 SASSY
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 
67 class Path : public std::string
68 {
69 private:
70  // std::string mPath; // the actual value
71  std::string::size_type lastSlash() const;
72  static bool spacePolicy;
73 
74  // removes surplus /'s
75  void normalise();
76 
77 public:
79  explicit Path();
80 
82 
87  explicit Path( csr path );
88 
90 
94  Path &append( csr name );
95 
97 
101  Path &appendExt( csr ext );
102 
104 
107  Path &up();
108 
112  bool absolute() const;
113 
117  std::string base() const;
118 
122  std::string dir() const;
123 
127  std::string ext() const;
128 
132  std::string name() const;
133 
137  std::string noExt() const;
138 
140 
143  void split( std::vector< std::string > &dirs ) const;
144 
146  bool operator == ( const Path &x ) const;
147 
149  // bool operator == ( const std::string &x ) const;
150 
152  // bool operator == ( const char *x ) const;
153 
155  bool isChildOf( const Path &p ) const;
156 
158  Path & operator = ( const char * );
159 
161  Path & operator = ( const std::string & );
162 
164  operator const char * () const;
165  // operator const std::string & () const;
166 
168  // const std::string & toString() const;
169 
171  bool defined() const;
172 
174  static bool check( const std::string &path );
175 
177  static void setSpacePolicy( bool allowSpaces = false );
178 };
179 
180 
181 } // namespace SASSY
182 
183 
184 
185 #endif /* STRINGY_H_ */
bool isChildOf(const Path &p) const
test for equality
Definition: stringy.cpp:366
Path & appendExt(csr ext)
Append an extension to this.
Definition: stringy.cpp:280
std::string name() const
Definition: stringy.cpp:497
Path & operator=(const char *)
assignment
Definition: stringy.cpp:383
std::string noExt() const
Definition: stringy.cpp:517
std::string dir() const
Definition: stringy.cpp:464
Path & append(csr name)
Append aname to a path.
Definition: stringy.cpp:265
bool defined() const
type conversion
Definition: stringy.cpp:407
Manipulate path strings.
Definition: stringy.h:67
Path & up()
shorten this by a level
Definition: stringy.cpp:295
void split(std::vector< std::string > &dirs) const
break into separate dirs
Definition: stringy.cpp:323
Path()
Constructor.
Definition: stringy.cpp:169
bool absolute() const
Definition: stringy.cpp:342
std::string base() const
Definition: stringy.cpp:443
bool operator==(const Path &x) const
test for equality
std::string expandMacros(csr s)
expand a string containing $ macros
Definition: stringy.cpp:108
const std::string & csr
Save some time typing and shorten parameter lines.
Definition: stringy.h:35
std::string ext() const
Definition: stringy.cpp:480
void trim(std::string &s)
rip off leading and trailing white spaces
Definition: stringy.cpp:37
static void setSpacePolicy(bool allowSpaces=false)
set policy for spaces in file names
Definition: stringy.cpp:211
int split(csr text, std::vector< std::string > &result)
split a string into sub-strings at spaces
Definition: stringy.cpp:53
static bool check(const std::string &path)
checks for valid string
Definition: stringy.cpp:220