MOO-cows Mailing List Archive

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

Very large match strings



What I'd like to be able to do is make a string to pass as the second
argument to the builtin function match() that repeats a certain sequence
a specified number of times.  I currently have a very large string that
includes the sequence (of 248 bytes) over and over 79 times (for a total
match-string size of 19592 bytes).  Now this works fine, but I'm betting
that it uses up lots of system resources (even though it is great when
it comes to counting ticks).  Would someone please tell me if this is a 
very bad idea, etc, please?  (or maybe if there's a way to repeat a 
sequence a /certain/ number of times)

The whole reason for doing this (and if the guy who made $ansi_utils is
listening, you might be interested -- listen up! :) is so that I can make
a very tick-happy :linesplit() function to deal with color sequences.
Basically, I'm passing a sequence that has the following in it over and
over again (but a few more colors):

        %(%[%(red%|white%|blue%|bell%)%]%)*.

This way, since it is repeated 79 times, I'll have any number (including 
zero) of escape sequences, and 79 characters of non-escape sequences,
and I can use the information that match() returns to me to figure out
where to cutoff the line (and check for a space and stuff like that).
My current linesplit function looks like this:

   line = args[1];                                                     
   len = args[2];                                                      
   cline = {};                                                         
   while (m = match(line, $color_utils.linesplit_match[1..len * 248])) 
     cutoff = rindex(line[1..a = m[2]], " ");                          
     if (nospace = cutoff < 4 * a / 5)                                 
       cutoff = a + 1;                                                 
       nospace = line[cutoff] != " ";                                  
     endif                                                             
     cline = {@cline, line[1..cutoff - 1]};                            
     line = (nospace ? " " | "") + line[cutoff..$];                    
   endwhile                                                            
   return {@cline, line};                                              

The $color_utils.linesplit_match is a very large string (the sequence
is repeated 158 times) which is cut off at the appropriate place for
the specified linelength.

Thanks in advance for any input...

--Nate


Follow-Ups:

Home | Subject Index | Thread Index