New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out why roxygen2 tests fail with dev stringr #99

Closed
hadley opened this Issue Oct 29, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@hadley
Member

hadley commented Oct 29, 2015

It's something to do with new str_replace behaviour

@hadley

This comment has been minimized.

Member

hadley commented Nov 4, 2015

Minimal reprex:

str_replace_all('"', '(["\\\\])', "\\\\\\1")
# [1] "\\1"

I'm reasonably certain the regular expression is correct, and it should return '\\"' (i.e. the goal is to insert an additional backslash in front of a double quote or backslash)

@gagolews I think this was caused by 4905b0d - I suspect this might not be a problem that regular expressions are well suited to solve, and it might be necessary to implemented a minimal parser in C++ (would need to understand character classes and \-escaping)

@hadley hadley changed the title from Figure out why roxygen2 tests fail with dev roxygen to Figure out why roxygen2 tests fail with dev stringr Jul 19, 2016

@hadley

This comment has been minimized.

Member

hadley commented Jul 19, 2016

@gagolews just wanted to check if you happened to have built any like this into stringi in the interim. Otherwise I'll start writing up more test cases

@gagolews

This comment has been minimized.

Contributor

gagolews commented Jul 20, 2016

> sub('(["\\\\])', "\\\\\\1", '"', perl=TRUE)
[1] "\\\""
> 
> sub('(["\\\\])', "\\\\\\1", '"', perl=FALSE)
[1] "\\\""

I didn't build anything into stringi like this.

@hadley

This comment has been minimized.

Member

hadley commented Aug 10, 2016

This is a somewhat easier to understand reprex:

library(stringr)
library(stringi)

# OK
str_replace_all("x", "(.)", "\\\\-\\1")
#> [1] "\\-x"
stri_replace_all_regex("x", "(.)", "\\\\-$1")
#> [1] "\\-x"

# NOT OK
str_replace_all("x", "(.)", "\\\\\\1")
#> [1] "\\1"
stri_replace_all_regex("x", "(.)", "\\\\$1")
#> [1] "\\x"

@hadley hadley closed this in 5575e26 Aug 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment