tidyverse / stringr
Showing 1 of 4 files from the diff.
Other files ignored by Codecov

@@ -15,6 +15,9 @@
Loading
15 15
#'   if `FALSE` will style using ANSI escapes. The default will prefers
16 16
#'   ANSI escapes if available in the current terminal; you can override by
17 17
#'   setting `option(stringr.html = TRUE)`.
18 +
#' @param use_escapes If `TRUE`, all non-ASCII characters will be rendered
19 +
#'   with unicode escapes. This is useful to see exactly what underlying
20 +
#'   values are stored in the string.
18 21
#' @export
19 22
#' @examples
20 23
#' # Show special characters
@@ -28,6 +31,9 @@
Loading
28 31
#' # str_view() brings it to your attention:
29 32
#' str_view(nbsp)
30 33
#'
34 +
#' # You can also use escapes for all non-ASCII characters
35 +
#' str_view(nbsp, use_escapes = TRUE)
36 +
#'
31 37
#' # Show first match
32 38
#' str_view(c("abc", "def", "fgh"), "[aeiou]")
33 39
#' str_view(c("abc", "def", "fgh"), "^")
@@ -35,28 +41,38 @@
Loading
35 41
#'
36 42
#' # Show all matches
37 43
#' str_view_all(c("abc", "def", "fgh"), "d|e")
38 -
str_view <- function(string, pattern = NULL, match = NA, html = NULL) {
44 +
str_view <- function(string, pattern = NULL, match = NA, html = NULL, use_escapes = FALSE) {
39 45
  html <- str_view_use_html(html)
40 46
41 47
  out <- str_view_filter(string, pattern, match)
42 48
  if (!is.null(pattern)) {
43 49
    out <- str_replace(out, pattern, str_view_highlighter(html))
44 50
  }
45 -
  out <- str_view_special(out, html = html)
51 +
  if (use_escapes) {
52 +
    out <- stri_escape_unicode(out)
53 +
    out <- str_replace_all(out, fixed("\\u001b"), "\u001b")
54 +
  } else {
55 +
    out <- str_view_special(out, html = html)
56 +
  }
46 57
47 58
  str_view_print(out, html)
48 59
}
49 60
50 61
#' @rdname str_view
51 62
#' @export
52 -
str_view_all <- function(string, pattern = NULL, match = NA, html = NULL) {
63 +
str_view_all <- function(string, pattern = NULL, match = NA, html = NULL, use_escapes = FALSE) {
53 64
  html <- str_view_use_html(html)
54 65
55 66
  out <- str_view_filter(string, pattern, match)
56 67
  if (!is.null(pattern)) {
57 68
    out <- str_replace_all(out, pattern, str_view_highlighter(html))
58 69
  }
59 -
  out <- str_view_special(out, html = html)
70 +
  if (use_escapes) {
71 +
    out <- stri_escape_unicode(out)
72 +
  } else {
73 +
    out <- str_view_special(out, html = html)
74 +
    out <- str_replace_all(out, fixed("\\u001b"), "\u001b")
75 +
  }
60 76
61 77
  str_view_print(out, html)
62 78
}
Files Coverage
R 90.37%
Project Totals (29 files) 90.37%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading