Skip to content

Commit

Permalink
Drop direct use of LEVELS in R >= 4.5
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aitap committed Aug 28, 2024
1 parent 40ad2e6 commit 3a3f305
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/bmerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ Differences over standard binary search (e.g. bsearch in stdlib.h) :
o non equi joins (no != yet) since 1.9.8
*/

#define ENC_KNOWN(x) (LEVELS(x) & 12)
// 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.

#define EQ 1
#define LE 2
#define LT 3
Expand Down
11 changes: 8 additions & 3 deletions src/data.table.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@
// #include <signal.h> // the debugging machinery + breakpoint aidee
// raise(SIGINT);

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

0 comments on commit 3a3f305

Please sign in to comment.