R/utf8_encode.R

Defines functions utf8_encode

Documented in utf8_encode

#  Copyright 2017 Patrick O. Perry.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

utf8_encode <- function(x, width = 0L, quote = FALSE, justify = "left",
                        escapes = NULL, display = FALSE, utf8 = NULL) {
  if (is.null(x)) {
    return(NULL)
  }

  if (!is.character(x)) {
    stop("argument is not a character object")
  }

  with_rethrow({
    width <- as_integer_scalar("width", width)
    quote <- as_option("quote", quote)
    justify <- as_justify("justify", justify)
    escapes <- as_style("escapes", escapes)
    display <- as_option("display", display)
    utf8 <- as_output_utf8("utf8", utf8)
  })

  .Call(rutf8_utf8_encode, x, width, quote, justify, escapes, display, utf8)
}
patperry/r-utf8 documentation built on Jan. 26, 2024, 12:59 a.m.