[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Most efficient way to recognize a line by its first (up to) three characters
- From: Coda Highland <chighland@...>
- Date: Tue, 11 Mar 2014 12:19:07 -0700
On Tue, Mar 11, 2014 at 12:12 PM, <meino.cramer@gmx.de> wrote:
> Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> [14-03-11 20:04]:
>> > Suppose I have one character code like this
>> >
>> > A;0000;0000;0000 ("0"s is data)
>>
>> Now that you've given us a sample of the input, the solution is easier:
>>
>> ... read line
>> local prefix,info=line:match("(.-);(.*)$")
>> local h=handlers[p[prefix] or badprefix
>> h(prefix,info)
>>
>> and register handlers for "A", "AB", "ABC", etc.
>>
>
> ...and the problem with examples is, that they are examples only :)
> And I have to sent all variations to completly define what I need
> (which I am not allowed to do, by the way).
> Only to describe another variation:
>
> *A N
>
> thats why I *trying* to describe things more theorectically (rigt
> word? I am no native english speaker...)...
>
In my opinion, at that point, try the example cited before but check
the longer prefixes first. The system would be inconsistent if a
command plus data could be confused for another command, so:
local h = handlers[line:sub(1,3)]
or handlers[line:sub(1,2)]
or handlers[line:sub(1,1)]
or badprefix
/s/ Adam