Sujet : Re: Parsing timestamps?
De : sjack (at) *nospam* dontemail.me (sjack)
Groupes : comp.lang.forthDate : 08. Oct 2024, 16:19:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <ve3iht$27sb2$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : tin/2.6.4-20240224 ("Banff") (Linux/6.8.0-45-generic (x86_64))
Ahmed <
melahi_ahmed@yahoo.fr> wrote:
I know you don't care about this case, but:
Yes, originally I had syntax checks, left them out to focus more on getting
the zeros in.
-- ts_elms ( "[hh:][mm:]ss<bl>" -- 0 0 ss | 0 mm ss | hh mm ss )
-- Parse timestamp elements: hh=hours mm=minutes ss=seconds
-- Input hh: element and hh:mm: combination elements may be left out
-- if zero(s).
: ts_elms
bl word here count
over c@ asc : = >r ( leading char check )
2dup + 1- c@ asc : = ( lagging char check )
r> or if ." --Invalid " 2drop rdrop exit then
o+s do i c@ asc : = if bl i c! then loop
0 0 0 here count
begin
bl split dup 0> while &num number drop
5 roll drop -rot
repeat 4drop
;
[s] Invalid syntax
i. ts_elms 25: tab3. --> --Invalid
i. ts_elms :25 tab3. --> --Invalid
i. ts_elms :25: tab3. --> --Invalid
[s] Valid syntax
ts_elms 25
i. tab3. --> 00 00 25
i. ts_elms 25 tab3. --> 00 00 25
i. ts_elms 10:25 tab3. --> 00 10 25
i. ts_elms 2:10:25 tab3. --> 02 10 25