Skip to content

Commit

Permalink
add unexported char_to_hex() and char_to_unicode() utility functi…
Browse files Browse the repository at this point in the history
…ons (#62)

* add unexported `char_to_hex()` and `char_to_unicode()` utility functions

* Update char_to_.R

* Update char_to_.R
  • Loading branch information
cjyetman authored Jan 17, 2024
1 parent d34d2d0 commit 5d772d0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions R/char_to_.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# These functions return ascii representations of extended or unicode
# characters using hex or unicode R escape strings

char_to_hex <- function(x) {
cat(paste0("\"", paste0("\\x", charToRaw(x), collapse = ""), "\""))
}

char_to_unicode <- function(x) {
cat(paste0("\"\\U", format(as.hexmode(utf8ToInt(x)), width = 8, upper = TRUE), "\""))
}

0 comments on commit 5d772d0

Please sign in to comment.