# WARNING - Generated by {fusen} from dev/flat_kwb_simulate_inflow.Rmd: do not edit by hand # nolint: line_length_linter.

#' Quote Character Strings
#' 
#' quotes objects of type character with quoting character
#' 
#' This function does the same thing as kwb.utils::hsQuoteChr(),
#' but it is bundled with *ambre* to avoid a hard dependency on the 
#' unmaintained package.
#' 
#' @param x vector or list of character strings
#' @param qchar quoting character to be used. Default: single quote "'"
#' @param escapeMethod one of \code{"double", "backslash", "none"} deciding
#'   how to treat the quote character if it occurs within the string to be
#'   quoted
#' @references
#'   Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0
#'   URL: \url{https://github.com/kwb-r/kwb.utils}
#'   (MIT Licence)
#' @noRd
#' 
#' @examples
#' # Example usage of hsQuoteChr
#' hsQuoteChr("Hello, world!", qchar = "'")
#' hsQuoteChr("He said, 'Hello!'", qchar = "'", escapeMethod = "backslash")
#' hsQuoteChr("He said, 'Hello!'", qchar = "'", escapeMethod = "double")
hsQuoteChr <- function(
  x, qchar = "'", escapeMethod = c("double", "backslash", "none")
) 
{
  if (mode(x) == "list") {
    
    len <- length(x)
    
    if (len == 0) return (NULL)
    
    if (len == 1) return (hsQuoteChr(x[[1]]))
    
    return (c(hsQuoteChr(x[[1]]), hsQuoteChr(x[-1])))
  }
  
  escapeChars <- list(double = qchar, backslash = '\\', none = "")
  
  if (mode(x) == "character") {
    
    escapeChar <- escapeChars[[escapeMethod[1]]]
    
    x.escaped <- gsub(qchar, paste0(escapeChar, qchar), x)
    
    return (paste0(qchar, x.escaped, qchar))
  }
  
  x
}
