Rev 73490 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/utf8Conversion.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2017 R Core Team% Distributed under GPL 2 or later\name{utf8Conversion}\alias{utf8ToInt}\alias{intToUtf8}\alias{Unicode}\alias{code point}\title{Convert Integer Vectors to or from UTF-8-encoded Character Vectors}\description{Conversion of UTF-8 encoded character vectors to and from integervectors representing a UTF-32 encoding.}\usage{utf8ToInt(x)intToUtf8(x, multiple = FALSE)}\arguments{\item{x}{object to be converted.}\item{multiple}{logical: should the conversion be to a singlecharacter string or multiple individual characters?}}\details{These will work in any locale, including on platforms that do nototherwise support multi-byte character sets.Unicode defines a name and a number of all of the glyphs itencompasses: the numbers are called \emph{code points}: since RFC3629they run from \code{0} to \code{0x10FFFF} (with about 12\% beingassigned by version 10.0 of the Unicode standard).\code{intToUtf8} does not handle surrogate pairs (which should notoccur in UTF-32): inputs in the surrogate ranges are mapped to\code{NA}.}\value{\code{utf8ToInt} converts a length-one character string encoded inUTF-8 to an integer vector of Unicode code points. It checks validityof the input. (Currently it accepts UTF-8 encodings of code pointsgreater than \code{0x10FFFF}: these are no longer regarded as valid bythe UTF-8 RFC and will in future be mapped to \code{NA}. Following\sQuote{Corrigendum 9} the UTF-8 encodings of the\sQuote{noncharacters} \code{0xFFFE} and \code{0xFFFF} are regarded asvalid as from \R 3.4.3.)\code{intToUtf8} converts a numeric vector of Unicode code pointseither (default) to a single character string or a character vector ofsingle characters. Non-integral numeric values are truncated tointegers: values above the maximum are mapped to \code{NA}. For asingle character string \code{0} is silently omitted: otherwise\code{0} is mapped to \code{""}. The \code{\link{Encoding}} of anon-\code{NA} return value is declared as \code{"UTF-8"}.Invalid and \code{NA} inputs are mapped to \code{NA} output.}\references{\url{https://tools.ietf.org/html/rfc3629}, the current standard for UTF-8.\url{http://www.unicode.org/versions/corrigendum9.html} for non-characters.}\examples{\donttest{## will only display in some locales and fontsintToUtf8(0x03B2L) # Greek beta}utf8ToInt("bi\u00dfchen")utf8ToInt("\xfa\xb4\xbf\xbf\x9f")}\keyword{character}\keyword{utilities}