Changeset 973 for cpp/frams/util/sstringutils.cpp
- Timestamp:
- 07/03/20 00:37:13 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/sstringutils.cpp
r904 r973 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 79 79 else 80 80 { 81 if (tmp.len () == 0) return 0; // nothing was changed!81 if (tmp.length() == 0) return 0; // nothing was changed! 82 82 tmp += x; 83 83 target = tmp; … … 112 112 else 113 113 { 114 if (tmp.len () == 0) return 0; // nothing was changed!114 if (tmp.length() == 0) return 0; // nothing was changed! 115 115 tmp += x; 116 116 target = tmp; … … 139 139 bool changed = 0; 140 140 SString tmp; 141 tmp. memoryHint(target.len());141 tmp.reserve(target.length()); 142 142 while (*x) 143 143 { … … 160 160 { 161 161 SString out; 162 if (in.len () > maxlen)163 out = in.substr(0, maxlen / 2) + "..." + in.substr(in.len () - maxlen + maxlen / 2);162 if (in.length() > maxlen) 163 out = in.substr(0, maxlen / 2) + "..." + in.substr(in.length() - maxlen + maxlen / 2); 164 164 else 165 165 { … … 169 169 out = before + out + after; 170 170 if (show_length) 171 out += SString::sprintf(" (length %d)", in.len ());171 out += SString::sprintf(" (length %d)", in.length()); 172 172 return out; 173 173 } … … 208 208 else 209 209 { 210 if (tmp.len () == 0) return 0; // nothing was changed!210 if (tmp.length() == 0) return 0; // nothing was changed! 211 211 tmp += x; 212 212 target = tmp; … … 223 223 { 224 224 n = strchr(t + pos, ','); 225 if ((!strncmp(t + pos, name.c_str(), name.len ())) && (t[pos + name.len()] == '='))226 { 227 if (n) end = n - t; else end = txt.len ();225 if ((!strncmp(t + pos, name.c_str(), name.length())) && (t[pos + name.length()] == '=')) 226 { 227 if (n) end = n - t; else end = txt.length(); 228 228 return pos; 229 229 } … … 238 238 p = strFindField(txt, name, e); 239 239 if (p < 0) return SString(); 240 p += name.len () + 1;240 p += name.length() + 1; 241 241 return SString(txt.substr(p, e - p)); 242 242 } … … 248 248 if (p < 0) 249 249 { 250 if (!value.len ()) return;251 char *t = txt.directAppend(1 + name.len () + value.len());250 if (!value.length()) return; 251 char *t = txt.directAppend(1 + name.length() + value.length()); 252 252 char *b = t; 253 if (txt.len ()) *(t++) = ',';254 strcpy(t, name.c_str()); t += name.len ();253 if (txt.length()) *(t++) = ','; 254 strcpy(t, name.c_str()); t += name.length(); 255 255 *(t++) = '='; 256 strcpy(t, value.c_str()); t += value.len ();256 strcpy(t, value.c_str()); t += value.length(); 257 257 txt.endAppend(t - b); 258 258 } 259 259 else 260 260 { 261 if (!value.len ())262 { 263 if (p > 0) p--; else if (e < txt.len ()) e++;261 if (!value.length()) 262 { 263 if (p > 0) p--; else if (e < txt.length()) e++; 264 264 char *t = txt.directWrite(0); 265 memmove(t + p, t + e, txt.len () - e);266 txt.endWrite(txt.len () + value.len() - (e - p));267 } 268 else 269 { 270 p += name.len () + 1;271 char *t = txt.directWrite(txt.len () + value.len() - (e - p));272 memmove(t + p + value.len (), t + e, txt.len() - e);273 memmove(t + p, value.c_str(), value.len ());274 txt.endWrite(txt.len () + value.len() - (e - p));265 memmove(t + p, t + e, txt.length() - e); 266 txt.endWrite(txt.length() + value.length() - (e - p)); 267 } 268 else 269 { 270 p += name.length() + 1; 271 char *t = txt.directWrite(txt.length() + value.length() - (e - p)); 272 memmove(t + p + value.length(), t + e, txt.length() - e); 273 memmove(t + p, value.c_str(), value.length()); 274 txt.endWrite(txt.length() + value.length() - (e - p)); 275 275 } 276 276 } … … 280 280 { 281 281 const unsigned char*b = (const unsigned char*)s.c_str(); 282 const unsigned char*e = b + s.len ();282 const unsigned char*e = b + s.length(); 283 283 while ((b < e) && (*b <= ' ')) b++; 284 284 while ((b < e) && (e[-1] <= ' ')) e--; 285 if ((e - b) == s.len ()) return s;285 if ((e - b) == s.length()) return s; 286 286 SString newstring; 287 287 char* t = newstring.directWrite(e - b); … … 291 291 } 292 292 293 SString concatPath(const SString& in1, const SString& in2)294 { 295 SString out =in1;296 if (out.len ()>0 && out[out.len()-1]!=PATH_SEPARATOR_CHAR)297 out +=PATH_SEPARATOR_CHAR;298 out +=in2;293 SString concatPath(const SString& in1, const SString& in2) 294 { 295 SString out = in1; 296 if (out.length() > 0 && out[out.length() - 1] != PATH_SEPARATOR_CHAR) 297 out += PATH_SEPARATOR_CHAR; 298 out += in2; 299 299 return out; 300 300 } … … 318 318 bool matchWildcard(const SString& word, const SString& pattern) 319 319 { 320 if (pattern.len () == 0)321 return word.len () == 0;320 if (pattern.length() == 0) 321 return word.length() == 0; 322 322 int aster = pattern.indexOf('*'); 323 323 if (aster >= 0) … … 325 325 SString before = pattern.substr(0, aster); 326 326 SString after = pattern.substr(aster + 1); 327 if (!word.len ()) return false;328 if (before.len ()) if (!word.startsWith(before.c_str())) return false;329 if (after.len ())330 if ((word.len () < after.len())331 || (strcmp(after.c_str(), word.c_str() + word.len () - after.len())))327 if (!word.length()) return false; 328 if (before.length()) if (!word.startsWith(before.c_str())) return false; 329 if (after.length()) 330 if ((word.length() < after.length()) 331 || (strcmp(after.c_str(), word.c_str() + word.length() - after.length()))) 332 332 return false; 333 333 return true; … … 339 339 bool matchWildcardList(const SString& word, const SString& patterns) 340 340 { 341 if (patterns.len () == 0)342 return word.len () == 0;341 if (patterns.length() == 0) 342 return word.length() == 0; 343 343 int pos = 0; 344 344 SString pattern;
Note: See TracChangeset
for help on using the changeset viewer.