ORD()
The ORD()
operator
returns the code point of a character in the current locale.
Syntax
ORD( source STRING )
- source is a string expression.
Usage
The value returned by ORD()
is the code point in the current locale of the
character passed as argument, or the first byte of the encoded character.
Only the first character (or byte) of the character string argument is evaluated.
The ORD()
operator returns NULL
, if the argument passed is not
valid.
The processing of the character byte sequence depends on the application locale and the length semantics setting:
- With a SBCS encoding like ISO-8859-15 (and byte length semantics),
ORD()
returns the code point of the first SBCS byte / character, in the current charset. - With UTF-8 encoding and CHAR length semantics,
ORD()
returns the UNICODE code point of the first character. - With UTF-8 encoding and BYTE length semantics,
ORD()
returns the value of the first byte of the first character.
The next example shows the behavior of
ORD()
, depending on the character set and
length semantics, on a Linux platform:MAIN
DEFINE src STRING
DISPLAY "LC_ALL : ", fgl_getenv("LC_ALL")
DISPLAY "FGL_LENGTH_SEMANTICS: ", fgl_getenv("FGL_LENGTH_SEMANTICS")
LET src = arg_val(1)
DISPLAY "src : ",src
DISPLAY "ORD(s) : ",ORD(src)
END MAIN
ISO-8859-15 + BYTE length semantics (with terminal using ISO-8859-15
encoding):
$ export LC_ALL="en_US.iso8859-15"
$ export FGL_LENGTH_SEMANTICS="BYTE"
$ fglrun ord.42m "ôxx"
LC_ALL : en_US.iso8859-15
FGL_LENGTH_SEMANTICS: BYTE
src : ôxx
ORD(s) : 244 <-- ISO-8859-15 code point (0xF4) of ô
UTF-8 + CHAR length semantics (with terminal using UTF-8
encoding):
$ export LC_ALL="en_US.utf-8"
$ export FGL_LENGTH_SEMANTICS="CHAR"
$ fglrun ord.42m "愛xx"
LC_ALL : en_US.utf-8
FGL_LENGTH_SEMANTICS: CHAR
src : 愛xx
ORD(s) : 24859 <-- UNICODE code point of 愛
UTF-8 + BYTE length semantics (with terminal using UTF-8
encoding):
$ export LC_ALL="en_US.utf-8"
$ export FGL_LENGTH_SEMANTICS="BYTE"
$ fglrun ord.42m "愛xx"
LC_ALL : en_US.utf-8
FGL_LENGTH_SEMANTICS: BYTE
src : 愛xx
ORD(s) : 230 <-- first UTF-8 byte (0xE6) of 愛