R/check_word.R

#' Check word
#'
#' Check a word against a list of `MySQL` keywords to see if it is a keyword and if so; whether or not it is reserved
#'
#' @param x a word to check
#' @export
#' @examples
#' check_word('name')
#'
#' check_word('create')
#'

check_word <- function(x)
{
  if (!is.character(x)) {
    stop(deparse(substitute(x)), ' must be a character')
  }

  x <- toupper(x)

  gidx <- grep(x, keywords$value)

  matches <- keywords[gidx, ]

  message(crayon::yellow('input:', toupper(x)))

  message(
    'VALUE',
    '\t',
    'RESERVED (',
    clisymbols::symbol$tick,
    '/',
    clisymbols::symbol$cross,
    ')'
  )
  message('-------------------')
  for (i in seq_along(gidx)) {
    if (matches$reserved[i] == 'TRUE')
      message(crayon::green(matches$value[i]),
              '\t',
              clisymbols::symbol$tick)

    if (matches$reserved[i] == 'FALSE')
      message(crayon::green(matches$value[i]),
              '\t',
              clisymbols::symbol$cross)
  }

  return(invisible(NULL))
}
wilsontom/MyRW documentation built on May 26, 2019, 6:36 a.m.