]> Savannah Git Hosting - gnulib.git/commitdiff
doc: Recommend string descriptors for application area like parsers.
authorBruno Haible <bruno@clisp.org>
Sat, 12 Oct 2024 07:23:24 +0000 (09:23 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 12 Oct 2024 07:23:24 +0000 (09:23 +0200)
* doc/string-desc.texi (Handling strings with NUL characters): Mention
the ease of taking a substring.

ChangeLog
doc/string-desc.texi

index e56b67a268bcfeb96ba3e219fe449d466391a7a9..ce225aa68e91680701d8e0736631b9311a294cec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-10-12  Bruno Haible  <bruno@clisp.org>
+
+       doc: Recommend string descriptors for application area like parsers.
+       * doc/string-desc.texi (Handling strings with NUL characters): Mention
+       the ease of taking a substring.
+
 2024-10-11  Bruno Haible  <bruno@clisp.org>
 
        bison-i18n: Add support for mingw builds on Cygwin hosts.
index 1d252164e622945d217e469e44831a02be415abe..602ec162b0fe6fd9ed403240a5bf5a440125d7c5 100644 (file)
@@ -21,7 +21,16 @@ handle strings that contain NUL characters: such strings will appear
 shorter than they were meant to be.  In most application areas, this is
 not a problem, and the @code{char *} type is well usable.
 
-In areas where strings with embedded NUL characters need to be handled,
+A second problem of this string representation is that
+taking a substring is not cheap:
+it either requires a memory allocation
+or a destructive modification of the string.
+The former has a runtime cost;
+the latter complicates the logic of the program.
+This matters for application areas that analyze text, such as parsers.
+
+In areas where strings with embedded NUL characters need to be handled
+or where taking substrings is a recurrent operation,
 the common approach is to use a @code{char *ptr} pointer variable
 together with a @code{size_t nbytes} variable (or an @code{idx_t nbytes}
 variable, if you want to avoid problems due to integer overflow).  This