Deutsch   English   Français   Italiano  
<5c65a8f1fdfc3e9937a825842fe23dc2758f48ef@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: Reverse SCAN SPLIT
Date: Mon, 7 Oct 2024 19:52:15 +1100
Organization: i2pn2 (i2pn.org)
Message-ID: <5c65a8f1fdfc3e9937a825842fe23dc2758f48ef@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Oct 2024 08:52:20 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="937806"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="XPw7UV90Iy7EOhY4YuUXhpdoEf5Vz7K+BsxA/Cx8bVc";
User-Agent: Mozilla Thunderbird
X-Spam-Checker-Version: SpamAssassin 4.0.0
Content-Language: en-GB
Bytes: 1532
Lines: 30

Earlier I mentioned scanning in reverse.  Here's an implementation.

[undefined] dxforth [if]
: \CHAR ( a u -- a2 u2 c )  1- 2dup + c@ ;
[then]

\ As for SCAN but scan from end
: SCAN< ( a u c -- a2 u2 | a 0 )
  >r over swap begin dup while \char r@ = until 1+ then
  rot drop rdrop ;

\ As for SPLIT but scan from end. Latter string is topmost.
: SPLIT< ( a u c -- a2 u2 a3 u3 )
  >r 2dup r> scan< 2swap 2 pick /string ;

\ example

: /T ( a u -- hour min sec )
  3 0 do
    [char] : split<  0 0 2swap >number 2drop drop  -rot
    ( u ... a u)  dup if  1-  then
  loop 2drop  swap rot ;

: T  /t  cr  rot . ." hr "  swap . ." min " . ." sec " ;

s" 1:2:3"    t
s" 02:03"    t
s" 06:"      t
s" 03"       t
s" 23:59:59" t
s" 0:00:03"  t