unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Replacement for string-as-unibyte function
@ 2021-01-31  0:34 Joe Riel
  2021-01-31  2:40 ` moasenwood--- via Users list for the GNU Emacs text editor
  2021-01-31  3:35 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Joe Riel @ 2021-01-31  0:34 UTC (permalink / raw)
  To: Help GNU Emacs

As of 26.1, string-as-unibyte is deprecated.  The suggested 
replacement is encode-coding-string.  What coding-system should
be passed to that function to get the equivalent result?

-- 
Joe Riel




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replacement for string-as-unibyte function
  2021-01-31  0:34 Replacement for string-as-unibyte function Joe Riel
@ 2021-01-31  2:40 ` moasenwood--- via Users list for the GNU Emacs text editor
  2021-01-31  3:35 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: moasenwood--- via Users list for the GNU Emacs text editor @ 2021-01-31  2:40 UTC (permalink / raw)
  To: help-gnu-emacs

Joe Riel wrote:

> As of 26.1, string-as-unibyte is deprecated. The suggested
> replacement is encode-coding-string. What coding-system
> should be passed to that function to get the
> equivalent result?

Good question!

That should be improved in the docstring!

No idea actually ...

(let ((multibyte-string (string-to-multibyte "Test string.\n")))
  (string=
   (string-as-unibyte    multibyte-string)
   (encode-coding-string multibyte-string 'utf-8-unix) )) ; t

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replacement for string-as-unibyte function
  2021-01-31  0:34 Replacement for string-as-unibyte function Joe Riel
  2021-01-31  2:40 ` moasenwood--- via Users list for the GNU Emacs text editor
@ 2021-01-31  3:35 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2021-01-31  3:35 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 30 Jan 2021 16:34:10 -0800
> From: Joe Riel <joer@san.rr.com>
> 
> As of 26.1, string-as-unibyte is deprecated.  The suggested 
> replacement is encode-coding-string.  What coding-system should
> be passed to that function to get the equivalent result?

Please describe your use case: what are you trying to do that you
needed string-as-unibyte?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Replacement for string-as-unibyte function
@ 2021-01-31 23:02 Joe Riel
  2021-02-01  3:30 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Riel @ 2021-01-31 23:02 UTC (permalink / raw)
  To: Help GNU Emacs

Apologies for this partial duplicate; after posting realized I no longer
receive email from this group, so renewed.  Am copying and responding to response
from the website:

Eli Zaretskii asks:
> Please describe your use case: what are you trying to do that you
> needed string-as-unibyte?  

Am handling a message passed in from an external process
(its passed in chunks).

The header of the message specifies its length, in bytes.
Some of the characters may be unicode.   Am using
buffer-substring-no-properties to later extract the message.
To get its length write, each byte has to be a character in the buffer.

It appears as though

   (encode-coding-string string 'utf-8-unix)

is the equivalent of (string-as-unibyte string).


-- 
Joe Riel




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replacement for string-as-unibyte function
  2021-01-31 23:02 Joe Riel
@ 2021-02-01  3:30 ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2021-02-01  3:30 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sun, 31 Jan 2021 15:02:27 -0800
> From: Joe Riel <joer@san.rr.com>
> 
> Eli Zaretskii asks:
> > Please describe your use case: what are you trying to do that you
> > needed string-as-unibyte?  
> 
> Am handling a message passed in from an external process
> (its passed in chunks).
> 
> The header of the message specifies its length, in bytes.
> Some of the characters may be unicode.   Am using
> buffer-substring-no-properties to later extract the message.
> To get its length write, each byte has to be a character in the buffer.

Then the text you get is already unibyte, and I see no reason to use
string-as-unibyte.  Just read the text into a unibyte buffer and
process it there, then _decode_ everything when you want to present it
or process it as human-readable text.

IOW, I don't see why you'd need string-as-unibyte in this scenario.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-01  3:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-31  0:34 Replacement for string-as-unibyte function Joe Riel
2021-01-31  2:40 ` moasenwood--- via Users list for the GNU Emacs text editor
2021-01-31  3:35 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2021-01-31 23:02 Joe Riel
2021-02-01  3:30 ` Eli Zaretskii

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).