The R Project SVN R

Rev

Rev 68948 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 74545
Line 1... Line 1...
1
% File src/library/base/man/validUTF8.Rd
1
% File src/library/base/man/validUTF8.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 2015 R Core Team
3
% Copyright 2015-2018 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{validUTF8}
6
\name{validUTF8}
-
 
7
\title{Check if a Character Vector is Validly Encoded}
7
\alias{validUTF8}
8
\alias{validUTF8}
8
\alias{validEnc}
9
\alias{validEnc}
9
\title{
-
 
10
  Check if a Character Vector is Validly Encoded
-
 
11
}
-
 
12
 
-
 
13
\description{
10
\description{
14
  Check if each element of a character vector is valid in its implied
11
  Check if each element of a character vector is valid in its implied
15
  encoding.
12
  encoding.
16
}
13
}
17
 
-
 
18
\usage{
14
\usage{
19
validUTF8(x)
15
validUTF8(x)
20
 
-
 
21
validEnc(x)
16
validEnc(x)
22
}
17
}
23
 
18
 
24
\arguments{
19
\arguments{
25
  \item{x}{A character vector.}
20
  \item{x}{a character vector.}
26
}
21
}
27
 
22
 
28
\details{
23
\details{
29
  These use similar checks to those used by functions such as
24
  These use similar checks to those used by functions such as
30
  \code{\link{grep}}.
25
  \code{\link{grep}}.
Line 60... Line 55...
60
   ## from a CRAN check log
55
   ## from a CRAN check log
61
   "\xfa\xb4\xbf\xbf\x9f")
56
   "\xfa\xb4\xbf\xbf\x9f")
62
validUTF8(x)
57
validUTF8(x)
63
validEnc(x) # depends on the locale
58
validEnc(x) # depends on the locale
64
Encoding(x) <-"UTF-8"
59
Encoding(x) <-"UTF-8"
-
 
60
validEnc(x) # typically the last, x[10], is invalid
-
 
61
 
-
 
62
## Maybe advantageous to declare it "unknown":
-
 
63
G <- x ; Encoding(G[!validEnc(G)]) <- "unknown"
-
 
64
try( substr(x, 1,1) ) # gives 'invalid multibyte string' error
-
 
65
try( substr(G, 1,1) ) # works
-
 
66
nchar(G) # fine, too
-
 
67
## but it is not "more valid" typically:
65
validEnc(x)
68
all.equal(validEnc(x),
-
 
69
          validEnc(G)) # typically TRUE
66
}
70
}