@@ -274,7 +274,7 @@ namespace fossil {
274
274
275
275
class CString {
276
276
private:
277
- std::string _str;
277
+ cstring _str;
278
278
279
279
public:
280
280
/* *
@@ -290,7 +290,7 @@ namespace fossil {
290
290
* Destructor to free the memory allocated for the cstring.
291
291
*/
292
292
~CString () {
293
- fossil_io_cstring_free (const_cast < char *>( _str. c_str ()) );
293
+ fossil_io_cstring_free (_str);
294
294
}
295
295
296
296
/* *
@@ -330,7 +330,7 @@ namespace fossil {
330
330
* @return The length of the cstring.
331
331
*/
332
332
size_t length () const {
333
- return fossil_io_cstring_length (_str. c_str () );
333
+ return fossil_io_cstring_length (_str);
334
334
}
335
335
336
336
/* *
@@ -340,14 +340,14 @@ namespace fossil {
340
340
* @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.
341
341
*/
342
342
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 ());
344
344
}
345
345
346
346
/* *
347
347
* Trims whitespace from the beginning and end of the cstring.
348
348
*/
349
349
void trim () {
350
- fossil_io_cstring_trim (const_cast < char *>( _str. c_str ()) );
350
+ fossil_io_cstring_trim (_str);
351
351
}
352
352
353
353
/* *
@@ -358,7 +358,7 @@ namespace fossil {
358
358
* @return An array of cstrings resulting from the split operation.
359
359
*/
360
360
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);
362
362
std::vector<std::string> vec;
363
363
for (size_t i = 0 ; i < *count; i++) {
364
364
vec.push_back (result[i]);
@@ -374,7 +374,7 @@ namespace fossil {
374
374
* @return A new CString with the replacements made.
375
375
*/
376
376
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 ()));
378
378
}
379
379
380
380
/* *
@@ -383,7 +383,7 @@ namespace fossil {
383
383
* @return The cstring with all characters converted to uppercase.
384
384
*/
385
385
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));
387
387
}
388
388
389
389
/* *
@@ -392,7 +392,7 @@ namespace fossil {
392
392
* @return The cstring with all characters converted to lowercase.
393
393
*/
394
394
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));
396
396
}
397
397
398
398
/* *
@@ -402,7 +402,7 @@ namespace fossil {
402
402
* @return True if the cstring starts with the prefix, false otherwise.
403
403
*/
404
404
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 ());
406
406
}
407
407
408
408
/* *
@@ -412,7 +412,7 @@ namespace fossil {
412
412
* @return True if the cstring ends with the suffix, false otherwise.
413
413
*/
414
414
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 ());
416
416
}
417
417
418
418
/* *
@@ -423,7 +423,7 @@ namespace fossil {
423
423
* @return A new CString that is the specified substring of the original cstring.
424
424
*/
425
425
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));
427
427
}
428
428
429
429
/* *
@@ -432,7 +432,7 @@ namespace fossil {
432
432
* @return A new CString that is the reverse of the cstring.
433
433
*/
434
434
CString reverse () const {
435
- return CString (fossil_io_cstring_reverse (const_cast < char *>( _str. c_str ()) ));
435
+ return CString (fossil_io_cstring_reverse (_str));
436
436
}
437
437
438
438
/* *
@@ -442,7 +442,7 @@ namespace fossil {
442
442
* @return True if the cstring contains the substring, false otherwise.
443
443
*/
444
444
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 ());
446
446
}
447
447
448
448
/* *
@@ -452,7 +452,7 @@ namespace fossil {
452
452
* @return A new CString that is the original cstring repeated the specified number of times.
453
453
*/
454
454
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));
456
456
}
457
457
458
458
/* *
@@ -462,7 +462,7 @@ namespace fossil {
462
462
* @return A new CString that is the original cstring with the specified character stripped from the beginning and end.
463
463
*/
464
464
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));
466
466
}
467
467
468
468
/* *
@@ -472,7 +472,7 @@ namespace fossil {
472
472
* @return The number of occurrences of the substring within the cstring.
473
473
*/
474
474
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 ());
476
476
}
477
477
478
478
/* *
@@ -483,7 +483,7 @@ namespace fossil {
483
483
* @return A new CString that is the original cstring padded on the left side.
484
484
*/
485
485
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));
487
487
}
488
488
489
489
/* *
@@ -494,15 +494,15 @@ namespace fossil {
494
494
* @return A new CString that is the original cstring padded on the right side.
495
495
*/
496
496
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));
498
498
}
499
499
500
500
/* *
501
501
* Returns the underlying cstring.
502
502
*
503
503
* @return The underlying cstring.
504
504
*/
505
- const std::string& str () const {
505
+ cstring str () const {
506
506
return _str;
507
507
}
508
508
};
0 commit comments