## Copyright (C) 2022 Brodie Gaslam
##
## This file is part of "fansi - ANSI Control Sequence Aware String Functions"
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 or 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## Go to <https://www.r-project.org/Licenses> for copies of the licenses.

nchar_ctl(c("hello", "world"), type = "width")

nchar_ctl(c("hello", "world"), type = "wi")

identical(nchar_ctl(na.world, keepNA = FALSE), nchar(na.world, 
    keepNA = FALSE))

identical(nchar_ctl(na.world, keepNA = NA, type = "width"), nchar(na.world, 
    keepNA = NA, type = "width"))

identical(nchar_ctl(na.world, keepNA = TRUE, type = "width"), 
    nchar(na.world, keepNA = TRUE, type = "width"))

identical(nzchar_ctl(na.world, keepNA = TRUE), nzchar(na.world, 
    keepNA = TRUE))

identical(nzchar_ctl(na.world, keepNA = NA), nzchar(na.world, 
    keepNA = NA))

identical(nchar_ctl(na.world, type = "bytes"), nchar(na.world, 
    type = "bytes"))

identical(nchar_ctl(na.world, keepNA = FALSE, type = "bytes"), 
    nchar(na.world, keepNA = FALSE, type = "bytes"))

identical(nchar_ctl(na.world, keepNA = TRUE, type = "bytes"), 
    nchar(na.world, keepNA = TRUE, type = "bytes"))

w.dim <- matrix(letters[1:6], 2, 3, dimnames = list(X = LETTERS[2:3], 
    Y = LETTERS[24:26]))

if (isTRUE(l10n_info()[["UTF-8"]])) {
    inherits(try(nchar_ctl(x), silent = TRUE), "try-error")
} else TRUE

# don't translate unknown in UTF-8 locale

Argument `x` contains a malformed UTF-8 sequence at index [1], 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 [1], see `?unhandled_ctl`.