From: Eli Zaretskii <eliz@gnu.org>
To: Richard Hansen <rhansen@rhansen.org>
Cc: 55801@debbugs.gnu.org
Subject: bug#55801: [PATCH] Fix documentation of `aset' on strings, `store-substring'
Date: Sun, 05 Jun 2022 11:30:00 +0300 [thread overview]
Message-ID: <83tu8za4xj.fsf@gnu.org> (raw)
In-Reply-To: <1d60b9cc-c6a5-e42b-7ed0-5ded2dcbab65@rhansen.org> (message from Richard Hansen on Sat, 4 Jun 2022 23:30:29 -0400)
> Date: Sat, 4 Jun 2022 23:30:29 -0400
> From: Richard Hansen <rhansen@rhansen.org>
>
> See attached patch:
>
> * doc/lispref/strings.texi (Modifying Strings): `aref` and
> `store-substring` automatically convert the string to multibyte if
> necessary, and support characters with different sized encodings.
Thanks.
I installed the following modified version, which I think is more
accurate (e.g., "length" and "index" can be ambiguous when talking
about Lisp strings), and also includes some practical advice that can
avoid some unibyte-vs-multibyte pitfalls and surprises with these
functions:
The most basic way to alter the contents of an existing string is with
@code{aset} (@pxref{Array Functions}). @w{@code{(aset @var{string}
@var{idx} @var{char})}} stores @var{char} into @var{string} at character
index @var{idx}. It will automatically convert a pure-@acronym{ASCII}
@var{string} to a multibyte string (@pxref{Text Representations}) if
needed, but we recommend to always make sure @var{string} is multibyte,
(e.g., by using @code{string-to-multibyte}, @pxref{Converting
Representations}), if @var{char} is a non-@acronym{ASCII} character, not
a raw byte.
A more powerful function is @code{store-substring}:
@defun store-substring string idx obj
This function alters part of the contents of the specified @var{string},
by storing @var{obj} starting at character index @var{idx}. The
argument @var{obj} may be either a character (in which case the function
behaves exactly as @code{aset}) or a (smaller) string. If @var{obj}
is a multibyte string, we recommend to make sure @var{string} is also
multibyte, even if it's pure-@acronym{ASCII}.
Since it is impossible to change the number of characters in an
existing string, it is en error if @var{obj} consists of more
characters than would fit in @var{string} starting at character index
@var{idx}.
@end defun
next prev parent reply other threads:[~2022-06-05 8:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-05 3:30 bug#55801: [PATCH] Fix documentation of `aset' on strings, `store-substring' Richard Hansen
2022-06-05 8:30 ` Eli Zaretskii [this message]
2022-06-05 19:22 ` Richard Hansen
2022-06-05 19:27 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83tu8za4xj.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=55801@debbugs.gnu.org \
--cc=rhansen@rhansen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).