Skip to content

Commit db8b3d1

Browse files
committed
Documentation updated.
1 parent 6555bd3 commit db8b3d1

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ with existing libraries, so decided to make the right one, once and forever.
1313
* Light-weight references to strings: cheap to create, copy, or pass by value;
1414
* Support for copy and move semantics, although not enforceable by the C language;
1515
* String composition functions writing to memory, file descriptors, or file streams;
16+
* Can be compiled using `gcc` or `clang`, and linked with `libc` or `musl`.
1617

1718
## Installation
1819
Just clone the project and copy (or symlink) the files `str.h` and `str.c` into your project,
@@ -57,20 +58,20 @@ _**Disclaimer:** This is the good old C language, not C++ or Rust, so nothing ca
5758
on the language level, and certain discipline is required to make sure there is no corrupt
5859
or leaked memory resulting from using this library._
5960

60-
A string is represented by the type `str` that maintains a pointer to some memory containing
61-
the actual string. Objects of type `str` are small enough (a struct of a `const char*` and a `size_t`)
62-
to be cheap to create, copy (pass by value), and move. The `str` structure should be treated
63-
as opaque (i.e., do not attempt to directly access or modify the fields in this structure).
64-
The strings are assumed to be immutable, like those in Java or Go, but only by means of `const char*`
65-
pointers, so it is actually possible to write to such a string, although the required type
66-
cast to `char*` offers at least some (mostly psychological) protection from modifying a string
67-
by mistake.
61+
A string is represented by the type `str` that maintains a pointer to some memory containing the
62+
actual string, and the length of the string. Objects of type `str` are small enough (a struct
63+
of a `const char*` and a `size_t`) to be cheap to create, copy (pass by value), and move. The
64+
`str` structure should be treated as opaque (i.e., do not attempt to directly access or modify
65+
the fields in this structure). The strings are assumed to be immutable, like those in Java or
66+
Go, but only by means of `const char*` pointers, so it is actually possible to modify such a
67+
string, although the required type cast to `char*` offers at least some (mostly psychological)
68+
protection from changing the string by mistake.
6869

6970
This library focusses only on handling strings, not gradually composing them like
7071
[StringBuffer](https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html)
7172
class in Java.
7273

73-
All string objects must be initialised. Uninitialised objects will cause
74+
All string objects must be initialised before use. Uninitialised objects will cause
7475
undefined behaviour. Use the provided constructors, or `str_null` for empty strings.
7576

7677
There are two kinds of `str` objects: those actually owning the memory they point to, and
@@ -98,7 +99,7 @@ can also be declared as `str_auto` (or `const str_auto`) for automatic cleanup w
9899
goes out of scope.
99100
* An owning object can be moved to another location by using `str_move` function. The
100101
function resets its source object to an empty string.
101-
* An owning object can be passed over to another location by using `str_pass` function. The
102+
* Object ownership can be passed over to another object by using `str_pass` function. The
102103
function sets its source to a non-owning reference to the original string.
103104

104105
It is technically possible to create a reference to a string that is not
@@ -111,7 +112,7 @@ A string object can be constructed form any C string, string literal, or a range
111112
The provided constructors are computationally cheap to apply. Depending on the constructor,
112113
the new object can either own the actual string it refers to, or be a non-owning reference.
113114
Constructors themselves do not allocate any memory. Importantly, constructors are the only
114-
functions in this library that return a string object, while others assign their results
115+
functions in this library that return a string object, while others only assign their results
115116
through a pointer to a pre-existing string. This makes constructors suitable for initialisation
116117
of new string objects. In all other situations one should combine construction with assignment,
117118
for example:<br>
@@ -167,11 +168,11 @@ str_join(&s, str_lit(", "),
167168
str_lit("there"),
168169
str_lit("and everywhere"));
169170

170-
// create a new string concatenating "s" and a literal; the function does not modify its
171-
// destination object "s" before the result is computed, also freeing the destination
171+
// create a new string concatenating "s" and a literal; the function only modifies its
172+
// destination object "s" after the result is computed, also freeing the destination
172173
// before the assignment, so it is safe to use "s" as both a parameter and a destination.
173174
// note: we pass a copy of the owning object "s" as the second parameter, and here it is
174-
// safe to do so because this particular function does not store or release its arguments.
175+
// safe to do so because this particular function does not modify its arguments.
175176
str_cat(&s, s, str_lit("..."));
176177

177178
// check that we have got the expected result

0 commit comments

Comments
 (0)