| Line 23... |
Line 23... |
| 23 |
|
23 |
|
| 24 |
## iconv() with substitution:
|
24 |
## iconv() with substitution:
|
| 25 |
iconv(c(x, xx), to = "ASCII", sub = NA) # default
|
25 |
iconv(c(x, xx), to = "ASCII", sub = NA) # default
|
| 26 |
## often both NA, but could still use substitution ("a**car" with musl's iconv)
|
26 |
## often both NA, but could still use substitution ("a**car" with musl's iconv)
|
| 27 |
stopifnot(length(tools::showNonASCII(c(x, xx))) == 2L) # robust via string comparison
|
27 |
stopifnot(length(tools::showNonASCII(c(x, xx))) == 2L) # robust via string comparison
|
| 28 |
## output for most iconvs (at least GNU libiconv, glibc, win_iconv):
|
28 |
## output for most iconvs (at least GNU libiconv, glibc, win_iconv, macOS >= 14):
|
| 29 |
## 1: a<e7><fa>car
|
29 |
## 1: a<e7><fa>car
|
| 30 |
## 2: a<c3><a7><c3><ba>car
|
30 |
## 2: a<c3><a7><c3><ba>car
|
| 31 |
## musl:
|
31 |
## musl:
|
| 32 |
## 1: a**car
|
32 |
## 1: a**car
|
| 33 |
## 2: a****car
|
33 |
## 2: a****car
|
| Line 49... |
Line 49... |
| 49 |
chkEQpr(iconv(z, "UTF-8", "ASCII", "byte"), "<f0><9f><98><80>")
|
49 |
chkEQpr(iconv(z, "UTF-8", "ASCII", "byte"), "<f0><9f><98><80>")
|
| 50 |
chkEQpr(iconv(z, "UTF-8", "ASCII", "Unicode"), "<U+1F600>")
|
50 |
chkEQpr(iconv(z, "UTF-8", "ASCII", "Unicode"), "<U+1F600>")
|
| 51 |
chkEQpr(iconv(z, "UTF-8", "ASCII", "c99" ), "\\U0001f600")
|
51 |
chkEQpr(iconv(z, "UTF-8", "ASCII", "c99" ), "\\U0001f600")
|
| 52 |
})
|
52 |
})
|
| 53 |
|
53 |
|
| 54 |
## write out to compare with GNU libiconv's iconv on e.g. macOS
|
54 |
## write out to compare with GNU libiconv's iconv on e.g. macOS < 14
|
| 55 |
## The reading can only work in a UTF-8 locale
|
55 |
## The reading can only work in a UTF-8 locale
|
| 56 |
if(startsWith(iconv_version, 'GNU libiconv') &&
|
56 |
if(startsWith(iconv_version, 'GNU libiconv') &&
|
| 57 |
l10n_info()[["UTF-8"]]) {
|
57 |
l10n_info()[["UTF-8"]]) {
|
| 58 |
writeLines(c(xx, z), "test.txt")
|
58 |
writeLines(c(xx, z), "test.txt")
|
| 59 |
zz <- system2("iconv", c("-f", "UTF-8", "-t", "c99", "test.txt"),
|
59 |
zz <- system2("iconv", c("-f", "UTF-8", "-t", "c99", "test.txt"),
|