17.6.2.2375 UNESCAPE STRING EXT
Replace each `%
' character in the input string
c-addr1 u1 by two `%
' characters. The output
is represented by c-addr2 u2. The buffer at c-addr2
shall be big enough to hold the unescaped string. An ambiguous
condition occurs if the resulting string will not fit into the
destination buffer (c-addr2).
See:
Implementation:
\ Replace each '
%
' character in the input string c-addr1 len1 with two '%
' characters. \ The output is represented by c-addr2 len2.
\ If you pass a string through UNESCAPE and then SUBSTITUTE, you get the original string.
DUP 2SWAP OVER + SWAP ?DO
I C@ [CHAR] % = IF
[CHAR] % OVER C! 1+
THEN
I C@ OVER C! 1+
LOOP
OVER -
;
Testing:
subbuff
, sub5
and sub6
from F.17.6.2.2255 SUBSTITUTE.
T{ sub6 subbuff UNESCAPE sub5 COMPARE -> 0 }T
ContributeContributions
ruv [85] Etymology and naming issueRequest for clarification2019-06-25 09:18:19
Why this word was called unescape?
Usually escape
function does what this word — it replaces some characters with an encoded form, and unescape
function does reverse transformation — it replaces an encoded form with its original. For example, see in JavaScript, Python, Rust, T-SQL, etc.
Did the committee have examples when the conventional Forth practice for unescape
word was so opposite to common usage of escape
and unescape
functions in many other languages?