| Deutsch English Français Italiano |
|
<f1e4ee424c323c0feab4c5a1db761cb8cdad6461@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: Thu, 10 Oct 2024 12:17:57 +1100 Organization: i2pn2 (i2pn.org) Message-ID: <f1e4ee424c323c0feab4c5a1db761cb8cdad6461@i2pn2.org> References: <1f433fabcb4d053d16cbc098dedc6c370608ac01@i2pn2.org> <72c9670d5935524d42be0ef5c6c48338@www.novabbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 10 Oct 2024 01:18:00 -0000 (UTC) Injection-Info: i2pn2.org; logging-data="1335661"; mail-complaints-to="usenet@i2pn2.org"; posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc"; User-Agent: Mozilla Thunderbird Content-Language: en-GB In-Reply-To: <72c9670d5935524d42be0ef5c6c48338@www.novabbs.com> X-Spam-Checker-Version: SpamAssassin 4.0.0 Bytes: 2007 Lines: 27 On 10/10/2024 2:27 am, alaa wrote: > Hi, > > here is another way, which was fun: > > \ > https://www.novabbs.com/devel/article-flat.php?id=28040&group=comp.lang.forth#28040 > VOCABULARY timestamps-parser ALSO timestamps-parser DEFINITIONS > > \ Idea: parse backward > VARIABLE a VARIABLE n > : >an n ! a ! ; : /an 0 a ! 0 n ! ; > : ch ( -- c ) a @ n @ + 1- C@ ; > : more? ( -- t/f ) n @ 0<> ; > : ch+ ( -- ) more? NOT ABORT" exceeded string" -1 n +! ; > : colon ( -- ) more? IF ch ':' <> ABORT" Expected colon!" ch+ THEN ; > : d? ( c -- t/f ) '0' '9' 1+ WITHIN ; > : digit? ( c -- t/f ) d? NOT ABORT" Expected a digit!" ; > : d ( -- ) ch digit? ch 48 - ch+ ; > : [d] ( -- n ) ch d? IF ch 48 - ch+ ELSE 0 THEN ; > : hr ( -- n ) [d] [d] 10 * + ; : min ( -- n ) [d] [d] 10 * + ; : sec ( > -- n ) d [d] 10 * + ; > : parse ( a n -- s m h ) >an sec colon min colon hr /an ; > ... Would be useful where extra checking of fields is required. In that case when ':' is detected, there ought to be at least one digit before it.