/
functions_strings.go
460 lines (415 loc) · 13.1 KB
/
functions_strings.go
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
package faunadb
// String
// Format formats values into a string.
//
// Parameters:
// format string - format a string with format specifiers.
//
// Optional parameters:
// values []string - list of values to format into string.
//
// Returns:
// string - A string.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Format(format interface{}, values ...interface{}) Expr {
return formatFn{Format: wrap(format), Values: wrap(varargs(values...))}
}
type formatFn struct {
fnApply
Format Expr `json:"format"`
Values Expr `json:"values"`
}
// Concat concatenates a list of strings into a single string.
//
// Parameters:
// terms []string - A list of strings to concatenate.
//
// Optional parameters:
// separator string - The separator to use between each string. See Separator() function.
//
// Returns:
// string - A string with all terms concatenated.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Concat(terms interface{}, options ...OptionalParameter) Expr {
fn := concatFn{Concat: wrap(terms)}
return applyOptionals(fn, options)
}
type concatFn struct {
fnApply
Concat Expr `json:"concat"`
Separator Expr `json:"separator,omitempty" faunarepr:"optfn"`
}
// Casefold normalizes strings according to the Unicode Standard section 5.18 "Case Mappings".
//
// Parameters:
// str string - The string to casefold.
//
// Optional parameters:
// normalizer string - The algorithm to use. One of: NormalizerNFKCCaseFold, NormalizerNFC, NormalizerNFD, NormalizerNFKC, NormalizerNFKD.
//
// Returns:
// string - The normalized string.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Casefold(str interface{}, options ...OptionalParameter) Expr {
fn := casefoldFn{Casefold: wrap(str)}
return applyOptionals(fn, options)
}
type casefoldFn struct {
fnApply
Casefold Expr `json:"casefold"`
Normalizer Expr `json:"normalizer,omitempty" faunarepr:"optfn"`
}
// StartsWith returns true if the string starts with the given prefix value, or false if otherwise
//
// Parameters:
//
// value string - the string to evaluate
// search string - the prefix to search for
//
// Returns:
// boolean - does `value` start with `search
//
// See https://docs.fauna.com/fauna/current/api/fql/functions/startswith
func StartsWith(value interface{}, search interface{}) Expr {
return startsWithFn{StartsWith: wrap(value), Search: wrap(search)}
}
type startsWithFn struct {
fnApply
StartsWith Expr `json:"startswith"`
Search Expr `json:"search"`
}
// EndsWith returns true if the string ends with the given suffix value, or false if otherwise
//
// Parameters:
//
// value string - the string to evaluate
// search string - the suffix to search for
//
// Returns:
// boolean - does `value` end with `search`
//
// See https://docs.fauna.com/fauna/current/api/fql/functions/endswith
func EndsWith(value interface{}, search interface{}) Expr {
return endsWithFn{EndsWith: wrap(value), Search: wrap(search)}
}
type endsWithFn struct {
fnApply
EndsWith Expr `json:"endswith"`
Search Expr `json:"search"`
}
// ContainsStr returns true if the string contains the given substring, or false if otherwise
//
// Parameters:
//
// value string - the string to evaluate
// search string - the substring to search for
//
// Returns:
// boolean - was the search result found
//
// See https://docs.fauna.com/fauna/current/api/fql/functions/containsstr
func ContainsStr(value interface{}, search interface{}) Expr {
return containsStrFn{ContainsStr: wrap(value), Search: wrap(search)}
}
type containsStrFn struct {
fnApply
ContainsStr Expr `json:"containsstr"`
Search Expr `json:"search"`
}
// ContainsStrRegex returns true if the string contains the given pattern, or false if otherwise
//
// Parameters:
//
// value string - the string to evaluate
// pattern string - the pattern to search for
//
// Returns:
// boolean - was the search result found
//
// See https://docs.fauna.com/fauna/current/api/fql/functions/containsstrregex
func ContainsStrRegex(value interface{}, pattern interface{}) Expr {
return containsStrRegexFn{ContainsStrRegex: wrap(value), Pattern: wrap(pattern)}
}
type containsStrRegexFn struct {
fnApply
ContainsStrRegex Expr `json:"containsstrregex"`
Pattern Expr `json:"pattern"`
}
// RegexEscape It takes a string and returns a regex which matches the input string verbatim.
//
// Parameters:
//
// value string - the string to analyze
// pattern - the pattern to search for
//
// Returns:
// boolean - was the search result found
//
// See https://docs.fauna.com/fauna/current/api/fql/functions/regexescape
func RegexEscape(value interface{}) Expr {
return regexEscapeFn{RegexEscape: wrap(value)}
}
type regexEscapeFn struct {
fnApply
RegexEscape Expr `json:"regexescape"`
}
// FindStr locates a substring in a source string. Optional parameters: Start
//
// Parameters:
// str string - The source string
// find string - The string to locate
//
// Optional parameters:
// start int - a position to start the search. See Start() function.
//
// Returns:
// string - The offset of where the substring starts or -1 if not found
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func FindStr(str, find interface{}, options ...OptionalParameter) Expr {
fn := findStrFn{FindStr: wrap(str), Find: wrap(find)}
return applyOptionals(fn, options)
}
type findStrFn struct {
fnApply
FindStr Expr `json:"findstr"`
Find Expr `json:"find"`
Start Expr `json:"start,omitempty" faunarepr:"optfn"`
}
// FindStrRegex locates a java regex pattern in a source string. Optional parameters: Start
//
// Parameters:
// str string - The sourcestring
// pattern string - The pattern to locate.
//
// Optional parameters:
// start long - a position to start the search. See Start() function.
//
// Returns:
// string - The offset of where the substring starts or -1 if not found
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func FindStrRegex(str, pattern interface{}, options ...OptionalParameter) Expr {
fn := findStrRegexFn{FindStrRegex: wrap(str), Pattern: wrap(pattern)}
return applyOptionals(fn, options)
}
type findStrRegexFn struct {
fnApply
FindStrRegex Expr `json:"findstrregex"`
Pattern Expr `json:"pattern"`
Start Expr `json:"start,omitempty" faunarepr:"optfn"`
NumResults Expr `json:"num_results,omitempty" faunarepr:"optfn"`
}
// Length finds the length of a string in codepoints
//
// Parameters:
// str string - A string to find the length in codepoints
//
// Returns:
// int - A length of a string.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Length(str interface{}) Expr { return lengthFn{Length: wrap(str)} }
type lengthFn struct {
fnApply
Length Expr `json:"length"`
}
// LowerCase changes all characters in the string to lowercase
//
// Parameters:
// str string - A string to convert to lowercase
//
// Returns:
// string - A string in lowercase.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func LowerCase(str interface{}) Expr { return lowercaseFn{Lowercase: wrap(str)} }
type lowercaseFn struct {
fnApply
Lowercase Expr `json:"lowercase"`
}
// LTrim returns a string wtih leading white space removed.
//
// Parameters:
// str string - A string to remove leading white space
//
// Returns:
// string - A string with all leading white space removed
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func LTrim(str interface{}) Expr { return lTrimFn{LTrim: wrap(str)} }
type lTrimFn struct {
fnApply
LTrim Expr `json:"ltrim"`
}
// Repeat returns a string wtih repeated n times
//
// Parameters:
// str string - A string to repeat
// number int - The number of times to repeat the string
//
// Optional parameters:
// Number - Only replace the first found pattern. See OnlyFirst() function.
//
// Returns:
// string - A string concatendanted the specified number of times
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Repeat(str interface{}, options ...OptionalParameter) Expr {
fn := repeatFn{Repeat: wrap(str)}
return applyOptionals(fn, options)
}
type repeatFn struct {
fnApply
Repeat Expr `json:"repeat"`
Number Expr `json:"number,omitempty" faunarepr:"fn=optfn,name=Number"`
}
// ReplaceStr returns a string with every occurence of the "find" string changed to "replace" string
//
// Parameters:
// str string - A source string
// find string - The substring to locate in in the source string
// replace string - The string to replaice the "find" string when located
//
// Returns:
// string - returns a string with every occurence of the "find" string changed to "replace"
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func ReplaceStr(str, find, replace interface{}) Expr {
return replaceStrFn{
ReplaceStr: wrap(str),
Find: wrap(find),
Replace: wrap(replace),
}
}
type replaceStrFn struct {
fnApply
ReplaceStr Expr `json:"replacestr"`
Find Expr `json:"find"`
Replace Expr `json:"replace"`
}
// ReplaceStrRegex returns a string with occurence(s) of the java regular expression "pattern" changed to "replace" string. Optional parameters: OnlyFirst
//
// Parameters:
// value string - The source string
// pattern string - A java regular expression to locate
// replace string - The string to replace the pattern when located
//
// Optional parameters:
// OnlyFirst - Only replace the first found pattern. See OnlyFirst() function.
//
// Returns:
// string - A string with occurence(s) of the java regular expression "pattern" changed to "replace" string
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func ReplaceStrRegex(value, pattern, replace interface{}, options ...OptionalParameter) Expr {
fn := replaceStrRegexFn{
ReplaceStrRegex: wrap(value),
Pattern: wrap(pattern),
Replace: wrap(replace),
}
return applyOptionals(fn, options)
}
type replaceStrRegexFn struct {
fnApply
ReplaceStrRegex Expr `json:"replacestrregex"`
Pattern Expr `json:"pattern"`
Replace Expr `json:"replace"`
First Expr `json:"first,omitempty" faunarepr:"fn=optfn,name=OnlyFirst,noargs=true"`
}
// RTrim returns a string wtih trailing white space removed.
//
// Parameters:
// str string - A string to remove trailing white space
//
// Returns:
// string - A string with all trailing white space removed
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func RTrim(str interface{}) Expr { return rTrimFn{RTrim: wrap(str)} }
type rTrimFn struct {
fnApply
RTrim Expr `json:"rtrim"`
}
// Space function returns "N" number of spaces
//
// Parameters:
// value int - the number of spaces
//
// Returns:
// string - function returns string with n spaces
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Space(value interface{}) Expr { return spaceFn{Space: wrap(value)} }
type spaceFn struct {
fnApply
Space Expr `json:"space"`
}
// SubString returns a subset of the source string. Optional parameters: StrLength
//
// Parameters:
// str string - A source string
// start int - The position in the source string where SubString starts extracting characters
//
// Optional parameters:
// StrLength int - A value for the length of the extracted substring. See StrLength() function.
//
// Returns:
// string - function returns a subset of the source string
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func SubString(str, start interface{}, options ...OptionalParameter) Expr {
fn := subStringFn{SubString: wrap(str), Start: wrap(start)}
return applyOptionals(fn, options)
}
type subStringFn struct {
fnApply
SubString Expr `json:"substring"`
Start Expr `json:"start"`
Length Expr `json:"length,omitempty" faunarepr:"fn=optfn,name=StrLength"`
}
// TitleCase changes all characters in the string to TitleCase
//
// Parameters:
// str string - A string to convert to TitleCase
//
// Returns:
// string - A string in TitleCase.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func TitleCase(str interface{}) Expr { return titleCaseFn{Titlecase: wrap(str)} }
type titleCaseFn struct {
fnApply
Titlecase Expr `json:"titlecase"`
}
// Trim returns a string wtih trailing white space removed.
//
// Parameters:
// str string - A string to remove trailing white space
//
// Returns:
// string - A string with all trailing white space removed
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func Trim(str interface{}) Expr { return trimFn{Trim: wrap(str)} }
type trimFn struct {
fnApply
Trim Expr `json:"trim"`
}
// UpperCase changes all characters in the string to uppercase
//
// Parameters:
// string - A string to convert to uppercase
//
// Returns:
// string - A string in uppercase.
//
// See: https://app.fauna.com/documentation/reference/queryapi#string-functions
func UpperCase(str interface{}) Expr { return upperCaseFn{UpperCase: wrap(str)} }
type upperCaseFn struct {
fnApply
UpperCase Expr `json:"uppercase"`
}