library(fansi)
flags <- "🇦🇷🇦🇴🇦🇮"
nchar(flags, type = "chars")
nchar(flags, type = "width")
nchar_ctl(flags, type = "chars")
nchar_ctl(flags, type = "width")
nchar(substr2_ctl(flags, 1, 2))
nchar(substr2_ctl(flags, 1, 2, type = "width"))
flags <- paste0(rep("🇦🇿🇧🇾🇨🇽", 2), collapse = "")
strwrap2_ctl(flags, 6, wrap.always = TRUE, pad.end = " ", carry = "\033[44m")
strwrap2_ctl(flags, 7, wrap.always = TRUE, pad.end = " ", carry = "\033[44m")
flags.1 <- paste0("a", flags)
strwrap2_ctl(flags.1, 7, wrap.always = TRUE, pad.end = " ", carry = "\033[44m")
substr2_ctl(flags, 1, 1, type = "width")
substr2_ctl(flags, 1, 1, type = "width", round = "stop")
substr2_ctl(flags, 1, 2, type = "width", round = "neither")
substr2_ctl(flags, 2, 3, type = "width", round = "stop")
substr2_ctl(flags, 2, 3, type = "width", round = "start")
substr2_ctl(flags, 2, 3, type = "width", round = "both")
substr2_ctl(flags, 2, 3, type = "width", round = "neither")
emo.0 <- "👶🏽👨🏿👮🏿"
emo.1 <- "A_👨🏾‍🦳_B"
emo.2 <- "👨🏾‍🦳"
emo.2a <- paste0("_", emo.2, "^", emo.2)
nchar_ctl(c(emo.0, emo.1, emo.2), type = "width")
nchar_ctl(c(emo.0, emo.1, emo.2), type = "graphemes")
substr2_ctl(emo.0, 1, 1, type = "width")
substr2_ctl(emo.0, 1, 1, type = "width", round = "stop")
substr2_ctl(emo.0, 1, 2, type = "width", round = "stop")
substr2_ctl(emo.0, 2, 3, type = "width", round = "stop")
substr2_ctl(emo.0, 2, 3, type = "width", round = "start")
substr2_ctl(emo.0, 2, 3, type = "width", round = "both")
substr2_ctl(emo.0, 2, 3, type = "width", round = "neither")
substr2_ctl(emo.1, 1, 3, type = "width")
substr2_ctl(emo.1, 1, 3, type = "width", round = "stop")
substr2_ctl(emo.1, 3, 5, type = "width")
substr2_ctl(emo.1, 4, 5, type = "width")
emo.3 <- "👩🏽‍✈️"
emo.4 <- "👨‍👩‍👧‍👦"
emo.big <- rep(sprintf(paste0("once upon a time %s there was a humpty %s%s dumpty %s on the wall %s", 
    "and he had %s a %s big fall %s oh no %s"), flags, emo.0, 
    emo.0, emo.1, emo.2, emo.3, emo.4, emo.3, emo.2), 2)
strwrap2_ctl(emo.big, 10, wrap.always = TRUE, carry = "\033[44m", 
    pad.end = " ")
emo.6 <- c(emo.0, emo.2a, emo.4)
substr2_ctl(emo.6, 1, 2, type = "graphemes")
substr2_ctl(emo.6, 1, 3, type = "graphemes")
substr2_ctl(emo.6, 2, 3, type = "graphemes")
substr2_ctl(emo.6, 3, 3, type = "graphemes")
emo.5 <- "👶\033[43m🏽###\033[m"
Encoding(emo.5) <- "UTF-8"
substr2_ctl(emo.5, 1, 2, type = "width")
substr2_ctl(emo.5, 2, 3, type = "width")
nchar_ctl(emo.5, type = "width")
nchar_ctl(emo.5, type = "grapheme")
emo.0.1 <- paste0("\033[33m", substr2_ctl(emo.0, 1, 1, type = "graphemes"), 
    "\033[45m")
substr2_ctl(emo.0.1, 2, 2, type = "width")
substr2_ctl(emo.0.1, 2, 2, type = "width", terminate = FALSE)
substr2_ctl(emo.0.1, 1, 1, type = "width", round = "stop")
substr2_ctl(emo.0.1, 1, 3, type = "width")
substr2_ctl(emo.0.1, 1, 3, type = "width", terminate = FALSE)
substr2_ctl(emo.0.1, 1, 3, type = "width", round = "stop")
emo.0.2 <- paste0(emo.0.1, "\a")
substr2_ctl(emo.0.2, 1, 3, type = "width", round = "start")
emo.0.3 <- paste0(emo.0.1, "\a\033]8;;x.yz\033\\")
substr2_ctl(emo.0.3, 1, 3, type = "width", round = "start")
emo.0.4 <- paste0("\033]8;;x.yz\033\\", substr2_ctl(emo.0, 1, 
    1, type = "graphemes"), "\033]8;;w.ww\033\\", "\a", "\033[42m")
substr2_ctl(emo.0.4, 1, 3, type = "width")
substr2_ctl(emo.0.4, 1, 3, type = "width", terminate = FALSE)
substr2_ctl(emo.0.4, 1, 2, type = "width", terminate = FALSE)
substr2_ctl(emo.0.4, 1, 2, type = "width")
`substr2_ctl<-`(emo.1, 3, 4, value = emo.0)
`substr2_ctl<-`(emo.1, 3, 4, value = emo.0, type = "width")
`substr2_ctl<-`(emo.1, 4, 4, value = emo.0, type = "width")
`substr2_ctl<-`(emo.1, 4, 4, value = emo.0, type = "width", round = "stop")
`substr2_ctl<-`(emo.1, 4, 4, value = emo.0, type = "width", round = "neither")
`substr2_ctl<-`(emo.1, 4, 4, value = "#", type = "width")
`substr2_ctl<-`(emo.1, 4, 5, value = emo.0, type = "width")
x <- "ABCDEF"
`substr2_ctl<-`(x, 2, 4, value = emo.0, type = "width")
`substr2_ctl<-`(x, 2, 4, value = emo.0, type = "width", round = "stop")
`substr2_ctl<-`(x, 2, 5, value = emo.0, type = "width")
`substr2_ctl<-`(emo.1, 3, 4, value = emo.0, type = "width", round = "both")
`substr2_ctl<-`(emo.1, 4, 4, value = emo.0, type = "width", round = "both")
a <- c(rep(emo.1, 4), rep(x, 2))
b <- c(emo.0, "#", rep(emo.0, 4))
starts <- c(3, 4, 4, 4, 2, 2)
stops <- c(4, 4, 4, 5, 4, 5)
x <- a
substr2_ctl(x, starts, stops, type = "width") <- b
x
starts <- c(3, 4, 2, 3, 4, 2)
ends <- c(8, 9, 7, 7, 8, 6)
emo.3 <- rep(paste0("👧🏿🧔🏿", emo.0), length(starts))
emo.4 <- "👩‍🦱🤷👩‍⚕️"
x0 <- x1 <- emo.3
substr2_ctl(x0, starts, ends, type = "width") <- emo.4
x0
substr2_ctl(x1, starts, ends, type = "width", round = "stop") <- emo.4
x1
emo.7 <- "😀_😀"
emo.7a <- "😀"
`substr2_ctl<-`(emo.7, 3, 3, type = "width", round = "stop", 
    value = emo.7a)
`substr2_ctl<-`(emo.7, 3, 3, type = "width", round = "stop", 
    value = "##")
`substr2_ctl<-`(emo.7a, 2, 1, type = "width", round = "both", 
    value = emo.7a)