Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > strings and nets > utf8
next | previous | forward | backward | up | index | toc

utf8 -- encode and decode unicode utf-8-encoded strings



  • Usage:
    utf8 x
  • Inputs:
    • x, a list, a list of small natural numbers to serve as character codes
  • Outputs:
    • a string, a string obtained by encoding the character codes in x according to the utf-8 encoding standard
i1 : s = utf8 {119, 111, 51, 32, 25105}

o1 = wo3 我


  • Usage:
    utf8 s
  • Inputs:
  • Outputs:
    • a list, a list of the integer codes obtained by decoding the string s according to the utf-8 encoding standard
i2 : utf8 s

o2 = {119, 111, 51, 32, 25105}

o2 : List

The two operations described above are inverse to each other.

The function utf8check can be used to verify that a string contains a valid uft8-encoding of a sequence of unicode characters. It returns null upon success, and signals an error otherwise.

i3 : try utf8check "你好" else "invalid"
i4 : try utf8check "\200\200" else "invalid"

o4 = invalid

See also

For the programmer

The object utf8 is a compiled function.