jed-users mailing list

[2004 Date Index] [2004 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Dynamic string arrays in slang/jed?


Brian Blais wrote:
 
> I am trying to make a string array which doesn't have a specified size at the
> beginning. 

For string "arrays", this is easy, as long as you have a "spare"
character that you can use as delimiter. For other types of arrays,
http://jedmodes.sf.net/mode/datutils/ contains helper functions for
"dynamic arrays (concatenate, delete, append/prepend).
 
> My current solution is to use a jed buffer, copy the buffer, and then do a
> strtok() call looking for end-of-line characters:
... 
> Is there a better solution?

Use a String_Type variable instead of a buffer. (See e.g.
http://jedmodes.sf.net/mode/recent for an example.)

You already know about strtok(). Also of interest are strjoin() and
strchop() as well as extract_list_element().


  variable fnames, fname; 
  foreach(listdir(dirname))
  {
      fname = ();
      if (isimage(fname))
         fnames += dirname+"/"+fname+"\n";
  }
  fnames=strchop(fnames, '\n', 0);


In your case, you can also use the array_map() and where() functions plus
the fact, that an array index can be an array itself:

  fnames = listdir(dirname);
  variable f_is_image = array_map(Int_Type, &isimage, fnames);
  fnames = fnames[where(f_is_image)];

(Untested. See the documentation of where and array_map.)

Günter

-- 
G.Milde at web.de

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2004 date index] [2004 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]