octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading multiple files


From: Francesco Potorti`
Subject: Re: Loading multiple files
Date: Fri, 11 Mar 2005 19:45:15 -0600

Ok, here is a simplified version, with error management and all that is
needed, I think.  It remains to be seen if the behaviour is the same as
Perl's. 

===File ~/math/octavelib/utils/strinc.m=====================
function incs = strinc(s)

  ## usage: incs = strinc (s)
  ##
  ## Given a string s, increment it similarly to the way Perl does.
  ##
  ## The last alphanumeric character is substituted by its successor, apart
  ## from the characters in "9zZ", which are substituted by those in "0aA",
  ## in which case the character to the left is also incremented, and so on.
  ##
  ## Francesco Potortì <address@hidden>, 2005 License: GNU GPL
  ## <http://www.gnu.org/licenses/gpl.html>

  chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  newch = "1234567890bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA";

  if (length(s) == 0)
    warning("wrapping around");
  else
    last = s(end);
    pos = index(chars, last);
    if (pos == 0)
      error("cannot increment: successor of '%s' unknown", last);
    endif

    s(end) = newch(pos);
    if (index("9zZ", last) > 0)
      incs = [strinc(s(1:end-1)), s(end)];
      return;
    endif
  endif
  incs = s;
endfunction
============================================================

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 313 8091
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key



reply via email to

[Prev in Thread] Current Thread [Next in Thread]