From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ken Newsgroups: gmane.emacs.help Subject: Re: use of "match-string" Date: Tue, 08 Mar 2011 18:48:36 -0500 Message-ID: <4D76C054.3090005@mousecar.com> References: <87r5ahi9bi.fsf@rapttech.com.au> Reply-To: gebser@mousecar.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1299628160 17280 80.91.229.12 (8 Mar 2011 23:49:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2011 23:49:20 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Tim X Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 09 00:49:16 2011 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.69) (envelope-from ) id 1Px6eQ-0002oJ-Lf for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Mar 2011 00:49:14 +0100 Original-Received: from localhost ([127.0.0.1]:37026 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px6eQ-0006q3-7R for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Mar 2011 18:49:14 -0500 Original-Received: from [140.186.70.92] (port=38928 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px6dv-0006pw-F6 for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 18:48:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Px6du-0001gk-3d for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 18:48:43 -0500 Original-Received: from mout.perfora.net ([74.208.4.194]:61398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Px6dt-0001gd-T1 for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 18:48:42 -0500 Original-Received: from dellap.mousecar.net (dsl093-011-016.cle1.dsl.speakeasy.net [66.93.11.16]) by mrelay.perfora.net (node=mrus0) with ESMTP (Nemesis) id 0M1m54-1QG9xn1Wx8-00tyfP; Tue, 08 Mar 2011 18:48:39 -0500 User-Agent: Thunderbird 2.0.0.24 (X11/20101213) In-Reply-To: <87r5ahi9bi.fsf@rapttech.com.au> X-Enigmail-Version: 0.96.0 OpenPGP: id=5AD091E7 X-Provags-ID: V02:K0:QdNxkoFE9G457c1dfAxg5XxQPpvDE+WWB4dosbKClgh 4IZcgzbrHEXy6yLexa2K5apipJ8OlSc7MX4DhAHBqumj96TsEp eD/t85Q9D+ZGLRaIiXd0fQoZ1pvWnFczWn08l9jenHrGoxJami +Cbrznpl2Qodzb72nf2fjVxcd5kTPvuvgx7YQ4zMl4eGABorLr gufge+VIKmx0VeNAqV9hwMzE+xGQr9UkD+v3tLwxV0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.208.4.194 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:79903 Archived-At: Thanks, Tim. PJ pointed this out a couple hours before you. You were quick, but he was quicker. On 03/08/2011 04:36 PM Tim X wrote: > ken writes: > >> Part of this function doesn't make sense-- >> >> (defun html-toc-find-max () >> (goto-char (point-min)) >> (let ((max-toc 0)) >> (while (search-forward-regexp html-toc-tocref nil t) >> (if (> (string-to-int (match-string 1)) max-toc) >> (setq max-toc (string-to-int (match-string 1))))) >> (1+ max-toc))) >> >> -- specifically, where match-string is first called and turned into a >> number. The docs say that match-string returns a string.... Yes, this >> can be done I suppose, but to what end? Moreover, depending upon its >> value, this "number" may then be assigned to a variable, and that value >> then compared with subsequent strings. >> >> Perhaps I'm missing some nuance here. The entirety of the code is >> below. Does anyone understand what's going on here? >> > > I'm not sure what it is you find 'odd' about the above function. Apart > from the fact it should be using string-to-number (string-to-int has > been marked obsolete since 22.1), it seems reasonable to me. > > The regexp used in the match is > >> (defvar html-toc-tocref (concat "> "\\([0-9]*\\)\">")) > > Note the 1st (and only) grouping in the regexp i.e. \\([0-9]*\\), which > will match on 0 or more digits between 0..9. This is what (match-string > 1) will return. (though as it is [0-9]* it could return 0 or more > digits, so match-string 1 could be "", which may be an issue). > > The string-to-int call will return that value as a number rather than as > a string, which is then compared to max-toc (initially set to 0), not to > a string. The final value has 1 added to it. So, your not comparing > strings, you are comparing strings of numers that are converted to be a number. > > So, this function would search through the buffer for the specified > regexp, extract the group of digits as a string, convert them to a > number and compare them to the last one found. If the number is larger, > it would set that as the max and then continue the loop. Finally, it > adds 1. > > I can see some things I would do differently and even if you don't find > a match, your max-toc value will have a value of at least 1, but apart > from that, it seems to do whatever it was intended to do. > > Tim > >