aboutsummaryrefslogtreecommitdiff
path: root/pattern.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-08-23 12:43:18 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-08-23 12:43:18 -0700
commit7e04f59554d31d063d2a5dd901184ab2e32b30d0 (patch)
treebb0adc28f2f930648bd2fe159de5b5a9e1f306ee /pattern.c
parent2f9b0ce941b0cdb6b332e4ef510fda07e8201801 (diff)
Add support for {strings}
Diffstat (limited to 'pattern.c')
-rw-r--r--pattern.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/pattern.c b/pattern.c
index a0efd26..5e4fb80 100644
--- a/pattern.c
+++ b/pattern.c
@@ -90,10 +90,11 @@ static pat_t *expand_replacements(file_t *f, pat_t *replace_pat, bool allow_nl)
while (matchstr(&str, "=>", allow_nl)) {
const char *repstr;
size_t replen;
- if (matchchar(&str, '"', allow_nl) || matchchar(&str, '\'', allow_nl)) {
- char quote = str[-1];
+ if (matchchar(&str, '"', allow_nl) || matchchar(&str, '\'', allow_nl)
+ || matchchar(&str, '{', allow_nl) || matchchar(&str, '\002', allow_nl)) {
+ char closequote = str[-1] == '{' ? '}' : (str[-1] == '\002' ? '\003' : str[-1]);
repstr = str;
- for (; *str && *str != quote; str = next_char(f, str)) {
+ for (; *str && *str != closequote; str = next_char(f, str)) {
if (*str == '\\') {
if (!str[1] || str[1] == '\n')
file_err(f, str, str+1,
@@ -102,7 +103,7 @@ static pat_t *expand_replacements(file_t *f, pat_t *replace_pat, bool allow_nl)
}
}
replen = (size_t)(str-repstr);
- (void)matchchar(&str, quote, true);
+ (void)matchchar(&str, closequote, true);
} else {
repstr = "";
replen = 0;
@@ -339,8 +340,8 @@ static pat_t *_bp_simplepattern(file_t *f, const char *str)
return new_pat(f, start, str, 0, 0, BP_WORD_BOUNDARY);
}
// String literal
- case '"': case '\'': case '\002': {
- char endquote = c == '\002' ? '\003' : c;
+ case '"': case '\'': case '\002': case '{': {
+ char endquote = c == '\002' ? '\003' : (c == '{' ? '}' : c);
char *litstart = (char*)str;
while (str < f->end && *str != endquote)
str = next_char(f, str);