Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/compare.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH library - COMPARE (STRING) - Copyright 2003,2004 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] ignorecase [IF]
true constant ignorecase immediate     \ default ignore case
[THEN]

[UNDEFINED] compare [IF]               \ this routine compares two strings
: compare                              ( a1 n1 a2 n2 -- f )
  rot over over swap - >r              ( a1 a2 n2 n1)
  min 0 tuck                           ( a1 a2 0 n 0)
  ?do                                  ( a1 a2 f)
    drop                               ( a1 a2)
    over i + c@                        ( a1 a2 c1)
ignorecase [IF]
    dup [char] A - max-n and 26 < if bl or then
[THEN]
    over i + c@                        ( a1 a2 c1 c2)
ignorecase [IF]
    dup [char] A - max-n and 26 < if bl or then
[THEN]
    - dup                              ( a1 a2 f f)
    if leave then                      ( a1 a2 f)
  loop
  >r drop drop r> r> swap dup          ( f1 f2 f2)
  if swap then drop                    ( f)
;
[THEN]


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].