changeset 2355:c9f70d39255f

[project @ 1996-08-20 23:30:54 by jwe]
author jwe
date Tue, 20 Aug 1996 23:32:09 +0000
parents 2ce6e1ec9b53
children de9eb7bd4405
files scripts/ChangeLog scripts/strings/bin2dec.m scripts/strings/blanks.m scripts/strings/deblank.m scripts/strings/dec2bin.m scripts/strings/dec2hex.m scripts/strings/findstr.m scripts/strings/hex2dec.m scripts/strings/index.m scripts/strings/rindex.m scripts/strings/split.m scripts/strings/str2mat.m scripts/strings/substr.m
diffstat 13 files changed, 42 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- 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  <Kurt.Hornik@ci.tuwien.ac.at>
+
+	* strings/substr.m: Allow negative OFFSET.  LEN is now optional.
+
 Mon Jul 15 16:15:22 1996  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* miscellaneous/bug_report.m: Don't redirect output to /dev/tty in
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function y = bin2dec (x)
 
-## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 1)
     usage ("bin2dec (x)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function s = blanks (n)
 
-## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 1)
     usage ("blanks (n)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function t = deblank (s)
 
-## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 1)
     usage ("deblank (s)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function y = dec2bin (x)
 
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 1)
     usage ("dec2bin (x)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function h = dec2hex (d)
 
-## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 1)
     usage ("dec2hex (d)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function v = findstr (s, t, overlap)
 
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin < 2 || nargin > 3)
     usage ("findstr (s, t [, overlap])");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function d = hex2dec (h)
 
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 1)
     usage ("hex2dec (x)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function n = index (s, t)
 
   ## This is patterned after the AWK function of the same name.
 
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 2)
     usage ("index (s, t)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function n = rindex (s, t)
 
   ## This is patterned after the AWK function of the same name.
 
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 2)
     usage ("rindex (s, t)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function m = split (s, t)
 
-## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin != 2)
     usage ("split (s, t)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
 function m = str2mat (...)
 
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
-
   if (nargin == 0)
     usage ("str2mat (s1, ...)");
   endif
--- 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 <Kurt.Hornik@ci.tuwien.ac.at>
+## Adapted-By: jwe
 
-function t = substr (s, beg, len)
-
-  ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
+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");