aboutsummaryrefslogtreecommitdiff
path: root/lib/patterns/patterns.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/patterns/patterns.c')
-rw-r--r--lib/patterns/patterns.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/lib/patterns/patterns.c b/lib/patterns/patterns.c
index 224a00a0..5df1047c 100644
--- a/lib/patterns/patterns.c
+++ b/lib/patterns/patterns.c
@@ -48,7 +48,7 @@ static Text_t replace_list(Text_t text, List_t replacements, Text_t backref_pat,
static INLINE void skip_whitespace(TextIter_t *state, int64_t *i)
{
while (*i < state->stack[0].text.length) {
- int32_t grapheme = Text$get_grapheme_fast(state, *i);
+ int32_t grapheme = Textヽget_grapheme_fast(state, *i);
if (grapheme > 0 && !uc_is_property_white_space((ucs4_t)grapheme))
return;
*i += 1;
@@ -57,7 +57,7 @@ static INLINE void skip_whitespace(TextIter_t *state, int64_t *i)
static INLINE bool match_grapheme(TextIter_t *state, int64_t *i, int32_t grapheme)
{
- if (*i < state->stack[0].text.length && Text$get_grapheme_fast(state, *i) == grapheme) {
+ if (*i < state->stack[0].text.length && Textヽget_grapheme_fast(state, *i) == grapheme) {
*i += 1;
return true;
}
@@ -68,7 +68,7 @@ static INLINE bool match_str(TextIter_t *state, int64_t *i, const char *str)
{
int64_t matched = 0;
while (matched[str]) {
- if (*i + matched >= state->stack[0].text.length || Text$get_grapheme_fast(state, *i + matched) != str[matched])
+ if (*i + matched >= state->stack[0].text.length || Textヽget_grapheme_fast(state, *i + matched) != str[matched])
return false;
matched += 1;
}
@@ -80,7 +80,7 @@ static int64_t parse_int(TextIter_t *state, int64_t *i)
{
int64_t value = 0;
for (;; *i += 1) {
- uint32_t grapheme = Text$get_main_grapheme_fast(state, *i);
+ uint32_t grapheme = Textヽget_main_grapheme_fast(state, *i);
int digit = uc_digit_value(grapheme);
if (digit < 0) break;
if (value >= INT64_MAX/10) break;
@@ -95,7 +95,7 @@ static const char *get_property_name(TextIter_t *state, int64_t *i)
char *name = GC_MALLOC_ATOMIC(UNINAME_MAX);
char *dest = name;
while (*i < state->stack[0].text.length) {
- int32_t grapheme = Text$get_grapheme_fast(state, *i);
+ int32_t grapheme = Textヽget_grapheme_fast(state, *i);
if (!(grapheme & ~0xFF) && (isalnum(grapheme) || grapheme == ' ' || grapheme == '_' || grapheme == '-')) {
*dest = (char)grapheme;
++dest;
@@ -116,16 +116,16 @@ static const char *get_property_name(TextIter_t *state, int64_t *i)
}
#define EAT1(state, index, cond) ({\
- int32_t grapheme = Text$get_grapheme_fast(state, index); \
+ int32_t grapheme = Textヽget_grapheme_fast(state, index); \
bool success = (cond); \
if (success) index += 1; \
success; })
#define EAT2(state, index, cond1, cond2) ({\
- int32_t grapheme = Text$get_grapheme_fast(state, index); \
+ int32_t grapheme = Textヽget_grapheme_fast(state, index); \
bool success = (cond1); \
if (success) { \
- grapheme = Text$get_grapheme_fast(state, index + 1); \
+ grapheme = Textヽget_grapheme_fast(state, index + 1); \
success = (cond2); \
if (success) \
index += 2; \
@@ -138,12 +138,12 @@ static const char *get_property_name(TextIter_t *state, int64_t *i)
static int64_t match_email(TextIter_t *state, int64_t index)
{
// email = local "@" domain
- // local = 1-64 ([a-zA-Z0-9!#$%&‘*+–/=?^_`.{|}~] | non-ascii)
+ // local = 1-64 ([a-zA-Z0-9!#ヽ%&‘*+–/=?^_`.{|}~] | non-ascii)
// domain = dns-label ("." dns-label)*
// dns-label = 1-63 ([a-zA-Z0-9-] | non-ascii)
if (index > 0) {
- uint32_t prev_codepoint = Text$get_main_grapheme_fast(state, index - 1);
+ uint32_t prev_codepoint = Textヽget_main_grapheme_fast(state, index - 1);
if (uc_is_property_alphabetic(prev_codepoint))
return -1;
}
@@ -187,7 +187,7 @@ static int64_t match_email(TextIter_t *state, int64_t index)
static int64_t match_ipv6(TextIter_t *state, int64_t index)
{
if (index > 0) {
- int32_t prev_codepoint = Text$get_grapheme_fast(state, index - 1);
+ int32_t prev_codepoint = Textヽget_grapheme_fast(state, index - 1);
if ((prev_codepoint & ~0x7F) && (isxdigit(prev_codepoint) || prev_codepoint == ':'))
return -1;
}
@@ -222,7 +222,7 @@ static int64_t match_ipv6(TextIter_t *state, int64_t index)
static int64_t match_ipv4(TextIter_t *state, int64_t index)
{
if (index > 0) {
- int32_t prev_codepoint = Text$get_grapheme_fast(state, index - 1);
+ int32_t prev_codepoint = Textヽget_grapheme_fast(state, index - 1);
if ((prev_codepoint & ~0x7F) && (isdigit(prev_codepoint) || prev_codepoint == '.'))
return -1;
}
@@ -310,7 +310,7 @@ static int64_t match_uri(TextIter_t *state, int64_t index)
if (index > 0) {
// Don't match if we're not at a word edge:
- uint32_t prev_codepoint = Text$get_main_grapheme_fast(state, index - 1);
+ uint32_t prev_codepoint = Textヽget_main_grapheme_fast(state, index - 1);
if (uc_is_property_alphabetic(prev_codepoint))
return -1;
}
@@ -408,10 +408,10 @@ static int64_t match_newline(TextIter_t *state, int64_t index)
if (index >= state->stack[0].text.length)
return -1;
- uint32_t grapheme = index >= state->stack[0].text.length ? 0 : Text$get_main_grapheme_fast(state, index);
+ uint32_t grapheme = index >= state->stack[0].text.length ? 0 : Textヽget_main_grapheme_fast(state, index);
if (grapheme == '\n')
return 1;
- if (grapheme == '\r' && Text$get_grapheme_fast(state, index + 1) == '\n')
+ if (grapheme == '\r' && Textヽget_grapheme_fast(state, index + 1) == '\n')
return 2;
return -1;
}
@@ -419,7 +419,7 @@ static int64_t match_newline(TextIter_t *state, int64_t index)
static int64_t match_pat(TextIter_t *state, int64_t index, pat_t pat)
{
Text_t text = state->stack[0].text;
- int32_t grapheme = index >= text.length ? 0 : Text$get_grapheme_fast(state, index);
+ int32_t grapheme = index >= text.length ? 0 : Textヽget_grapheme_fast(state, index);
switch (pat.tag) {
case PAT_START: {
@@ -466,7 +466,7 @@ static int64_t match_pat(TextIter_t *state, int64_t index, pat_t pat)
if (index + match_len >= text.length)
return pat.negated ? 1 : -1;
- int32_t c = Text$get_grapheme_fast(state, index + match_len);
+ int32_t c = Textヽget_grapheme_fast(state, index + match_len);
if (c == open)
depth += 1;
else if (c == close)
@@ -485,7 +485,7 @@ static int64_t match_pat(TextIter_t *state, int64_t index, pat_t pat)
int32_t close = pat.quote_graphemes[1];
for (int64_t i = index + 1; i < text.length; i++) {
- int32_t c = Text$get_grapheme_fast(state, i);
+ int32_t c = Textヽget_grapheme_fast(state, i);
if (c == close) {
return pat.negated ? -1 : (i - index) + 1;
} else if (c == '\\' && index + 1 < text.length) {
@@ -512,7 +512,7 @@ static pat_t parse_next_pat(TextIter_t *state, int64_t *index)
uc_is_property((ucs4_t)grapheme, UC_PROPERTY_QUOTATION_MARK),
grapheme == '?')) {
// Quotations: "?", '?', etc
- int32_t open = Text$get_grapheme_fast(state, *index-2);
+ int32_t open = Textヽget_grapheme_fast(state, *index-2);
int32_t close = open;
uc_mirror_char((ucs4_t)open, (ucs4_t*)&close);
if (!match_grapheme(state, index, close))
@@ -527,7 +527,7 @@ static pat_t parse_next_pat(TextIter_t *state, int64_t *index)
uc_is_property((ucs4_t)grapheme, UC_PROPERTY_PAIRED_PUNCTUATION),
grapheme == '?')) {
// Nested punctuation: (?), [?], etc
- int32_t open = Text$get_grapheme_fast(state, *index-2);
+ int32_t open = Textヽget_grapheme_fast(state, *index-2);
int32_t close = open;
uc_mirror_char((ucs4_t)open, (ucs4_t*)&close);
if (!match_grapheme(state, index, close))
@@ -541,7 +541,7 @@ static pat_t parse_next_pat(TextIter_t *state, int64_t *index)
} else if (EAT1(state, *index, grapheme == '{')) { // named patterns {id}, {2-3 hex}, etc.
skip_whitespace(state, index);
int64_t min, max;
- if (uc_is_digit((ucs4_t)Text$get_grapheme_fast(state, *index))) {
+ if (uc_is_digit((ucs4_t)Textヽget_grapheme_fast(state, *index))) {
min = parse_int(state, index);
skip_whitespace(state, index);
if (match_grapheme(state, index, '+')) {
@@ -569,7 +569,7 @@ static pat_t parse_next_pat(TextIter_t *state, int64_t *index)
if (!prop_name) {
// Literal character, e.g. {1?}
skip_whitespace(state, index);
- int32_t grapheme = Text$get_grapheme_fast(state, (*index)++);
+ int32_t grapheme = Textヽget_grapheme_fast(state, (*index)++);
if (!match_grapheme(state, index, '}'))
fail("Missing closing '}' in pattern: ", state->stack[0].text);
return PAT(PAT_GRAPHEME, .grapheme=grapheme);
@@ -680,7 +680,7 @@ static pat_t parse_next_pat(TextIter_t *state, int64_t *index)
return PAT(PAT_GRAPHEME, .grapheme=(int32_t)grapheme);
#undef PAT
} else {
- return (pat_t){.tag=PAT_GRAPHEME, .non_capturing=true, .min=1, .max=1, .grapheme=Text$get_grapheme_fast(state, (*index)++)};
+ return (pat_t){.tag=PAT_GRAPHEME, .non_capturing=true, .min=1, .max=1, .grapheme=Textヽget_grapheme_fast(state, (*index)++)};
}
}
@@ -786,7 +786,7 @@ static int64_t match(Text_t text, int64_t text_index, Text_t pattern, int64_t pa
static int64_t _find(Text_t text, Text_t pattern, int64_t first, int64_t last, int64_t *match_length, capture_t *captures)
{
- int32_t first_grapheme = Text$get_grapheme(pattern, 0);
+ int32_t first_grapheme = Textヽget_grapheme(pattern, 0);
bool find_first = (first_grapheme != '{'
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_QUOTATION_MARK)
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_PAIRED_PUNCTUATION));
@@ -795,7 +795,7 @@ static int64_t _find(Text_t text, Text_t pattern, int64_t first, int64_t last, i
for (int64_t i = first; i <= last; i++) {
// Optimization: quickly skip ahead to first char in pattern:
if (find_first) {
- while (i < text.length && Text$get_grapheme_fast(&text_state, i) != first_grapheme)
+ while (i < text.length && Textヽget_grapheme_fast(&text_state, i) != first_grapheme)
++i;
}
@@ -813,7 +813,7 @@ static int64_t _find(Text_t text, Text_t pattern, int64_t first, int64_t last, i
static OptionalPatternMatch find(Text_t text, Text_t pattern, Int_t from_index)
{
- int64_t first = Int64$from_int(from_index, false);
+ int64_t first = Int64ヽfrom_int(from_index, false);
if (first == 0) fail("Invalid index: 0");
if (first < 0) first = text.length + first + 1;
if (first > text.length || first < 1)
@@ -827,22 +827,22 @@ static OptionalPatternMatch find(Text_t text, Text_t pattern, Int_t from_index)
List_t capture_list = {};
for (int i = 0; captures[i].occupied; i++) {
- Text_t capture = Text$slice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
- List$insert(&capture_list, &capture, I(0), sizeof(Text_t));
+ Text_t capture = Textヽslice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
+ Listヽinsert(&capture_list, &capture, I(0), sizeof(Text_t));
}
return (OptionalPatternMatch){
- .text=Text$slice(text, I(found+1), I(found+len)),
+ .text=Textヽslice(text, I(found+1), I(found+len)),
.index=I(found+1),
.captures=capture_list,
};
}
-PUREFUNC static bool Pattern$has(Text_t text, Text_t pattern)
+PUREFUNC static bool Patternヽhas(Text_t text, Text_t pattern)
{
- if (Text$starts_with(pattern, Text("{start}"), &pattern)) {
+ if (Textヽstarts_with(pattern, Text("{start}"), &pattern)) {
int64_t m = match(text, 0, pattern, 0, NULL, 0);
return m >= 0;
- } else if (Text$ends_with(text, Text("{end}"), NULL)) {
+ } else if (Textヽends_with(text, Text("{end}"), NULL)) {
for (int64_t i = text.length-1; i >= 0; i--) {
int64_t match_len = match(text, i, pattern, 0, NULL, 0);
if (match_len >= 0 && i + match_len == text.length)
@@ -855,16 +855,16 @@ PUREFUNC static bool Pattern$has(Text_t text, Text_t pattern)
}
}
-static bool Pattern$matches(Text_t text, Text_t pattern)
+static bool Patternヽmatches(Text_t text, Text_t pattern)
{
capture_t captures[MAX_BACKREFS] = {};
int64_t match_len = match(text, 0, pattern, 0, NULL, 0);
return (match_len == text.length);
}
-static bool Pattern$match_at(Text_t text, Text_t pattern, Int_t pos, PatternMatch *dest)
+static bool Patternヽmatch_at(Text_t text, Text_t pattern, Int_t pos, PatternMatch *dest)
{
- int64_t start = Int64$from_int(pos, false) - 1;
+ int64_t start = Int64ヽfrom_int(pos, false) - 1;
capture_t captures[MAX_BACKREFS] = {};
int64_t match_len = match(text, start, pattern, 0, captures, 0);
if (match_len < 0)
@@ -872,16 +872,16 @@ static bool Pattern$match_at(Text_t text, Text_t pattern, Int_t pos, PatternMatc
List_t capture_list = {};
for (int i = 0; captures[i].occupied; i++) {
- Text_t capture = Text$slice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
- List$insert(&capture_list, &capture, I(0), sizeof(Text_t));
+ Text_t capture = Textヽslice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
+ Listヽinsert(&capture_list, &capture, I(0), sizeof(Text_t));
}
- dest->text = Text$slice(text, I(start+1), I(start+match_len));
+ dest->text = Textヽslice(text, I(start+1), I(start+match_len));
dest->index = I(start+1);
dest->captures = capture_list;
return true;
}
-static OptionalList_t Pattern$captures(Text_t text, Text_t pattern)
+static OptionalList_t Patternヽcaptures(Text_t text, Text_t pattern)
{
capture_t captures[MAX_BACKREFS] = {};
int64_t match_len = match(text, 0, pattern, 0, captures, 0);
@@ -890,13 +890,13 @@ static OptionalList_t Pattern$captures(Text_t text, Text_t pattern)
List_t capture_list = {};
for (int i = 0; captures[i].occupied; i++) {
- Text_t capture = Text$slice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
- List$insert(&capture_list, &capture, I(0), sizeof(Text_t));
+ Text_t capture = Textヽslice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
+ Listヽinsert(&capture_list, &capture, I(0), sizeof(Text_t));
}
return capture_list;
}
-static List_t Pattern$find_all(Text_t text, Text_t pattern)
+static List_t Patternヽfind_all(Text_t text, Text_t pattern)
{
if (pattern.length == 0) // special case
return (List_t){.length=0};
@@ -906,8 +906,8 @@ static List_t Pattern$find_all(Text_t text, Text_t pattern)
OptionalPatternMatch m = find(text, pattern, I(i));
if (m.is_none)
break;
- i = Int64$from_int(m.index, false) + m.text.length;
- List$insert(&matches, &m, I_small(0), sizeof(PatternMatch));
+ i = Int64ヽfrom_int(m.index, false) + m.text.length;
+ Listヽinsert(&matches, &m, I_small(0), sizeof(PatternMatch));
}
return matches;
}
@@ -920,18 +920,18 @@ typedef struct {
static OptionalPatternMatch next_match(match_iter_state_t *state)
{
- if (Int64$from_int(state->i, false) > state->state.stack[0].text.length)
+ if (Int64ヽfrom_int(state->i, false) > state->state.stack[0].text.length)
return NONE_MATCH;
OptionalPatternMatch m = find(state->state.stack[0].text, state->pattern, state->i);
if (m.is_none) // No match
state->i = I(state->state.stack[0].text.length + 1);
else
- state->i = Int$plus(m.index, I(MAX(1, m.text.length)));
+ state->i = Intヽplus(m.index, I(MAX(1, m.text.length)));
return m;
}
-static Closure_t Pattern$by_match(Text_t text, Text_t pattern)
+static Closure_t Patternヽby_match(Text_t text, Text_t pattern)
{
return (Closure_t){
.fn=(void*)next_match,
@@ -944,7 +944,7 @@ static Text_t apply_backrefs(Text_t text, List_t recursive_replacements, Text_t
if (backref_pat.length == 0)
return replacement;
- int32_t first_grapheme = Text$get_grapheme(backref_pat, 0);
+ int32_t first_grapheme = Textヽget_grapheme(backref_pat, 0);
bool find_first = (first_grapheme != '{'
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_QUOTATION_MARK)
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_PAIRED_PUNCTUATION));
@@ -955,7 +955,7 @@ static Text_t apply_backrefs(Text_t text, List_t recursive_replacements, Text_t
for (int64_t pos = 0; pos < replacement.length; ) {
// Optimization: quickly skip ahead to first char in the backref pattern:
if (find_first) {
- while (pos < replacement.length && Text$get_grapheme_fast(&replacement_state, pos) != first_grapheme)
+ while (pos < replacement.length && Textヽget_grapheme_fast(&replacement_state, pos) != first_grapheme)
++pos;
}
@@ -974,39 +974,39 @@ static Text_t apply_backrefs(Text_t text, List_t recursive_replacements, Text_t
if (backref < 0 || backref > 9) fail("Invalid backref index: ", backref, " (only 0-", MAX_BACKREFS-1, " are allowed)");
backref_len = (after_backref - pos);
- if (Text$get_grapheme_fast(&replacement_state, pos + backref_len) == ';')
+ if (Textヽget_grapheme_fast(&replacement_state, pos + backref_len) == ';')
backref_len += 1; // skip optional semicolon
if (!captures[backref].occupied)
fail("There is no capture number ", backref, "!");
- Text_t backref_text = Text$slice(text, I(captures[backref].index+1), I(captures[backref].index + captures[backref].length));
+ Text_t backref_text = Textヽslice(text, I(captures[backref].index+1), I(captures[backref].index + captures[backref].length));
if (captures[backref].recursive && recursive_replacements.length > 0)
backref_text = replace_list(backref_text, recursive_replacements, backref_pat, true);
if (pos > nonmatching_pos) {
- Text_t before_slice = Text$slice(replacement, I(nonmatching_pos+1), I(pos));
- ret = Text$concat(ret, before_slice, backref_text);
+ Text_t before_slice = Textヽslice(replacement, I(nonmatching_pos+1), I(pos));
+ ret = Textヽconcat(ret, before_slice, backref_text);
} else {
- ret = Text$concat(ret, backref_text);
+ ret = Textヽconcat(ret, backref_text);
}
pos += backref_len;
nonmatching_pos = pos;
}
if (nonmatching_pos < replacement.length) {
- Text_t last_slice = Text$slice(replacement, I(nonmatching_pos+1), I(replacement.length));
- ret = Text$concat(ret, last_slice);
+ Text_t last_slice = Textヽslice(replacement, I(nonmatching_pos+1), I(replacement.length));
+ ret = Textヽconcat(ret, last_slice);
}
return ret;
}
-static Text_t Pattern$replace(Text_t text, Text_t pattern, Text_t replacement, Text_t backref_pat, bool recursive)
+static Text_t Patternヽreplace(Text_t text, Text_t pattern, Text_t replacement, Text_t backref_pat, bool recursive)
{
Text_t ret = EMPTY_TEXT;
- int32_t first_grapheme = Text$get_grapheme(pattern, 0);
+ int32_t first_grapheme = Textヽget_grapheme(pattern, 0);
bool find_first = (first_grapheme != '{'
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_QUOTATION_MARK)
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_PAIRED_PUNCTUATION));
@@ -1023,7 +1023,7 @@ static Text_t Pattern$replace(Text_t text, Text_t pattern, Text_t replacement, T
for (int64_t pos = 0; pos < text.length; ) {
// Optimization: quickly skip ahead to first char in pattern:
if (find_first) {
- while (pos < text.length && Text$get_grapheme_fast(&text_state, pos) != first_grapheme)
+ while (pos < text.length && Textヽget_grapheme_fast(&text_state, pos) != first_grapheme)
++pos;
}
@@ -1040,22 +1040,22 @@ static Text_t Pattern$replace(Text_t text, Text_t pattern, Text_t replacement, T
Text_t replacement_text = apply_backrefs(text, recursive ? replacements : (List_t){}, replacement, backref_pat, captures);
if (pos > nonmatching_pos) {
- Text_t before_slice = Text$slice(text, I(nonmatching_pos+1), I(pos));
- ret = Text$concat(ret, before_slice, replacement_text);
+ Text_t before_slice = Textヽslice(text, I(nonmatching_pos+1), I(pos));
+ ret = Textヽconcat(ret, before_slice, replacement_text);
} else {
- ret = Text$concat(ret, replacement_text);
+ ret = Textヽconcat(ret, replacement_text);
}
nonmatching_pos = pos + match_len;
pos += MAX(match_len, 1);
}
if (nonmatching_pos < text.length) {
- Text_t last_slice = Text$slice(text, I(nonmatching_pos+1), I(text.length));
- ret = Text$concat(ret, last_slice);
+ Text_t last_slice = Textヽslice(text, I(nonmatching_pos+1), I(text.length));
+ ret = Textヽconcat(ret, last_slice);
}
return ret;
}
-static Text_t Pattern$trim(Text_t text, Text_t pattern, bool trim_left, bool trim_right)
+static Text_t Patternヽtrim(Text_t text, Text_t pattern, bool trim_left, bool trim_right)
{
int64_t first = 0, last = text.length-1;
if (trim_left) {
@@ -1071,14 +1071,14 @@ static Text_t Pattern$trim(Text_t text, Text_t pattern, bool trim_left, bool tri
last = i-1;
}
}
- return Text$slice(text, I(first+1), I(last+1));
+ return Textヽslice(text, I(first+1), I(last+1));
}
-static Text_t Pattern$map(Text_t text, Text_t pattern, Closure_t fn, bool recursive)
+static Text_t Patternヽmap(Text_t text, Text_t pattern, Closure_t fn, bool recursive)
{
Text_t ret = EMPTY_TEXT;
- int32_t first_grapheme = Text$get_grapheme(pattern, 0);
+ int32_t first_grapheme = Textヽget_grapheme(pattern, 0);
bool find_first = (first_grapheme != '{'
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_QUOTATION_MARK)
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_PAIRED_PUNCTUATION));
@@ -1090,7 +1090,7 @@ static Text_t Pattern$map(Text_t text, Text_t pattern, Closure_t fn, bool recurs
for (int64_t pos = 0; pos < text.length; pos++) {
// Optimization: quickly skip ahead to first char in pattern:
if (find_first) {
- while (pos < text.length && Text$get_grapheme_fast(&text_state, pos) != first_grapheme)
+ while (pos < text.length && Textヽget_grapheme_fast(&text_state, pos) != first_grapheme)
++pos;
}
@@ -1099,37 +1099,37 @@ static Text_t Pattern$map(Text_t text, Text_t pattern, Closure_t fn, bool recurs
if (match_len < 0) continue;
PatternMatch m = {
- .text=Text$slice(text, I(pos+1), I(pos+match_len)),
+ .text=Textヽslice(text, I(pos+1), I(pos+match_len)),
.index=I(pos+1),
.captures={},
};
for (int i = 0; captures[i].occupied; i++) {
- Text_t capture = Text$slice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
+ Text_t capture = Textヽslice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
if (recursive)
- capture = Pattern$map(capture, pattern, fn, recursive);
- List$insert(&m.captures, &capture, I(0), sizeof(Text_t));
+ capture = Patternヽmap(capture, pattern, fn, recursive);
+ Listヽinsert(&m.captures, &capture, I(0), sizeof(Text_t));
}
Text_t replacement = text_mapper(m, fn.userdata);
if (pos > nonmatching_pos) {
- Text_t before_slice = Text$slice(text, I(nonmatching_pos+1), I(pos));
- ret = Text$concat(ret, before_slice, replacement);
+ Text_t before_slice = Textヽslice(text, I(nonmatching_pos+1), I(pos));
+ ret = Textヽconcat(ret, before_slice, replacement);
} else {
- ret = Text$concat(ret, replacement);
+ ret = Textヽconcat(ret, replacement);
}
nonmatching_pos = pos + match_len;
pos += (match_len - 1);
}
if (nonmatching_pos < text.length) {
- Text_t last_slice = Text$slice(text, I(nonmatching_pos+1), I(text.length));
- ret = Text$concat(ret, last_slice);
+ Text_t last_slice = Textヽslice(text, I(nonmatching_pos+1), I(text.length));
+ ret = Textヽconcat(ret, last_slice);
}
return ret;
}
-static void Pattern$each(Text_t text, Text_t pattern, Closure_t fn, bool recursive)
+static void Patternヽeach(Text_t text, Text_t pattern, Closure_t fn, bool recursive)
{
- int32_t first_grapheme = Text$get_grapheme(pattern, 0);
+ int32_t first_grapheme = Textヽget_grapheme(pattern, 0);
bool find_first = (first_grapheme != '{'
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_QUOTATION_MARK)
&& !uc_is_property((ucs4_t)first_grapheme, UC_PROPERTY_PAIRED_PUNCTUATION));
@@ -1139,7 +1139,7 @@ static void Pattern$each(Text_t text, Text_t pattern, Closure_t fn, bool recursi
for (int64_t pos = 0; pos < text.length; pos++) {
// Optimization: quickly skip ahead to first char in pattern:
if (find_first) {
- while (pos < text.length && Text$get_grapheme_fast(&text_state, pos) != first_grapheme)
+ while (pos < text.length && Textヽget_grapheme_fast(&text_state, pos) != first_grapheme)
++pos;
}
@@ -1148,15 +1148,15 @@ static void Pattern$each(Text_t text, Text_t pattern, Closure_t fn, bool recursi
if (match_len < 0) continue;
PatternMatch m = {
- .text=Text$slice(text, I(pos+1), I(pos+match_len)),
+ .text=Textヽslice(text, I(pos+1), I(pos+match_len)),
.index=I(pos+1),
.captures={},
};
for (int i = 0; captures[i].occupied; i++) {
- Text_t capture = Text$slice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
+ Text_t capture = Textヽslice(text, I(captures[i].index+1), I(captures[i].index+captures[i].length));
if (recursive)
- Pattern$each(capture, pattern, fn, recursive);
- List$insert(&m.captures, &capture, I(0), sizeof(Text_t));
+ Patternヽeach(capture, pattern, fn, recursive);
+ Listヽinsert(&m.captures, &capture, I(0), sizeof(Text_t));
}
action(m, fn.userdata);
@@ -1183,14 +1183,14 @@ Text_t replace_list(Text_t text, List_t replacements, Text_t backref_pat, bool r
// If we skipped over some non-matching text before finding a match, insert it here:
if (pos > nonmatch_pos) {
- Text_t before_slice = Text$slice(text, I(nonmatch_pos+1), I(pos));
- ret = Text$concat(ret, before_slice);
+ Text_t before_slice = Textヽslice(text, I(nonmatch_pos+1), I(pos));
+ ret = Textヽconcat(ret, before_slice);
}
// Concatenate the replacement:
Text_t replacement = *(Text_t*)(replacements.data + i*replacements.stride + sizeof(Text_t));
Text_t replacement_text = apply_backrefs(text, recursive ? replacements : (List_t){}, replacement, backref_pat, captures);
- ret = Text$concat(ret, replacement_text);
+ ret = Textヽconcat(ret, replacement_text);
pos += MAX(len, 1);
nonmatch_pos = pos;
goto next_pos;
@@ -1202,24 +1202,24 @@ Text_t replace_list(Text_t text, List_t replacements, Text_t backref_pat, bool r
}
if (nonmatch_pos <= text.length) {
- Text_t last_slice = Text$slice(text, I(nonmatch_pos+1), I(text.length));
- ret = Text$concat(ret, last_slice);
+ Text_t last_slice = Textヽslice(text, I(nonmatch_pos+1), I(text.length));
+ ret = Textヽconcat(ret, last_slice);
}
return ret;
}
-static Text_t Pattern$replace_all(Text_t text, Table_t replacements, Text_t backref_pat, bool recursive)
+static Text_t Patternヽreplace_all(Text_t text, Table_t replacements, Text_t backref_pat, bool recursive)
{
return replace_list(text, replacements.entries, backref_pat, recursive);
}
-static List_t Pattern$split(Text_t text, Text_t pattern)
+static List_t Patternヽsplit(Text_t text, Text_t pattern)
{
if (text.length == 0) // special case
return (List_t){.length=0};
if (pattern.length == 0) // special case
- return Text$clusters(text);
+ return Textヽclusters(text);
List_t chunks = {};
@@ -1230,13 +1230,13 @@ static List_t Pattern$split(Text_t text, Text_t pattern)
if (found == i && len == 0)
found = _find(text, pattern, i + 1, text.length-1, &len, NULL);
if (found < 0) break;
- Text_t chunk = Text$slice(text, I(i+1), I(found));
- List$insert(&chunks, &chunk, I_small(0), sizeof(Text_t));
+ Text_t chunk = Textヽslice(text, I(i+1), I(found));
+ Listヽinsert(&chunks, &chunk, I_small(0), sizeof(Text_t));
i = MAX(found + len, i + 1);
}
- Text_t last_chunk = Text$slice(text, I(i+1), I(text.length));
- List$insert(&chunks, &last_chunk, I_small(0), sizeof(Text_t));
+ Text_t last_chunk = Textヽslice(text, I(i+1), I(text.length));
+ Listヽinsert(&chunks, &last_chunk, I_small(0), sizeof(Text_t));
return chunks;
}
@@ -1259,7 +1259,7 @@ static OptionalText_t next_split(split_iter_state_t *state)
}
if (state->pattern.length == 0) { // special case
- Text_t ret = Text$cluster(text, I(state->i+1));
+ Text_t ret = Textヽcluster(text, I(state->i+1));
state->i += 1;
return ret;
}
@@ -1273,14 +1273,14 @@ static OptionalText_t next_split(split_iter_state_t *state)
if (found >= 0) {
state->i = MAX(found + len, state->i + 1);
- return Text$slice(text, I(start+1), I(found));
+ return Textヽslice(text, I(start+1), I(found));
} else {
state->i = state->state.stack[0].text.length + 1;
- return Text$slice(text, I(start+1), I(text.length));
+ return Textヽslice(text, I(start+1), I(text.length));
}
}
-static Closure_t Pattern$by_split(Text_t text, Text_t pattern)
+static Closure_t Patternヽby_split(Text_t text, Text_t pattern)
{
return (Closure_t){
.fn=(void*)next_split,
@@ -1288,34 +1288,34 @@ static Closure_t Pattern$by_split(Text_t text, Text_t pattern)
};
}
-static Text_t Pattern$escape_text(Text_t text)
+static Text_t Patternヽescape_text(Text_t text)
{
// TODO: optimize for spans of non-escaped text
Text_t ret = EMPTY_TEXT;
TextIter_t state = NEW_TEXT_ITER_STATE(text);
for (int64_t i = 0; i < text.length; i++) {
- uint32_t g = Text$get_main_grapheme_fast(&state, i);
+ uint32_t g = Textヽget_main_grapheme_fast(&state, i);
if (g == '{') {
- ret = Text$concat(ret, Text("{1{}"));
+ ret = Textヽconcat(ret, Text("{1{}"));
} else if (g == '?'
|| uc_is_property_quotation_mark(g)
|| (uc_is_property_paired_punctuation(g) && uc_is_property_left_of_pair(g))) {
- ret = Text$concat(ret, Text("{1"), Text$slice(text, I(i+1), I(i+1)), Text("}"));
+ ret = Textヽconcat(ret, Text("{1"), Textヽslice(text, I(i+1), I(i+1)), Text("}"));
} else {
- ret = Text$concat(ret, Text$slice(text, I(i+1), I(i+1)));
+ ret = Textヽconcat(ret, Textヽslice(text, I(i+1), I(i+1)));
}
}
return ret;
}
-static Text_t Pattern$as_text(const void *obj, bool colorize, const TypeInfo_t *info)
+static Text_t Patternヽas_text(const void *obj, bool colorize, const TypeInfo_t *info)
{
(void)info;
if (!obj) return Text("Pattern");
Text_t pat = *(Text_t*)obj;
- Text_t quote = Pattern$has(pat, Text("/")) && !Pattern$has(pat, Text("|")) ? Text("|") : Text("/");
- return Text$concat(colorize ? Text("\x1b[1m$\033[m") : Text("$"), Text$quoted(pat, colorize, quote));
+ Text_t quote = Patternヽhas(pat, Text("/")) && !Patternヽhas(pat, Text("|")) ? Text("|") : Text("/");
+ return Textヽconcat(colorize ? Text("\x1b[1mヽ\033[m") : Text("ヽ"), Textヽquoted(pat, colorize, quote));
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0