unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Checking for ASCII 7-bit Cleaness
@ 2009-06-09 18:44 Nordlöw
  2009-06-09 18:50 ` Nordlöw
  0 siblings, 1 reply; 3+ messages in thread
From: Nordlöw @ 2009-06-09 18:44 UTC (permalink / raw)
  To: help-gnu-emacs

How do I check that a buffer is 7-bit ASCII-clean, that is it only
contains characters between 0 and 127 inclusively.

I guess it should all start with find-file-literally().

Performance is of high priority in this case.

Thanks in advance,
Nordlöw


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

* Re: Checking for ASCII 7-bit Cleaness
  2009-06-09 18:44 Checking for ASCII 7-bit Cleaness Nordlöw
@ 2009-06-09 18:50 ` Nordlöw
  2009-06-09 18:53   ` Hallvard B Furuseth
  0 siblings, 1 reply; 3+ messages in thread
From: Nordlöw @ 2009-06-09 18:50 UTC (permalink / raw)
  To: help-gnu-emacs

In C I would have stepped forward 4 bytes (except for the resting 1-3
bytes of the file of course) and for each such block x then tested
that (x & 0x80808080) equals zero. If so the file is 7-bit clean.
Could we do something similar with elisp regular expression
operations?

/Nordlöw


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

* Re: Checking for ASCII 7-bit Cleaness
  2009-06-09 18:50 ` Nordlöw
@ 2009-06-09 18:53   ` Hallvard B Furuseth
  0 siblings, 0 replies; 3+ messages in thread
From: Hallvard B Furuseth @ 2009-06-09 18:53 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw writes:
> In C I would have stepped forward 4 bytes (except for the resting 1-3
> bytes of the file of course) and for each such block x then tested
> that (x & 0x80808080) equals zero. If so the file is 7-bit clean.
> Could we do something similar with elisp regular expression
> operations?

Don't think so.  That's a C internals trick, abusing how integers and
bytes are represented.

(defun buffer-ascii-clean-p ()
  (save-excursion
    (goto-char (point-min))
    (skip-chars-forward "[\0-\177]")
    (eobp)))

-- 
Hallvard


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

end of thread, other threads:[~2009-06-09 18:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-09 18:44 Checking for ASCII 7-bit Cleaness Nordlöw
2009-06-09 18:50 ` Nordlöw
2009-06-09 18:53   ` Hallvard B Furuseth

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