Skip to content

Commit

Permalink
Ignore empty lines when trimming common leading whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Sep 12, 2018
1 parent 8c64e13 commit d37ac25
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ trim_ws <- function(x) {

trim_common_leading_ws <- function(x) {
m <- regexpr("^(\\s*)", x)
ws <- regmatches(x, m)
num <- min(nchar(ws))
n_chars <- nchar(x)
n_spaces <- attr(m, which = "match.length")
num <- min(n_spaces[n_chars > 0])
substring(x, num + 1)
}

Expand Down

0 comments on commit d37ac25

Please sign in to comment.