587 You should not use the `S()` or `ST()` macro with string of unknown origin, |
587 You should not use the `S()` or `ST()` macro with string of unknown origin, |
588 since the `sizeof()` call might not coincide with the string length in those |
588 since the `sizeof()` call might not coincide with the string length in those |
589 cases. If you know what you are doing, it can save you some performance, |
589 cases. If you know what you are doing, it can save you some performance, |
590 because you do not need the `strlen()` call. |
590 because you do not need the `strlen()` call. |
591 |
591 |
|
592 ### Handling immutable strings |
|
593 |
|
594 *(Since: UCX 2.0)* |
|
595 |
|
596 For immutable strings (i.e. `const char*` strings), UCX provides the `scstr_t` |
|
597 type, which works exactly as the `sstr_t` type but with a pointer |
|
598 to `const char`. All UCX string functions come in two flavors: one that enforces |
|
599 the `scstr_t` type, and another that usually accepts both types and performs |
|
600 a conversion automatically, if necessary. |
|
601 |
|
602 There are some exceptions to this rule, as the return type may depend on the |
|
603 argument type. |
|
604 E.g. the `sstrchr()` function returns a substring starting at |
|
605 the first occurrence of the specified character. |
|
606 Since this substring points to the memory of the argument string, it does not |
|
607 accept `scstr_t` as input argument, because the return type would break the |
|
608 constness. |
|
609 |
|
610 |
592 ### Finding the position of a substring |
611 ### Finding the position of a substring |
593 |
612 |
594 The `sstrstr()` function gives you a new `sstr_t` object starting with the |
613 The `sstrstr()` function gives you a new `sstr_t` object starting with the |
595 requested substring. Thus determining the position comes down to a simple |
614 requested substring. Thus determining the position comes down to a simple |
596 subtraction. |
615 subtraction. |