-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclasses.R
More file actions
107 lines (88 loc) · 1.96 KB
/
classes.R
File metadata and controls
107 lines (88 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
setClass(
"fixed",
representation(
value = "character",
ignore_case = "logical"
)
)
setClass(
"regex",
representation(
value = "character",
ignore_case = "logical",
multiline = "logical",
dot_all = "logical",
comments = "logical"
)
)
setClass(
"coll",
representation(
value = "character",
ignore_case = "logical",
locale = "character"
)
)
setClass(
"boundary",
representation(
value = "character"
)
)
fixed <- function(x, ignore_case = FALSE) {
new("fixed", value = x, ignore_case = ignore_case)
}
get_fixed <- function(x) {
if (is.null(x)) {
return(NULL)
}
if (x@ignore_case) {
x@value <- convert_to_uppercase(x@value)
}
x@value
}
regex <- function(x, ignore_case = FALSE, multiline = FALSE, comments = FALSE, dot_all = FALSE) {
new("regex", value = x, ignore_case = ignore_case, multiline = multiline, comments = comments, dot_all = dot_all)
}
get_regex <- function(x) {
if (is.null(x)) {
return(NULL)
}
if (x@dot_all) {
x@value <- add_s_flag_to_dot(x@value)
}
if (x@multiline) {
x@value <- add_m_flag_to(x@value)
}
if (x@comments) {
x@value <- add_x_flag_to(x@value)
}
if (x@ignore_case) {
x@value <- add_i_flag_to(x@value)
}
x@value
}
coll <- function(x, ignore_case = FALSE, locale = "en") {
new("coll", value = x, ignore_case = ignore_case, locale = locale)
}
get_coll <- function(x) {
if (is.null(x)) {
return(NULL)
}
if (x@ignore_case) {
x@value <- convert_to_uppercase(x@value)
}
x@value
}
boundary <- function(x) {
if (is.null(x)) {
return(NULL)
}
switch(
x,
"word" = get_boundary_word(),
"sentence" = get_boundary_sentence(),
"line_break" = get_boundary_linebreak(),
"character" = get_boundary_character()
)
}