docs.intersystems.com
InterSystems IRIS Data Platform 2019.2  /  ObjectScript Reference

ObjectScript Reference
$WREVERSE
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


Returns the characters in a string in reverse order, recognizing surrogate pairs.
Synopsis
$WREVERSE(string)
$WRE(string)
Parameter
string A string or expression that evaluates to a string.
Description
$WREVERSE returns the characters in string in reverse order. $WREVERSE is functionally identical to $REVERSE, except that $WREVERSE recognizes surrogate pairs. You can use the $WISWIDE function to determine if a string contains a surrogate pair.
A surrogate pair is a pair of 16-bit InterSystems IRIS character elements that together encode a single Unicode character. Surrogate pairs are used to represent certain ideographs which are used in Chinese, Japanese kanji, and Korean hanja. (Most commonly-used Chinese, kanji, and hanja characters are represented by standard 16-bit Unicode encodings.) Surrogate pairs provide InterSystems IRIS support for the Japanese JIS X0213:2004 (JIS2004) encoding standard and the Chinese GB18030 encoding standard.
A surrogate pair consists of high-order 16-bit character element in the hexadecimal range D800 through DBFF, and a low-order 16-bit character element in the hexadecimal range DC00 through DFFF.
The $WREVERSE function counts a surrogate pair as a single character. The $REVERSE function treats a surrogate pair as two characters. In all other aspects, $WREVERSE and $REVERSE are functionally identical. However, because $REVERSE is generally faster than $WREVERSE, $REVERSE is preferable for all cases where a surrogate pair is not likely to be encountered.
For further details on reversing strings, refer to the $REVERSE function.
Example
The following example shows how $WREVERSE treats a surrogate pair as a single character:
  SET spair=$CHAR($ZHEX("D806"),$ZHEX("DC06"))
  SET str="AB"_spair_"CD"
    WRITE !,"String before reversing:"
    ZZDUMP str
  SET wrev=$WREVERSE(str)
    WRITE !,"$WREVERSE did not reverse surrogate pair:"
    ZZDUMP wrev
  SET rev=$REVERSE(str)
    WRITE !,"$REVERSE reversed surrogate pair:"
    ZZDUMP rev
See Also


Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-08-22 06:48:58