| Deutsch English Français Italiano |
|
<927ca1c2b969054aafdcd77657ab096b10eded5d@i2pn2.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: dxf <dxforth@gmail.com>
Newsgroups: comp.lang.forth
Subject: Re: Parsing timestamps?
Date: Tue, 8 Oct 2024 14:07:31 +1100
Organization: i2pn2 (i2pn.org)
Message-ID: <927ca1c2b969054aafdcd77657ab096b10eded5d@i2pn2.org>
References: <1f433fabcb4d053d16cbc098dedc6c370608ac01@i2pn2.org>
<nnd$4c9fbd3d$321d37fb@0e0bb7c1bfc1d5fc>
<8650bd010df25e0833e658b7b54995b4ca62fec8@i2pn2.org>
<ve11od$1pcla$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 8 Oct 2024 03:07:32 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="1050420"; mail-complaints-to="usenet@i2pn2.org";
posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc";
User-Agent: Mozilla Thunderbird
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <ve11od$1pcla$1@dont-email.me>
Content-Language: en-GB
Bytes: 2491
Lines: 49
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