aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2022-06-05 11:28:10 +0300
committerEli Zaretskii2022-06-05 11:28:10 +0300
commit3ea9357d109e303fece9d49e1fdad8a2e42cc858 (patch)
tree841f64e8540a7a16995cbfa411b41b00c58fe2ca
parent1b8719835a200a2be17da226e82030f691caba80 (diff)
downloademacs-3ea9357d109e303fece9d49e1fdad8a2e42cc858.tar.gz
emacs-3ea9357d109e303fece9d49e1fdad8a2e42cc858.zip
Update documentation of 'aset' and 'store-substring'
* doc/lispref/strings.texi (Modifying Strings): Adjust to implementation changes: it is possible for the modified string to have fewer or more bytes than the original. Add recommendations regarding unibyte vs multibyte strings and characters. (Bug#55801)
-rw-r--r--doc/lispref/strings.texi32
1 files changed, 19 insertions, 13 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 742ab76244d..c9612e598a3 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -461,23 +461,29 @@ Remove the final newline, if any, from @var{string}.
461described in this section. @xref{Mutability}. 461described in this section. @xref{Mutability}.
462 462
463 The most basic way to alter the contents of an existing string is with 463 The most basic way to alter the contents of an existing string is with
464@code{aset} (@pxref{Array Functions}). @code{(aset @var{string} 464@code{aset} (@pxref{Array Functions}). @w{@code{(aset @var{string}
465@var{idx} @var{char})} stores @var{char} into @var{string} at index 465@var{idx} @var{char})}} stores @var{char} into @var{string} at character
466@var{idx}. Each character occupies one or more bytes, and if @var{char} 466index @var{idx}. It will automatically convert a pure-@acronym{ASCII}
467needs a different number of bytes from the character already present at 467@var{string} to a multibyte string (@pxref{Text Representations}) if
468that index, @code{aset} signals an error. 468needed, but we recommend to always make sure @var{string} is multibyte
469(e.g., by using @code{string-to-multibyte}, @pxref{Converting
470Representations}), if @var{char} is a non-@acronym{ASCII} character, not
471a raw byte.
469 472
470 A more powerful function is @code{store-substring}: 473 A more powerful function is @code{store-substring}:
471 474
472@defun store-substring string idx obj 475@defun store-substring string idx obj
473This function alters part of the contents of the string @var{string}, by 476This function alters part of the contents of the specified @var{string},
474storing @var{obj} starting at index @var{idx}. The argument @var{obj} 477by storing @var{obj} starting at character index @var{idx}. The
475may be either a character or a (smaller) string. 478argument @var{obj} may be either a character (in which case the function
476 479behaves exactly as @code{aset}) or a (smaller) string. If @var{obj}
477Since it is impossible to change the length of an existing string, it is 480is a multibyte string, we recommend to make sure @var{string} is also
478an error if @var{obj} doesn't fit within @var{string}'s actual length, 481multibyte, even if it's pure-@acronym{ASCII}.
479or if any new character requires a different number of bytes from the 482
480character currently present at that point in @var{string}. 483Since it is impossible to change the number of characters in an
484existing string, it is en error if @var{obj} consists of more
485characters than would fit in @var{string} starting at character index
486@var{idx}.
481@end defun 487@end defun
482 488
483 To clear out a string that contained a password, use 489 To clear out a string that contained a password, use