Argument `x` contains an illegal non-ASCII byte at index [1], see `?unhandled_ctl`.

Error in substr_ctl_internal(x, start = start, stop = stop, type.int = TYPE.INT,  : 
  Argument `x` contains an illegal non-ASCII byte at index [1], see `?unhandled_ctl`.

identical(substr_ctl(b.test, 0, 3), substr(b.test, 0, 3))

identical(substr_ctl(b.test, 0, 2), substr(b.test, 0, 2))

identical(substr_ctl(b.test, 1, 2), substr(b.test, 1, 2))

identical(substr_ctl(b.test, 0, 4), substr(b.test, 0, 4))

identical(substr_ctl(b.test, 4, 4), substr(b.test, 4, 4))

substr2_ctl(b.t.c, 0, 0, type = "width")

substr2_ctl(b.t.c, 0, 2, type = "width")

substr2_ctl(b.t.c, 1, 4, type = "width")

substr2_ctl(b.t.c, 0, 5, type = "width")

substr2_ctl(b.t.c, 5, 5, type = "width")

substr_ctl(b.t.c, 0, 4, terminate = FALSE)

substr2_ctl(b.t.c, 1, 4, terminate = FALSE, type = "width")

hello.illegal <- c("hello", "ð", "ðaaaa")

Argument `x` contains a malformed UTF-8 sequence at index [2], see `?unhandled_ctl`.

Error in nchar_ctl_internal(x = x, type.int = TYPE.INT, allowNA = allowNA,  : 
  Argument `x` contains a malformed UTF-8 sequence at index [2], see `?unhandled_ctl`.

# nzchar doesn't care about multi-byte illegal

nchar_ctl(c(esc.1, esc.2, "hello"), warn = FALSE)

esc.4 <- c(sprintf("\033[31m%shello", w1), NA, hello.illegal)

nchar_sgr(esc.4, type = "width", keepNA = FALSE, warn = FALSE, 
    allowNA = TRUE)

nzchar_sgr(esc.4, keepNA = FALSE, warn = FALSE)

nchar_sgr("\033[31m\thello", type = "width") >= nchar_ctl("\033[31m\thello", 
    type = "width")

# _sgr does not strip C0; note R behavior on width of C0-C1
# fluctuating around R4.1 transition so can't test directly.

# nchar doesn't care about bad bits embedded in escapes

index start stop             error translated      esc
1     1     6    7     malformed-ESC      FALSE \033\033
2     1     8   12 non-SGR/hyperlink      FALSE \033[45p
3     1    14   14    malformed-UTF8      FALSE     <f0>
4     1    22   22                C0      FALSE       \a

index start stop          error translated  esc
1     1     7    7 malformed-UTF8      FALSE <f0>