R/istitle.R

Defines functions strs_istitle

Documented in strs_istitle

#' Check if string is in title case
#'
#' `strs_istitle` checks whether each element of a character vector is title
#' case. This is similar to Python's `str.istitle` method.
#'
#' @param string A character vector where each element is a string to be
#' checked.
#' @return A logical vector of the same length as `string`, indicating whether
#' each element is in title case.
#' @examples
#' strs_istitle("This Is Title Case")
#' strs_istitle("not title case")
#' strs_istitle("123 Another Example")
#' @seealso [Python str.istitle() documentation](https://docs.python.org/3/library/stdtypes.html#str.istitle)
#' @export
strs_istitle <- function(string) {
  !stringi::stri_detect_regex(
    string,
    pattern = "\\b\\p{Ll}"
  )
}

Try the strs package in your browser

Any scripts or data that you put into this service are public.

strs documentation built on Sept. 11, 2024, 6:44 p.m.