Skip to content

Commit

Permalink
Remove old implementation of plu_ral()
Browse files Browse the repository at this point in the history
  • Loading branch information
rossellhayes committed Jan 11, 2021
1 parent a7fc061 commit 6b54a91
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions R/plu_ral.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,94 +128,6 @@ plu_ral <- function(
x
}

plu_ral2 <- function(
x, vector = integer(2), n_fn = NULL, ...,
n = length(vector), pl = abs(n) != 1,
irregulars = c("moderate", "conservative", "liberal", "none"),
replace_n = TRUE
) {
if (!length(x)) {return(character(0))}
if (!is.character(x)) {rlang::abort("`x` must be a character vector")}

if (length(n) != 1) {rlang::abort("`n` must be length one")}
if (!is.numeric(n)) {rlang::abort("`n` must be numeric")}

if (length(pl) != 1) {rlang::abort("`pl` must be length one")}
if (!is.logical(pl) | is.na(pl)) {rlang::abort("`pl` must be TRUE or FALSE")}

if (length(replace_n) != 1) {rlang::abort("`replace_n` must be length one")}
if (!is.logical(replace_n) | is.na(replace_n)) {
rlang::abort("`replace_n` must be TRUE or FALSE")
}

if (length(x) > 1) {
return(
vapply(
x, plu_ral, character(1), USE.NAMES = !is.null(names(x)),
vector = vector, n_fn = n_fn, ..., n = n, pl = pl,
irregulars = irregulars, replace_n = replace_n
)
)
}

if (nchar(x) > 1) {
x <- c(
stringi::stri_split_boundaries(x, type = "sentence"),
recursive = TRUE
)

if (length(x) > 1) {
return(
paste(
vapply(
x, plu_ral, character(1), USE.NAMES = FALSE,
vector = vector, n_fn = n_fn, ..., n = n, pl = pl,
irregulars = irregulars, replace_n = replace_n
),
collapse = ""
)
)
}
}

start_space <- substr(x, 1, 1) == " "
end_space <- substr(x, nchar_x <- nchar(x), nchar_x) == " "
start_caps <- isTRUE(is_capitalized(x))

if (pl) {
x <- unlist(strsplit(x, "(?=[^A-Za-z0-9'\\-{])(?![^{]*})", perl = TRUE))

braced <- grepl(paste0("\\{|\\}", ifelse(replace_n, "|\\bn\\b", "")), x)
x[!braced] <- plu_ralize(x[!braced], irregulars = irregulars)
x <- paste(x, collapse = "")
}

x <- gsub(
"\\{([^{}\\|]*?)\\|([^{}\\|]*?)\\|([^{}\\|]*?)\\}",
ifelse(abs(n) == 1, "\\1", ifelse(abs(n) == 2, "\\2", "\\3")),
x
)
x <- gsub(
"\\{([^{}\\|]*?)\\|([^{}\\|]*?)\\}",
ifelse(abs(n) == 1, "\\1", "\\2"),
x
)

if (replace_n) {
n_fn <- get_fun(n_fn)
x <- gsub("\\bn\\b", n_fn(n, ...), x)
}

x <- gsub("\\{([^{}]*)\\}", "\\1", x)
x <- plu_nge(x, ends = TRUE)

if (start_space) x <- paste0(" ", x)
if (end_space) x <- paste0(x, " ")
if (start_caps) x <- capitalize(x)

x
}

#' @rdname plu_ral
#' @export

Expand Down

0 comments on commit 6b54a91

Please sign in to comment.