Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 116,860 of 117,927    |
|    dxf to sjack    |
|    Re: Parsing timestamps?    |
|    08 Oct 24 14:07:31    |
   
   From: dxforth@gmail.com   
      
   On 8/10/2024 3:20 am, sjack wrote:   
   > dxf 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" -- 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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca