docs/Writerside/topics/string.h.md

Thu, 23 Jan 2025 01:33:36 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 23 Jan 2025 01:33:36 +0100
branch
docs/3.1
changeset 1141
a06a2d27c043
child 1142
9437530176bc
permissions
-rw-r--r--

create new page structure

relates to #451

1141
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 # string.h
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 UCX strings come in two variants: immutable (`cxstring`) and mutable (`cxmutstr`).
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 The functions of UCX are designed to work with immutable strings by default but in situations where it is necessary,
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 the API also provides alternative functions that work directly with mutable strings.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 Functions that change a string in-place are, of course, only accepting mutable strings.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 When you are using UCX functions, or defining your own functions, you are sometimes facing the "problem",
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 that the function only accepts arguments of type `cxstring` but you only have a `cxmutstr` at hand.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 In this case you _should not_ introduce a wrapper function that accepts the `cxmutstr`,
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 but instead you should use the `cx_strcast()` function to cast the argument to the correct type.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 In general, UCX strings are **not** necessarily zero-terminated. If a function guarantees to return zero-terminated
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 string, it is explicitly mentioned in the documentation of the respective function.
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 As a rule of thumb, you _should not_ pass the strings of a UCX string structure to another API without explicitly
a06a2d27c043 create new page structure
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 ensuring that the string is zero-terminated.

mercurial