-TRAILING-GARBAGE

( 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