From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.help Subject: Re: Is X'ABCD' notation of general interest? Date: Sun, 12 Apr 2009 13:45:53 +0200 Message-ID: <8763hajdse.fsf@ambire.localdomain> References: <4e8b531d-ecc7-4b71-ac69-faa82eccd4ae@c9g2000yqm.googlegroups.com> <45202d31-fd33-4b35-9bb7-fe4af6eb4012@c9g2000yqm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1239537096 8990 80.91.229.12 (12 Apr 2009 11:51:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Apr 2009 11:51:36 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: florian Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 12 13:52:55 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LsyF3-0006C5-83 for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2009 13:52:53 +0200 Original-Received: from localhost ([127.0.0.1]:41717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsyDe-0001Wp-Ru for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2009 07:51:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LsyDG-0001WU-Uh for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 07:51:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LsyDF-0001WI-C7 for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 07:51:02 -0400 Original-Received: from [199.232.76.173] (port=55514 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsyDF-0001WF-6B for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 07:51:01 -0400 Original-Received: from smtp-out113.alice.it ([85.37.17.113]:1391) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LsyDE-0004Go-Os for help-gnu-emacs@gnu.org; Sun, 12 Apr 2009 07:51:00 -0400 Original-Received: from FBCMMO02.fbc.local ([192.168.68.196]) by smtp-out113.alice.it with Microsoft SMTPSVC(6.0.3790.3959); Sun, 12 Apr 2009 13:50:58 +0200 Original-Received: from FBCMCL01B04.fbc.local ([192.168.69.85]) by FBCMMO02.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sun, 12 Apr 2009 13:50:27 +0200 Original-Received: from ambire.localdomain ([79.40.68.58]) by FBCMCL01B04.fbc.local with Microsoft SMTPSVC(6.0.3790.3959); Sun, 12 Apr 2009 13:50:26 +0200 Original-Received: from ttn by ambire.localdomain with local (Exim 4.63) (envelope-from ) id 1Lsy8H-0002W3-1j; Sun, 12 Apr 2009 13:45:53 +0200 In-Reply-To: <45202d31-fd33-4b35-9bb7-fe4af6eb4012@c9g2000yqm.googlegroups.com> (florian's message of "Thu, 9 Apr 2009 03:05:03 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-OriginalArrivalTime: 12 Apr 2009 11:50:27.0181 (UTC) FILETIME=[DF27A1D0:01C9BB64] X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:63689 Archived-At: () florian () Thu, 9 Apr 2009 03:05:03 -0700 (PDT) The X'ABCD' notation represents arbitrary bytes as their two-digit hexadecimal representation, which produces strings that have double the size and can be passed over the command line (SQLite uses this). Does anybody think that functions to handle that (I have round-trip tested them) would be of general interest, so that posting them on gnu.emacs.sources would make sense? (Just don't want to clutter public space needlessly.) You may be interested in knowing that Emacs can `read' hex if the number has the "#x" prefix. (let ((standard-input "#x0a")) (read)) => 10 Something like the following (completely untested) code might be faster than using `string-to-number': (defvar small "#x......" "Fixed-size buffer holding a small hex number to be `read'.") (defun next-small-X-quote-hex-quote-number () "Return the next parsed X'HEX-NUMBER' or nil." (let ((ok (- (length small) 2)) ;; -2 for "#x" b e) (when (re-search-forward "X'[0-9a-fA-F]+'" nil t) (setq b (+ 2 (match-beginning 0)) e (1- (point))) (if (not (< ok (- e b))) ;; "fast path" (one hopes, one wonders) (do ((w 2 (1+ w))) ((= b e) (let ((standard-input small)) (read))) (aset small w (char-before (incf b)))) ;; fallback for big strings (string-to-number (buffer-substring b e) 16))))) This is the limit (performance wise) if the buffer is not to be modified. If the buffer can be modified, you can go even faster if you rewrite the "X'" as "x#" directly and set `standard-input' to `(current-buffer)' (plus usual performance tweaks). Of course, if speed matters not, then no worries, feel free to ignore... thi