Skip to content

Commit 3622f52

Browse files
switch stl string for cstring type
1 parent 613328a commit 3622f52

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

code/logic/fossil/io/cstring.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace fossil {
274274

275275
class CString {
276276
private:
277-
std::string _str;
277+
cstring _str;
278278

279279
public:
280280
/**
@@ -290,7 +290,7 @@ namespace fossil {
290290
* Destructor to free the memory allocated for the cstring.
291291
*/
292292
~CString() {
293-
fossil_io_cstring_free(const_cast<char*>(_str.c_str()));
293+
fossil_io_cstring_free(_str);
294294
}
295295

296296
/**
@@ -330,7 +330,7 @@ namespace fossil {
330330
* @return The length of the cstring.
331331
*/
332332
size_t length() const {
333-
return fossil_io_cstring_length(_str.c_str());
333+
return fossil_io_cstring_length(_str);
334334
}
335335

336336
/**
@@ -340,14 +340,14 @@ namespace fossil {
340340
* @return An integer less than, equal to, or greater than zero if this cstring is found, respectively, to be less than, to match, or be greater than the other cstring.
341341
*/
342342
int compare(const std::string &other) const {
343-
return fossil_io_cstring_compare(_str.c_str(), other.c_str());
343+
return fossil_io_cstring_compare(_str, other.c_str());
344344
}
345345

346346
/**
347347
* Trims whitespace from the beginning and end of the cstring.
348348
*/
349349
void trim() {
350-
fossil_io_cstring_trim(const_cast<char*>(_str.c_str()));
350+
fossil_io_cstring_trim(_str);
351351
}
352352

353353
/**
@@ -358,7 +358,7 @@ namespace fossil {
358358
* @return An array of cstrings resulting from the split operation.
359359
*/
360360
std::vector<std::string> split(char delimiter, size_t *count) const {
361-
cstring *result = fossil_io_cstring_split(_str.c_str(), delimiter, count);
361+
cstring *result = fossil_io_cstring_split(_str, delimiter, count);
362362
std::vector<std::string> vec;
363363
for (size_t i = 0; i < *count; i++) {
364364
vec.push_back(result[i]);
@@ -374,7 +374,7 @@ namespace fossil {
374374
* @return A new CString with the replacements made.
375375
*/
376376
CString replace(const std::string &old, const std::string &new_str) const {
377-
return CString(fossil_io_cstring_replace(_str.c_str(), old.c_str(), new_str.c_str()));
377+
return CString(fossil_io_cstring_replace(_str, old.c_str(), new_str.c_str()));
378378
}
379379

380380
/**
@@ -383,7 +383,7 @@ namespace fossil {
383383
* @return The cstring with all characters converted to uppercase.
384384
*/
385385
CString to_upper() const {
386-
return CString(fossil_io_cstring_to_upper(const_cast<char*>(_str.c_str())));
386+
return CString(fossil_io_cstring_to_upper(_str));
387387
}
388388

389389
/**
@@ -392,7 +392,7 @@ namespace fossil {
392392
* @return The cstring with all characters converted to lowercase.
393393
*/
394394
CString to_lower() const {
395-
return CString(fossil_io_cstring_to_lower(const_cast<char*>(_str.c_str())));
395+
return CString(fossil_io_cstring_to_lower(_str));
396396
}
397397

398398
/**
@@ -402,7 +402,7 @@ namespace fossil {
402402
* @return True if the cstring starts with the prefix, false otherwise.
403403
*/
404404
bool starts_with(const std::string &prefix) const {
405-
return fossil_io_cstring_starts_with(_str.c_str(), prefix.c_str());
405+
return fossil_io_cstring_starts_with(_str, prefix.c_str());
406406
}
407407

408408
/**
@@ -412,7 +412,7 @@ namespace fossil {
412412
* @return True if the cstring ends with the suffix, false otherwise.
413413
*/
414414
bool ends_with(const std::string &suffix) const {
415-
return fossil_io_cstring_ends_with(_str.c_str(), suffix.c_str());
415+
return fossil_io_cstring_ends_with(_str, suffix.c_str());
416416
}
417417

418418
/**
@@ -423,7 +423,7 @@ namespace fossil {
423423
* @return A new CString that is the specified substring of the original cstring.
424424
*/
425425
CString substring(size_t start, size_t length) const {
426-
return CString(fossil_io_cstring_substring(_str.c_str(), start, length));
426+
return CString(fossil_io_cstring_substring(_str, start, length));
427427
}
428428

429429
/**
@@ -432,7 +432,7 @@ namespace fossil {
432432
* @return A new CString that is the reverse of the cstring.
433433
*/
434434
CString reverse() const {
435-
return CString(fossil_io_cstring_reverse(const_cast<char*>(_str.c_str())));
435+
return CString(fossil_io_cstring_reverse(_str));
436436
}
437437

438438
/**
@@ -442,7 +442,7 @@ namespace fossil {
442442
* @return True if the cstring contains the substring, false otherwise.
443443
*/
444444
bool contains(const std::string &substr) const {
445-
return fossil_io_cstring_contains(_str.c_str(), substr.c_str());
445+
return fossil_io_cstring_contains(_str, substr.c_str());
446446
}
447447

448448
/**
@@ -452,7 +452,7 @@ namespace fossil {
452452
* @return A new CString that is the original cstring repeated the specified number of times.
453453
*/
454454
CString repeat(size_t count) const {
455-
return CString(fossil_io_cstring_repeat(_str.c_str(), count));
455+
return CString(fossil_io_cstring_repeat(_str, count));
456456
}
457457

458458
/**
@@ -462,7 +462,7 @@ namespace fossil {
462462
* @return A new CString that is the original cstring with the specified character stripped from the beginning and end.
463463
*/
464464
CString strip(char ch) const {
465-
return CString(fossil_io_cstring_strip(_str.c_str(), ch));
465+
return CString(fossil_io_cstring_strip(_str, ch));
466466
}
467467

468468
/**
@@ -472,7 +472,7 @@ namespace fossil {
472472
* @return The number of occurrences of the substring within the cstring.
473473
*/
474474
size_t count(const std::string &substr) const {
475-
return fossil_io_cstring_count(_str.c_str(), substr.c_str());
475+
return fossil_io_cstring_count(_str, substr.c_str());
476476
}
477477

478478
/**
@@ -483,7 +483,7 @@ namespace fossil {
483483
* @return A new CString that is the original cstring padded on the left side.
484484
*/
485485
CString pad_left(size_t total_length, char pad_char) const {
486-
return CString(fossil_io_cstring_pad_left(_str.c_str(), total_length, pad_char));
486+
return CString(fossil_io_cstring_pad_left(_str, total_length, pad_char));
487487
}
488488

489489
/**
@@ -494,15 +494,15 @@ namespace fossil {
494494
* @return A new CString that is the original cstring padded on the right side.
495495
*/
496496
CString pad_right(size_t total_length, char pad_char) const {
497-
return CString(fossil_io_cstring_pad_right(_str.c_str(), total_length, pad_char));
497+
return CString(fossil_io_cstring_pad_right(_str, total_length, pad_char));
498498
}
499499

500500
/**
501501
* Returns the underlying cstring.
502502
*
503503
* @return The underlying cstring.
504504
*/
505-
const std::string& str() const {
505+
cstring str() const {
506506
return _str;
507507
}
508508
};

0 commit comments

Comments
 (0)