# HG changeset patch # User jwe # Date 840583929 0 # Node ID c9f70d39255fd00ab984edc8dd8bdc57c20f30c2 # Parent 2ce6e1ec9b5355d0d481a189a842a44223ba13b9 [project @ 1996-08-20 23:30:54 by jwe] diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/ChangeLog --- a/scripts/ChangeLog Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/ChangeLog Tue Aug 20 23:32:09 1996 +0000 @@ -1,3 +1,7 @@ +Tue Aug 20 18:27:36 1996 Kurt Hornik + + * strings/substr.m: Allow negative OFFSET. LEN is now optional. + Mon Jul 15 16:15:22 1996 John W. Eaton * miscellaneous/bug_report.m: Don't redirect output to /dev/tty in diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/bin2dec.m --- a/scripts/strings/bin2dec.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/bin2dec.m Tue Aug 20 23:32:09 1996 +0000 @@ -22,12 +22,11 @@ ## Returns the decimal number corresponding to the binary number in ## quotes. For example, bin2dec ("1110") returns 14. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function y = bin2dec (x) -## Original version by Kurt Hornik . - if (nargin != 1) usage ("bin2dec (x)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/blanks.m --- a/scripts/strings/blanks.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/blanks.m Tue Aug 20 23:32:09 1996 +0000 @@ -21,12 +21,11 @@ ## ## Returns a string of n blanks. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function s = blanks (n) -## Original version by Kurt Hornik . - if (nargin != 1) usage ("blanks (n)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/deblank.m --- a/scripts/strings/deblank.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/deblank.m Tue Aug 20 23:32:09 1996 +0000 @@ -21,12 +21,11 @@ ## ## Remove trailing blanks from the string s. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function t = deblank (s) -## Original version by Kurt Hornik . - if (nargin != 1) usage ("deblank (s)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/dec2bin.m --- a/scripts/strings/dec2bin.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/dec2bin.m Tue Aug 20 23:32:09 1996 +0000 @@ -22,12 +22,11 @@ ## Returns the binary number corresponding to the nonnegative integer ## x. For example, dec2bin (14) returns "1110". -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function y = dec2bin (x) - ## Original version by Kurt Hornik . - if (nargin != 1) usage ("dec2bin (x)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/dec2hex.m --- a/scripts/strings/dec2hex.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/dec2hex.m Tue Aug 20 23:32:09 1996 +0000 @@ -22,12 +22,11 @@ ## Returns the hex number corresponding to the decimal number d. For ## example, dec2hex (2748) returns "abc". -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function h = dec2hex (d) -## Original version by Kurt Hornik . - if (nargin != 1) usage ("dec2hex (d)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/findstr.m --- a/scripts/strings/findstr.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/findstr.m Tue Aug 20 23:32:09 1996 +0000 @@ -30,12 +30,11 @@ ## findstr ("abababa", "aba") => [1, 3, 5] ## findstr ("abababa", "aba", 0) => [1, 5] -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function v = findstr (s, t, overlap) - ## Original version by Kurt Hornik . - if (nargin < 2 || nargin > 3) usage ("findstr (s, t [, overlap])"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/hex2dec.m --- a/scripts/strings/hex2dec.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/hex2dec.m Tue Aug 20 23:32:09 1996 +0000 @@ -23,12 +23,11 @@ ## quotes. For example, hex2dec ("12B") and hex2dec ("12b") both ## return 299. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function d = hex2dec (h) - ## Original version by Kurt Hornik . - if (nargin != 1) usage ("hex2dec (x)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/index.m --- a/scripts/strings/index.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/index.m Tue Aug 20 23:32:09 1996 +0000 @@ -24,14 +24,13 @@ ## ## NOTE: this function does not work for arrays of strings. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function n = index (s, t) ## This is patterned after the AWK function of the same name. - ## Original version by Kurt Hornik . - if (nargin != 2) usage ("index (s, t)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/rindex.m --- a/scripts/strings/rindex.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/rindex.m Tue Aug 20 23:32:09 1996 +0000 @@ -24,14 +24,13 @@ ## ## NOTE: this function does not work for arrays of strings. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function n = rindex (s, t) ## This is patterned after the AWK function of the same name. - ## Original version by Kurt Hornik . - if (nargin != 2) usage ("rindex (s, t)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/split.m --- a/scripts/strings/split.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/split.m Tue Aug 20 23:32:09 1996 +0000 @@ -23,12 +23,11 @@ ## pieces as the rows of M (padded with blanks to form a valid ## matrix). -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function m = split (s, t) -## Original version by Kurt Hornik . - if (nargin != 2) usage ("split (s, t)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/str2mat.m --- a/scripts/strings/str2mat.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/str2mat.m Tue Aug 20 23:32:09 1996 +0000 @@ -22,12 +22,11 @@ ## Forms the matrix M containing the strings S1, ... as its rows. ## Each string is padded with blanks in order to form a valid matrix. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe function m = str2mat (...) - ## Original version by Kurt Hornik . - if (nargin == 0) usage ("str2mat (s1, ...)"); endif diff -r 2ce6e1ec9b53 -r c9f70d39255f scripts/strings/substr.m --- a/scripts/strings/substr.m Tue Aug 20 22:45:36 1996 +0000 +++ b/scripts/strings/substr.m Tue Aug 20 23:32:09 1996 +0000 @@ -17,24 +17,30 @@ ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. -## usage: substr (s, beg, len) +## usage: substr (s, offset, len) ## -## Returns the substring of S of length LEN starting at index BEG. -## If LEN is missing, the substring extends to the end of S. +## Returns the substring of S of length LEN starting at index OFFSET. +## If OFFSET is negative, extraction starts that far from the end of +## the string. If LEN is omitted, the substring extends to the end +## of S. -## Author: jwe +## Author: Kurt Hornik +## Adapted-By: jwe -function t = substr (s, beg, len) - - ## Original version by Kurt Hornik . +function t = substr (s, offset, len) if (nargin < 2 || nargin > 3) - usage ("substr (s, beg, len)"); + usage ("substr (s, offset [, len])"); endif if (isstr (s)) nc = columns (s); - if (beg > 0 && beg <= nc) + if (abs (offset) > 0 && abs (offset) <= nc) + if (offset > 0) + beg = offset; + else + beg = nc + offset + 1; + endif if (nargin == 2) eos = nc; else @@ -46,7 +52,7 @@ error ("substr: length = %d out of range", len); endif else - error ("substr: beginning index = %d out of range", beg); + error ("substr: offset = %d out of range", offset); endif else error ("substr: expecting string argument");