File: ticc_string.1

package info (click to toggle)
ticcutils 0.36-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,724 kB
  • sloc: cpp: 24,704; ansic: 636; makefile: 45; sh: 33
file content (266 lines) | stat: -rw-r--r-- 4,623 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
.TH ticc_string 1 "2015 November 26"

.SH NAME
ticc_string - A collection of C++ string manipulating utilities.

.SH SYNOPSIS
.B #include "ticcutils/StringOps.h"

.B using namespace TiCC;

.SH DESCRIPTION
Ticc String Utilities provides a few convenient functions for manipulating
C++ 'string' objects. These functions are widely used in the TiCC software
stack , but are of general use too.

.SH List of Functions

.B  string trim( const string& in, const string& filter= """ \et\er\en""" );
.RS
Remove from
.B in
all leading and trailing characters that are present in
.BR filter .

Embedded characters are retained.

.RE

.B  string trim_front( const string& in, const string& filter = """ \et\er\en""" );
.RS
Remove from
.B in
all leading characters that are present in
.BR filter .

Embedded characters are retained.
.RE

.B  string trim_back( const string& in, const string& filter = """ \et\er\en""" );
.RS
Remove from
.B in
all trailing characters that are present in
.BR filter .

Embedded characters are retained.
.RE

.B  void to_lower( string& s );
.RS
convert all characters in
.B s
to lowercase
.BR filter .
.RE

.B  void to_upper( string& s );
.RS
convert all characters in
.B s
to uppercase
.BR filter .
.RE

.B  string lowercase( const string& in );
.RS
Return a string that contains the lowercase of the characters in
.BR in .
.RE

.B  string uppercase( const string& in );
.RS
Return a string that contains the uppercase of the characters in
.BR in .
.RE

.B  size_t split_at( const string& s, vector<string>& vec, const string& sep, bool exact=false );
.RS
split the input string
.B s
at every position of the string
.B sep
and return the parts in the string vector
.BR vec .

consecutive occurrences of
.B sep
are all skipped, so
.B vec
will never contain empty strings, except when
.B exact
is set to true.

.B return value:
The size of
.BR vec .
.RE

.B size_t split_at_first_of( const string& s, vector<string>& vec, const string& filter, bool exact=false );
.RS
split the input string
.B s
at every occurrence of one of the characters from
.B filter
and return the parts in the string vector
.BR vec .

consecutive occurrences of
.B filter
characters are all skipped, so
.B vec
will never contain empty strings, except when
.B exact
is set to true.


.B return value:
The size of
.BR vec .
.RE

.B  inline size_t split( const string& s, vector<string>& vec, bool exact=false
.B    return split_at_first_of( s, vec, """ \et\er\en""" );
.B  }
.RS
split the input string
.B s
at every occurrence of a whitespace character, and return the parts in the string vector
.B vec

consecutive occurrences of
.B filter
characters are all skipped, so
.B vec
will never contain empty strings, except when
.B exact
is set to true.

.B return value:
The size of
.B vec
.RE

.B  bool match_front( const string& s, const string& f );
.RS
does the string
.B s
start with the string
.B f
?
.RE

.B  bool match_back( const string& s, const string& b );
.RS
does the string
.B s
end with the string
.B b
?
.RE

.B template< typename T > T stringTo( const std::string& s )
.RS
convert the string
.B s
into a value of type
.B T

Might throw when the conversion fails.
.RE

.B template< typename T > bool stringTo( const std::string& s, T& result )
.RS
convert the string
.B s
into a
.B result
value of type
.B T
return
.B false
when the conversion fails, otherwise returns
.B true
.RE

.B template<> bool stringTo( const std::string& s )
.RS
convert the string
.B s
into a value of type
.B bool

The string values:
.B YES
,
.B TRUE
,
.B 1
yield
.B true
(case insensitive)
The string values:
.B NO
,
.B FALSE
,
.B 0
yield
.B false
(case insensitive)

Will throw when conversion fails.
.RE

.B template< typename T > string toString ( const T& obj );
.RS
convert the
.B obj
of type
.B T
to a string. It uses the
.B <<
output operator for
.B obj
so it will fail if that operator is unavailable
.RE

.B string basename( const string& f );
.RS
returns the basename for filename
.BR f.
The basename is defined as the string after the last
.B /
in
.BR f.
If there is no
.B /
present, it will return the input string
.BR f .
.RE

.B string dirname( const string& f );
.RS
returns the pathname for filename
.B f.
The pathname is defined as the string before the last
.B /
in
.BR f.
If there is no
.B /
present, it will return
.BR ".".
.RE

.B  string format_nonascii( const string& s );
.RS
given a string
.B s
with possibly unprintable (non-ascii) characters, produce a string where these
are replaced by hexadecimal representations.
Useful for debugging Unicode stuff.
.RE

.SH AUTHORS
Ko van der Sloot lamasoftware@science.ru.nl