18.6.2.0175 -TRAILING-GARBAGE minus-trailing-garbage XCHAR EXT

( xc-addr u1 -- xc-addr u2 )

Examine the last xchar in the string xc-addr u1 — if the encoding is correct and it represents a full xchar, u2 equals u1, otherwise, u2 represents the string without the last (garbled) xchar. -TRAILING-GARBAGE does not change this garbled xchar.

Implementation:

: -TRAILING-GARBAGE ( xc-addr u1 -- xc-addr u2 )
   2DUP + DUP XCHAR- ( addr u1 end1 end2 )
   2DUP DUP OVER OVER - X-SIZE + = IF \ last xchar ok
     2DROP
   ELSE
     NIP NIP OVER -
   THEN ;

ContributeContributions

AntonErtlavatar of AntonErtl [257] PronounciationComment2022-08-15 14:04:40

In keeping with the style for -trailing, the pronounciation of -trailing-garbage should be "dash-trailing-garbage".

Reply New Version