Re: Parsing timestamps?

Liste des GroupesRevenir à cl forth 
Sujet : Re: Parsing timestamps?
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forth
Date : 08. Oct 2024, 04:07:31
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <927ca1c2b969054aafdcd77657ab096b10eded5d@i2pn2.org>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 8/10/2024 3:20 am, sjack wrote:
dxf <dxforth@gmail.com> wrote:
The HH:MM:SS format is easy but how to deal with the variants shown above?
They occur in the real world.
 
Toad code:
fload job
: xx.  0 <# bl hold # # #> type ;
: tab3.    tab rot xx. swap xx. xx. ;
 
-- &num  ( g -- s )
-- Convert g-string to numeric string address
: &num drop 1- ;
-- Note g-string is ANS string ( addr u )
 
-- 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
  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
  ;
...

Not bad.  Here's a translation.  Hopefully it's equivalent (?)

: split ( a u c -- a2 u2 a3 u3 )
  >r 2dup r> scan 2swap 2 pick - ;

: number ( a u -- u )  0 0 2swap >number 2drop ;

: xx. ( u -- )  0 <# bl hold # # #> type ;
: tab3. ( h m s -- )  3 spaces ( tab)  rot xx. swap xx. xx. ;

: ts_elms ( a u -- h m s )
  2>r  0 0 0  2r>  begin
    [char] : skip  [char] : split  dup 0> while
    number drop  5 roll drop -rot
  repeat 2drop 2drop ;

s" 25"      ts_elms  tab3.    00 00 25  ok
s" 10:25"   ts_elms  tab3.    00 10 25  ok
s" 2:10:25" ts_elms  tab3.    02 10 25  ok


Date Sujet#  Auteur
6 Oct 24 * Parsing timestamps?45dxf
6 Oct 24 +* Re: Parsing timestamps?8mhx
6 Oct 24 i+* Re: Parsing timestamps?3dxf
6 Oct 24 ii`* Re: Parsing timestamps?2dxf
7 Oct 24 ii `- Re: Parsing timestamps?1dxf
7 Jun13:38 i`* Re: Parsing timestamps?4B. Pym
7 Jun15:36 i `* Re: Parsing timestamps?3dxf
7 Jun18:07 i  `* Re: Parsing timestamps?2LIT
8 Jun03:38 i   `- Re: Parsing timestamps?1dxf
6 Oct 24 +* Re: Parsing timestamps?5Ruvim
6 Oct 24 i`* Re: Parsing timestamps?4dxf
6 Oct 24 i `* Re: Parsing timestamps?3Ruvim
6 Oct 24 i  +- Re: Parsing timestamps?1Ruvim
6 Oct 24 i  `- Re: Parsing timestamps?1Ruvim
6 Oct 24 +* Re: Parsing timestamps?6FFmike
6 Oct 24 i`* Re: Parsing timestamps?5FFmike
7 Oct 24 i `* Re: Parsing timestamps?4dxf
7 Oct 24 i  `* Re: Parsing timestamps?3FFmike
7 Oct 24 i   `* Re: Parsing timestamps?2dxf
7 Oct 24 i    `- Re: Parsing timestamps?1FFmike
6 Oct 24 +* Re: Parsing timestamps?2Anthony Howe
7 Oct 24 i`- Re: Parsing timestamps?1dxf
7 Oct 24 +* Re: Parsing timestamps?9albert
7 Oct 24 i`* Re: Parsing timestamps?8dxf
7 Oct 24 i `* Re: Parsing timestamps?7sjack
8 Oct 24 i  `* Re: Parsing timestamps?6dxf
8 Oct 24 i   +* Re: Parsing timestamps?3Ahmed
8 Oct 24 i   i+- Re: Parsing timestamps?1dxf
8 Oct 24 i   i`- Re: Parsing timestamps?1sjack
8 Oct 24 i   `* Re: Parsing timestamps?2sjack
9 Oct 24 i    `- Re: Parsing timestamps?1dxf
8 Oct 24 +* Re: Parsing timestamps?3albert
8 Oct 24 i`* Re: Parsing timestamps?2dxf
8 Oct 24 i `- Re: Parsing timestamps?1Ahmed
9 Oct 24 +* Re: Parsing timestamps?4alaa
10 Oct 24 i+* Re: Parsing timestamps?2dxf
10 Oct 24 ii`- Re: Parsing timestamps?1alaa
16 Oct 24 i`- Re: Parsing timestamps?1Hans Bezemer
18 Oct 24 `* Re: Parsing timestamps?7Gerry Jackson
19 Oct 24  `* Re: Parsing timestamps?6dxf
28 Oct 24   `* Re: Parsing timestamps?5Hans Bezemer
29 Oct 24    `* Re: Parsing timestamps?4dxf
29 Oct 24     `* Re: Parsing timestamps?3Hans Bezemer
30 Oct 24      `* Re: Parsing timestamps?2dxf
31 Oct 24       `- Re: Parsing timestamps?1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal