Skip to content

Commit

Permalink
gsub with fixed=TRUE (fix tidyverse#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Apr 29, 2013
1 parent 043147b commit 76bfdb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions R/guess.r
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ guess_formats <- function(x, orders, locale = Sys.getlocale("LC_TIME"),
p <- p[nzchar(p)]
alpha["p"] <-
if ( length(p) == 0L ) ""
else sprintf("(?<p>%s)(?![[:alpha:]])", paste(p, collapse = "|"))
else sprintf("(?<p>%s)(?![[:alpha:]])", paste(p, collapse = "|"))

alpha <- unlist(alpha)

Expand Down Expand Up @@ -405,10 +405,10 @@ guess_formats <- function(x, orders, locale = Sys.getlocale("LC_TIME"),

num_exact <- num_flex <- num
num_flex[] <- sprintf("%s(?!\\d)", num)

num_exact[] <- gsub("(?<!\\()\\?(?!<)", "", perl = T, # remove ?
gsub("+", "*", fixed = T,
gsub(">", "_e>", num))) # append _e to avoid duplicates
## it is crittcal tu use fixed = TRUE because of the multibyte bug #181
num_exact[] <- gsub("(?<!\\()\\?(?!<)", "", perl = TRUE, # remove ?
gsub("+", "*", fixed = TRUE,
gsub(">", "_e>", num, fixed = TRUE))) # append _e to avoid duplicates

num_flex["m"] <- sprintf("((?<m>1[0-2]|0?[1-9](?!\\d))|(%s))", gsub("_[bB]", "\\1_m", alpha[["b"]]))
num_exact["m"] <- sprintf("((?<m_e>1[0-2]|0[1-9])|(%s))", gsub("_[bB]", "\\1_m_e>", alpha[["b"]]))
Expand Down
4 changes: 3 additions & 1 deletion inst/tests/test-parsers.R
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ test_that("ymd_hms parses OO and Oo formats correctly", {
## x_RU2 <- "Вт. 2012 авг. 14 11:52:57 "
## ymd_hms(c(x_RU, x_RU2), locale = "ru_RU.utf8")

## Sys.setlocale("LC_TIME", "ja_JP.utf8")
## format(Sys.time(), format = "%A %Y %B %d %I:%M:%S %p")

## gsub("([].|(){^$*+?[])", "\\\\\\1", "sdfs.")

Expand All @@ -561,4 +563,4 @@ test_that("ymd_hms parses OO and Oo formats correctly", {
## guess_formats("101010202020", "ymdT")
## guess_formats("001020", "ymd")

## guess_formats("10 am", "r")
## guess_formats("10 am", "r")

0 comments on commit 76bfdb5

Please sign in to comment.