· Dec 7, 2016

What does macro $$$URLENCODE do


I was looking at the ENSDEMO namespace in our Ensemble server. In the class Demo.REST.DirectoryOperation, there is a line that uses the macro $$$URLENCODE. I would like to know exactly what does this macro $$$URLENCODE() do. Specifically what value does it. Unfortunately, I can't find anything about this macro in the Ensemble Documentation.

Discussion (2)0
Log in or sign up to continue

It's defined in as:

#define URLENCODE(%string) $zconvert($zconvert(%string,"O",$replace($$$GETIO,"JSML","UTF8")),"O","URL")

See documentation on $ZCONVERT as well. This mentions:

“UTF8” which converts (output mode) 16-bit Unicode characters to a series of 8-bit characters. Thus, the characters $CHAR(0) through $CHAR(127) are the same in RAW and UTF8 mode; characters $CHAR(128) and above are converted.

“URL” which adds (output mode) or removes (input mode) URL parameter escape characters to a string. Characters higher than $CHAR(255) are represented in Unicode hexadecimal notation: $CHAR(256) = %u0100.

So, in short, $$$URLENCODE converts the input from (possibly) 16-bit to 8-bit characters, then adds URL parameter escape characters where they're needed. (For example, escaping slashes.)