Skip to content

Commit 3a3f305

Browse files
committed
Drop direct use of LEVELS in R >= 4.5
getCharCE appeared in R-2.7, making it possible to check for strings _marked_ as UTF-8 or Latin-1. There's no explicit encoding code for ASCII, and charIsASCII() ("eapi") is to appear in R-4.5.0.
1 parent 40ad2e6 commit 3a3f305

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/bmerge.c

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ Differences over standard binary search (e.g. bsearch in stdlib.h) :
1717
o non equi joins (no != yet) since 1.9.8
1818
*/
1919

20-
#define ENC_KNOWN(x) (LEVELS(x) & 12)
21-
// 12 = LATIN1_MASK (1<<2) | UTF8_MASK (1<<3) // Would use these definitions from Defn.h, but that appears to be private to R. Hence 12.
22-
2320
#define EQ 1
2421
#define LE 2
2522
#define LT 3

src/data.table.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@
3333
// #include <signal.h> // the debugging machinery + breakpoint aidee
3434
// raise(SIGINT);
3535

36-
#define IS_UTF8(x) (LEVELS(x) & 8)
37-
#define IS_ASCII(x) (LEVELS(x) & 64)
38-
#define IS_LATIN(x) (LEVELS(x) & 4)
36+
/* we mean the encoding bits, not CE_NATIVE in a UTF-8 locale */
37+
#define IS_UTF8(x) (getCharCE(x) == CE_UTF8)
38+
#define IS_LATIN(x) (getCharCE(x) == CE_LATIN1)
39+
#if R_VERSION < R_Version(4, 5, 0)
40+
# define IS_ASCII(x) (LEVELS(x) & 64)
41+
#else
42+
# define IS_ASCII(x) (Rf_charIsASCII(x)) // no CE_ASCII
43+
#endif
3944
#define IS_TRUE(x) (TYPEOF(x)==LGLSXP && LENGTH(x)==1 && LOGICAL(x)[0]==TRUE)
4045
#define IS_FALSE(x) (TYPEOF(x)==LGLSXP && LENGTH(x)==1 && LOGICAL(x)[0]==FALSE)
4146
#define IS_TRUE_OR_FALSE(x) (TYPEOF(x)==LGLSXP && LENGTH(x)==1 && LOGICAL(x)[0]!=NA_LOGICAL)

0 commit comments

Comments
 (0)