Skip to content

Commit c0045fb

Browse files
minor style and clarification, more tests
1 parent 007cbc6 commit c0045fb

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

R/rules-spacing.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ remove_space_after_unary_pm_nested <- function(pd) {
130130
#' @keywords internal
131131
fix_quotes <- function(pd_flat) {
132132
str_const <- which(pd_flat$token == "STR_CONST")
133-
# Shortcut for performance
134-
if (is_empty(str_const)) return(pd_flat)
133+
if (is_empty(str_const)) {
134+
return(pd_flat)
135+
}
135136

136137
pd_flat$text[str_const] <- map(pd_flat$text[str_const], fix_quotes_one)
137138
pd_flat
@@ -141,12 +142,14 @@ fix_quotes <- function(pd_flat) {
141142
fix_quotes_one <- function(x) {
142143
rx <- "^'([^\"]*)'$"
143144
i <- grep(rx, x)
144-
# Shortcut for performance
145-
if (is_empty(i)) return(x)
145+
if (is_empty(i)) {
146+
return(x)
147+
}
146148

149+
# replace outer single quotes
147150
xi <- gsub(rx, '"\\1"', x[i])
148151

149-
# Replace all \' by ' and keep all other instances of \., including \\
152+
# Replace inner escaped quotes (\') by ' and keep all other instances of \., including \\
150153
x[i] <- gsub("\\\\(')|(\\\\[^'])", "\\1\\2", xi)
151154
x
152155
}

tests/testthat/escaping/basic-escape-in.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ NULL
2828

2929
'single quotes with
3030
embedded and \n not embedded line breaks'
31+
32+
x <- ' 2' # there is a tab emebbed (created with writeLines("x <- '\t2'"))
33+
34+
x <- '\001'
35+
'\x01'
36+
37+
# FIXME: "\01" gives an error when not in a comment
38+
# FIXME: this too: '\01'

tests/testthat/escaping/basic-escape-in_tree

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/escaping/basic-escape-out.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ NULL
2828

2929
"single quotes with
3030
embedded and \n not embedded line breaks"
31+
32+
x <- " 2" # there is a tab emebbed (created with writeLines("x <- '\t2'"))
33+
34+
x <- "\001"
35+
"\x01"
36+
37+
# FIXME: "\01" gives an error when not in a comment
38+
# FIXME: this too: '\01'

0 commit comments

Comments
 (0)