Skip to content
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
Closed

Figure out why roxygen2 tests fail with dev stringr #99

hadley opened this issue Oct 29, 2015 · 4 comments

Comments

@hadley
Copy link
Member

hadley commented Oct 29, 2015

It's something to do with new str_replace behaviour

@hadley
Copy link
Member Author

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 Figure out why roxygen2 tests fail with dev roxygen Figure out why roxygen2 tests fail with dev stringr Jul 19, 2016
@hadley
Copy link
Member Author

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
Copy link
Contributor

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

I didn't build anything into stringi like this.

@hadley
Copy link
Member Author

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 as completed in 5575e26 Aug 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants