|
Lines 12-18
Link Here
|
| 12 |
void kStringInsertStringBehindTags ( std::string & str, const std::string & insertString, |
12 |
void kStringInsertStringBehindTags ( std::string & str, const std::string & insertString, |
| 13 |
const std::string & tag ) |
13 |
const std::string & tag ) |
| 14 |
{ |
14 |
{ |
| 15 |
unsigned int oldPos = 0; |
15 |
std::string::size_type oldPos = 0; |
| 16 |
while ((oldPos = str.find(tag, oldPos)) != std::string::npos) |
16 |
while ((oldPos = str.find(tag, oldPos)) != std::string::npos) |
| 17 |
{ |
17 |
{ |
| 18 |
oldPos += tag.size(); |
18 |
oldPos += tag.size(); |
|
Lines 34-40
std::vector<std::string> kStringGetCompo
Link Here
|
| 34 |
std::vector<std::string> components; |
34 |
std::vector<std::string> components; |
| 35 |
|
35 |
|
| 36 |
unsigned int dividerLength = divider.size(); |
36 |
unsigned int dividerLength = divider.size(); |
| 37 |
unsigned int oldpos = 0, pos; |
37 |
std::string::size_type oldpos = 0, pos; |
| 38 |
|
38 |
|
| 39 |
while ((pos = str.find(divider, oldpos)) != std::string::npos) |
39 |
while ((pos = str.find(divider, oldpos)) != std::string::npos) |
| 40 |
{ |
40 |
{ |
|
Lines 49-55
std::vector<std::string> kStringGetCompo
Link Here
|
| 49 |
// -------------------------------------------------------------------------------------------------------- |
49 |
// -------------------------------------------------------------------------------------------------------- |
| 50 |
void kStringReplace ( std::string & str, const std::string & toReplace, const std::string & replacement ) |
50 |
void kStringReplace ( std::string & str, const std::string & toReplace, const std::string & replacement ) |
| 51 |
{ |
51 |
{ |
| 52 |
unsigned int pos = 0, chars = toReplace.size(); |
52 |
std::string::size_type pos = 0; |
|
|
53 |
unsigned int chars = toReplace.size(); |
| 53 |
while ((pos = str.find(toReplace, pos)) != std::string::npos) |
54 |
while ((pos = str.find(toReplace, pos)) != std::string::npos) |
| 54 |
{ |
55 |
{ |
| 55 |
str.replace(pos, chars, replacement); |
56 |
str.replace(pos, chars, replacement); |
|
Lines 59-69
void kStringReplace ( std::string & str,
Link Here
|
| 59 |
// -------------------------------------------------------------------------------------------------------- |
60 |
// -------------------------------------------------------------------------------------------------------- |
| 60 |
void kStringReplaceTabs ( std::string & str, unsigned int tabWidth ) |
61 |
void kStringReplaceTabs ( std::string & str, unsigned int tabWidth ) |
| 61 |
{ |
62 |
{ |
| 62 |
unsigned int tabPos; |
63 |
std::string::size_type tabPos; |
| 63 |
while ((tabPos = str.find('\t')) != std::string::npos) |
64 |
while ((tabPos = str.find('\t')) != std::string::npos) |
| 64 |
{ |
65 |
{ |
| 65 |
unsigned int lastNewlinePos = str.rfind('\n', tabPos-1); |
66 |
std::string::size_type lastNewlinePos = str.rfind('\n', tabPos-1); |
| 66 |
unsigned int relPos = (lastNewlinePos == std::string::npos) ? tabPos : tabPos - lastNewlinePos; |
67 |
std::string::size_type relPos = (lastNewlinePos == std::string::npos) ? tabPos : tabPos - lastNewlinePos; |
| 67 |
str.replace(tabPos, 1, std::string(tabWidth-(relPos % tabWidth), ' ')); |
68 |
str.replace(tabPos, 1, std::string(tabWidth-(relPos % tabWidth), ' ')); |
| 68 |
} |
69 |
} |
| 69 |
} |
70 |
} |
|
Lines 111-119
unsigned int kStringCountChars ( const s
Link Here
|
| 111 |
} |
112 |
} |
| 112 |
|
113 |
|
| 113 |
// -------------------------------------------------------------------------------------------------------- |
114 |
// -------------------------------------------------------------------------------------------------------- |
| 114 |
unsigned int kStringNthCharPos ( const std::string & str, unsigned int n, char c ) |
115 |
std::string::size_type kStringNthCharPos ( const std::string & str, unsigned int n, char c ) |
| 115 |
{ |
116 |
{ |
| 116 |
unsigned int loc = n, oloc = 0; |
117 |
std::string::size_type loc = n, oloc = 0; |
| 117 |
while (n > 0 && (loc = str.find(c, oloc)) != std::string::npos) |
118 |
while (n > 0 && (loc = str.find(c, oloc)) != std::string::npos) |
| 118 |
{ |
119 |
{ |
| 119 |
n--; |
120 |
n--; |
|
Lines 129-135
void kStringCropRows ( std::string & str
Link Here
|
| 129 |
unsigned int lines = kStringRows(str); |
130 |
unsigned int lines = kStringRows(str); |
| 130 |
if (lines > rows) |
131 |
if (lines > rows) |
| 131 |
{ |
132 |
{ |
| 132 |
unsigned int loc = kStringNthCharPos(str, (lines-rows), '\n'); |
133 |
std::string::size_type loc = kStringNthCharPos(str, (lines-rows), '\n'); |
| 133 |
str.erase(0, loc+1); |
134 |
str.erase(0, loc+1); |
| 134 |
} |
135 |
} |
| 135 |
} |
136 |
} |
|
Lines 137-143
void kStringCropRows ( std::string & str
Link Here
|
| 137 |
// -------------------------------------------------------------------------------------------------------- |
138 |
// -------------------------------------------------------------------------------------------------------- |
| 138 |
void kStringCropCols ( std::string & str, unsigned int columns ) |
139 |
void kStringCropCols ( std::string & str, unsigned int columns ) |
| 139 |
{ |
140 |
{ |
| 140 |
unsigned int oloc = 0, nloc = 0; |
141 |
std::string::size_type oloc = 0, nloc = 0; |
| 141 |
while ((nloc = str.find('\n', oloc)) != std::string::npos) |
142 |
while ((nloc = str.find('\n', oloc)) != std::string::npos) |
| 142 |
{ |
143 |
{ |
| 143 |
if ((nloc - oloc) > columns) |
144 |
if ((nloc - oloc) > columns) |
|
Lines 159-168
void kStringCropCols ( std::string & str
Link Here
|
| 159 |
unsigned int kStringCols ( const std::string & str ) |
160 |
unsigned int kStringCols ( const std::string & str ) |
| 160 |
{ |
161 |
{ |
| 161 |
if (str.size() == 0) return 0; |
162 |
if (str.size() == 0) return 0; |
| 162 |
int oloc = 0, nloc; |
163 |
std::string::size_type oloc = 0, nloc; |
| 163 |
std::string substring; |
164 |
std::string substring; |
| 164 |
int maxlength = 0, length; |
165 |
int maxlength = 0, length; |
| 165 |
while ((nloc = str.find('\n', oloc)) != (int)std::string::npos) |
166 |
while ((nloc = str.find('\n', oloc)) != std::string::npos) |
| 166 |
{ |
167 |
{ |
| 167 |
substring = str.substr(oloc, nloc - oloc); |
168 |
substring = str.substr(oloc, nloc - oloc); |
| 168 |
length = substring.size(); |
169 |
length = substring.size(); |
|
Lines 180-186
unsigned int kStringCols ( const std::st
Link Here
|
| 180 |
unsigned int kStringRows ( const std::string & str ) |
181 |
unsigned int kStringRows ( const std::string & str ) |
| 181 |
{ |
182 |
{ |
| 182 |
if (str.size() == 0) return 1; |
183 |
if (str.size() == 0) return 1; |
| 183 |
unsigned int loc = 0, lines = 0; |
184 |
std::string::size_type loc = 0; |
|
|
185 |
unsigned int lines = 0; |
| 184 |
while ((loc = str.find('\n', loc)) != std::string::npos) { lines++; loc++; } |
186 |
while ((loc = str.find('\n', loc)) != std::string::npos) { lines++; loc++; } |
| 185 |
if (str[str.size()-1] == '\n') return lines; |
187 |
if (str[str.size()-1] == '\n') return lines; |
| 186 |
return lines+1; |
188 |
return lines+1; |
|
Lines 203-210
std::string kStringPrintf ( const std::s
Link Here
|
| 203 |
{ |
205 |
{ |
| 204 |
static char str[256]; |
206 |
static char str[256]; |
| 205 |
std::string format(fmt), subformat, text; |
207 |
std::string format(fmt), subformat, text; |
| 206 |
unsigned int oloc = 0; |
208 |
std::string::size_type oloc = 0; |
| 207 |
unsigned int nloc = 0; |
209 |
std::string::size_type nloc = 0; |
| 208 |
|
210 |
|
| 209 |
kStringReplaceTabs(format); |
211 |
kStringReplaceTabs(format); |
| 210 |
|
212 |
|
|
Lines 259-265
std::string kStringPrintf ( const char *
Link Here
|
| 259 |
// -------------------------------------------------------------------------------------------------------- |
261 |
// -------------------------------------------------------------------------------------------------------- |
| 260 |
bool kStringHasSuffix ( const std::string & str, const std::string & suffix ) |
262 |
bool kStringHasSuffix ( const std::string & str, const std::string & suffix ) |
| 261 |
{ |
263 |
{ |
| 262 |
unsigned int result = str.rfind(suffix); |
264 |
std::string::size_type result = str.rfind(suffix); |
| 263 |
if (result == std::string::npos) return false; |
265 |
if (result == std::string::npos) return false; |
| 264 |
return (result == str.size()-suffix.size()); |
266 |
return (result == str.size()-suffix.size()); |
| 265 |
} |
267 |
} |