[EXIM] Additional string/token function for exim

Top Page
Delete this message
Reply to this message
Author: Philip Hazel
Date:  
To: Nigel Metheringham
CC: exim-users
Subject: [EXIM] Additional string/token function for exim
On Mon, 22 Dec 1997, Nigel Metheringham wrote:

> I'm finally having to give in and implement a string function to extract a
> section from a token separated string - ie like getting components out of
> a passwd line.
>
> I was thinking of making this something like:-
>    ${token{<field>}{<sep>}{<string>}}

>
> where:-
>   <field>    - numeric field id >= 0 (first field is zero)
>   <sep>        - class of characters acting as separators (as in strtok(2)
>          or strchr(2))
>   <string>    - string to parse

>
> so in a passwd like line,
>    ${token{5}{:}{<line>}}
> would extract the home directory.

>
> Are there any problems with this? Syntax/Name OK?? Any suggestions for a
> better solution? etc...


I don't like the word "token" because it's not clear what it means, and
other similar things (lookup and extract) are verbs. I think I'd be
happier with "field" (though it isn't a verb) or "getfield". Neither
very nice, though.

This does complement the existing key=value style of extraction. As that
has only two arguments, I suppose one *could* use the same verb,
"extract", and separate the two cases by the number of arguments. So

${extract{5}{:}{<line>}}

extracts the fifth colon-separated field, while

${extract{uid}{<line>}}

extracts the field keyed by uid= in the line. What do you think?

I'm not sure that I like numbering the first field from zero. It is sure
to cause confusion, because people will talk about things like "the 6th
field in the password file". I'd rather number from 1 and give an error
for zero (or give the whole line, like $0 after a regex match).

The only way of getting this effect without writing code is of course to
use a regex.

Philip

-- 
Philip Hazel                   University Computing Service,
ph10@???             New Museums Site, Cambridge CB2 3QG,
P.Hazel@???          England.  Phone: +44 1223 334714



--
*** Exim information can be found at http://www.exim.org/ ***