A drop-in replacement for base::strsplit. It will be noticeably slower, but should otherwise behave the same way except for CSI SGR sequence awareness.
strsplit_ctl(x, split, fixed = FALSE, perl = FALSE, useBytes = FALSE,
warn = getOption("fansi.warn"), term.cap = getOption("fansi.term.cap"))
a character vector, or, unlike base::strsplit an object that can be coerced to character.
character vector (or object which can be coerced to such)
containing regular expression(s) (unless fixed = TRUE
)
to use for splitting. If empty matches occur, in particular if
split
has length 0, x
is split into single characters.
If split
has length greater than 1, it is re-cycled along
x
.
logical. If TRUE
match split
exactly, otherwise
use regular expressions. Has priority over perl
.
logical. Should Perl-compatible regexps be used?
logical. If TRUE
the matching is done
byte-by-byte rather than character-by-character, and inputs with
marked encodings are not converted. This is forced (with a warning)
if any input is found which is marked as "bytes"
(see Encoding
).
TRUE (default) or FALSE, whether to warn when potentially
problematic Control Sequences are encountered. These could cause the
assumptions fansi
makes about how strings are rendered on your display
to be incorrect, for example by moving the cursor (see fansi).
character a vector of the capabilities of the terminal, can
be any combination "bright" (SGR codes 90-97, 100-107), "256" (SGR codes
starting with "38;5" or "48;5"), and "truecolor" (SGR codes starting with
"38;2" or "48;2"). Changing this parameter changes how fansi
interprets
escape sequences, so you should ensure that it matches your terminal
capabilities. See term_cap_test for details.
list, see base::strsplit.
fansi for details on how Control Sequences are interpreted, particularly if you are getting unexpected results, base::strsplit for details on the splitting.
# NOT RUN {
strsplit_ctl("\033[31mhello\033[42m world!", " ")
# }
Run the code above in your browser using DataCamp Workspace