## 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.

hello.0 <- "hello world this is a lovely day"

# We do not want to use `base::strwrap` because it triggers the pcre valgrind
# error on heap allocations (this is not a fansi problem)

# identical(strwrap_ctl(hello.0, width=10), strwrap(hello.0, width=10))

[1] "hello"     "world"     "this is a" "lovely"    "day"

hello.1 <- "hello  world  this  is.  a lovely day."

# identical(strwrap_ctl(hello.1, width=10), strwrap(hello.1, width=10))

[1] "hello"    "world"    "this is." "a lovely" "day."

hello.2 <- "hello\rworld\rthis  is.  a lovely day."

# identical(strwrap(hello.2, width=10), strwrap_ctl(hello.2, width=10))

Argument `x` contains a C0 control character at index [1], see `?unhandled_ctl`; you can use `warn=FALSE` to turn off these warnings.

[1] "hello\rworld\rthis" "is.  a"             "lovely"            
[4] "day."

Warning in strwrap2_ctl(x = x, width = width, indent = indent, exdent = exdent,  :
  Argument `x` contains a C0 control character at index [1], see `?unhandled_ctl`; you can use `warn=FALSE` to turn off these warnings.

hello.3 <- "hello\rworld\nthis  is.  a lovely\n day."

# identical(strwrap(hello.3, width=10), strwrap_ctl(hello.3, width=10))

[1] "hello\rworld" "this is."     "a lovely"     "day."

hello.4 <- "  hello  world  this  is  a lovely day."

# identical(strwrap(hello.4, width=10), strwrap_ctl(hello.4, width=10))

[1] "hello"     "world"     "this is a" "lovely"    "day."