docs/Writerside/topics/string.h.md

changeset 1332
02946dc73e6a
parent 1318
12fa1d37fe48
equal deleted inserted replaced
1331:caa66055b025 1332:02946dc73e6a
7 As a rule of thumb, you _should not_ pass a character array of a UCX string structure to another API without explicitly 7 As a rule of thumb, you _should not_ pass a character array of a UCX string structure to another API without explicitly
8 ensuring that the string is zero-terminated. 8 ensuring that the string is zero-terminated.
9 9
10 ## Basics 10 ## Basics
11 11
12 > To make documentation simpler, we introduce the pseudo-type `AnyStr` with the meaning that 12 > To simplify documentation, we introduce the pseudo-type `AnyStr` with the meaning that
13 > both `cxstring` and `cxmutstr` are accepted for that argument. 13 > both `cxstring` and `cxmutstr` are accepted for that argument.
14 > The implementation is actually hidden behind a macro which uses `cx_strcast()` to guarantee compatibility. 14 > The implementation is actually hidden behind a macro which uses `cx_strcast()` to guarantee compatibility.
15 {style="note"} 15 {style="note"}
16 16
17 ```C 17 ```C
31 31
32 cxmutstr cx_mutstr(char *cstring); 32 cxmutstr cx_mutstr(char *cstring);
33 33
34 cxmutstr cx_mutstrn(char *cstring, size_t length); 34 cxmutstr cx_mutstrn(char *cstring, size_t length);
35 35
36 cxstring cx_strcast(AnyStr str);
37
38 cxmutstr cx_strdup(AnyStr string); 36 cxmutstr cx_strdup(AnyStr string);
39 37
40 cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string); 38 cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string);
41 39
42 int cx_strcpy(cxmutstr *dest, cxstring source); 40 int cx_strcpy(cxmutstr *dest, cxstring source);
49 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); 47 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str);
50 48
51 49
52 #define CX_SFMT(s) (int) (s).length, (s).ptr 50 #define CX_SFMT(s) (int) (s).length, (s).ptr
53 #define CX_PRIstr ".*s" 51 #define CX_PRIstr ".*s"
52 #define cx_strcast(s) // converts any string to cxstring
54 ``` 53 ```
55 54
56 The functions `cx_str()` and `cx_mutstr()` create a UCX string from a `const char*` or a `char*` 55 The functions `cx_str()` and `cx_mutstr()` create a UCX string from a `const char*` or a `char*`
57 and compute the length with a call to stdlib `strlen()`. 56 and compute the length with a call to stdlib `strlen()`.
58 In case you already know the length, or the string is not zero-terminated, you can use `cx_strn()` or `cx_mutstrn()`. 57 In case you already know the length, or the string is not zero-terminated, you can use `cx_strn()` or `cx_mutstrn()`.

mercurial