diff options
| author | Eli Zaretskii | 2022-06-05 11:28:10 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2022-06-05 11:28:10 +0300 |
| commit | 3ea9357d109e303fece9d49e1fdad8a2e42cc858 (patch) | |
| tree | 841f64e8540a7a16995cbfa411b41b00c58fe2ca | |
| parent | 1b8719835a200a2be17da226e82030f691caba80 (diff) | |
| download | emacs-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.texi | 32 |
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}. | |||
| 461 | described in this section. @xref{Mutability}. | 461 | described 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} | 466 | index @var{idx}. It will automatically convert a pure-@acronym{ASCII} |
| 467 | needs a different number of bytes from the character already present at | 467 | @var{string} to a multibyte string (@pxref{Text Representations}) if |
| 468 | that index, @code{aset} signals an error. | 468 | needed, but we recommend to always make sure @var{string} is multibyte |
| 469 | (e.g., by using @code{string-to-multibyte}, @pxref{Converting | ||
| 470 | Representations}), if @var{char} is a non-@acronym{ASCII} character, not | ||
| 471 | a 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 |
| 473 | This function alters part of the contents of the string @var{string}, by | 476 | This function alters part of the contents of the specified @var{string}, |
| 474 | storing @var{obj} starting at index @var{idx}. The argument @var{obj} | 477 | by storing @var{obj} starting at character index @var{idx}. The |
| 475 | may be either a character or a (smaller) string. | 478 | argument @var{obj} may be either a character (in which case the function |
| 476 | 479 | behaves exactly as @code{aset}) or a (smaller) string. If @var{obj} | |
| 477 | Since it is impossible to change the length of an existing string, it is | 480 | is a multibyte string, we recommend to make sure @var{string} is also |
| 478 | an error if @var{obj} doesn't fit within @var{string}'s actual length, | 481 | multibyte, even if it's pure-@acronym{ASCII}. |
| 479 | or if any new character requires a different number of bytes from the | 482 | |
| 480 | character currently present at that point in @var{string}. | 483 | Since it is impossible to change the number of characters in an |
| 484 | existing string, it is en error if @var{obj} consists of more | ||
| 485 | characters 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 |