changeset 6753:a5c64dad5b93

[project @ 2007-06-25 17:05:58 by jwe]
author jwe
date Mon, 25 Jun 2007 17:05:58 +0000
parents ee2ad7b5454a
children 451b346d8c2f
files scripts/ChangeLog scripts/strings/substr.m
diffstat 2 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Jun 25 16:54:52 2007 +0000
+++ b/scripts/ChangeLog	Mon Jun 25 17:05:58 2007 +0000
@@ -1,3 +1,8 @@
+2007-06-25  John W. Eaton  <jwe@octave.org>
+
+	* strings/substr.m: Use offset consistently in code and doc string.
+	From Rafael Laboissiere <rafael@debian.org>.
+
 2007-06-25  Pete Gustafson <petegus@umich.edu>
 
         * plot/__go_draw_axes__.m: Handle units for text objects.
--- a/scripts/strings/substr.m	Mon Jun 25 16:54:52 2007 +0000
+++ b/scripts/strings/substr.m	Mon Jun 25 17:05:58 2007 +0000
@@ -18,25 +18,23 @@
 ## 02110-1301, USA.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} substr (@var{s}, @var{beg}, @var{len})
+## @deftypefn {Function File} {} substr (@var{s}, @var{offset}, @var{len})
 ## Return the substring of @var{s} which starts at character number
-## @var{beg} and is @var{len} characters long.
+## @var{offset} and is @var{len} characters long.
 ##
-## If OFFSET is negative, extraction starts that far from the end of
-## the string.  If LEN is omitted, the substring extends to the end
+## If @var{offset} is negative, extraction starts that far from the end of
+## the string.  If @var{len} is omitted, the substring extends to the end
 ## of S.
 ##
-##   For example,
+## For example,
 ##
 ## @example
 ## substr ("This is a test string", 6, 9)
 ##      @result{} "is a test"
 ## @end example
 ##
-## @quotation
 ## This function is patterned after AWK.  You can get the same result by
-## @code{@var{s} (@var{beg} : (@var{beg} + @var{len} - 1))}.
-## @end quotation
+## @code{@var{s} (@var{offset} : (@var{offset} + @var{len} - 1))}.
 ## @end deftypefn
 
 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
@@ -51,18 +49,16 @@
   if (ischar (s))
     nc = columns (s);
     if (abs (offset) > 0 && abs (offset) <= nc)
-      if (offset > 0)
-        beg = offset;
-      else
-        beg = nc + offset + 1;
+      if (offset <= 0)
+        offset += nc + 1;
       endif
       if (nargin == 2)
         eos = nc;
       else
-        eos = beg + len - 1;
+        eos = offset + len - 1;
       endif
       if (eos <= nc)
-        t = s (:, beg:eos);
+        t = s (:, offset:eos);
       else
         error ("substr: length = %d out of range", len);
       endif