summaryrefslogtreecommitdiff
path: root/quote.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-19 20:22:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-07-19 20:22:17 (GMT)
commita883c31af66195556a775f75851f46573c98e43d (patch)
tree895fcd7abecd46cf97821bdad4bc8d64b3c4c142 /quote.c
parenta63d31b4d3640960d9a71606eee80c32459f906e (diff)
parent695f95ba5dc4ab44f327574f85c3ebe7ebf449b1 (diff)
downloadgit-a883c31af66195556a775f75851f46573c98e43d.zip
git-a883c31af66195556a775f75851f46573c98e43d.tar.gz
git-a883c31af66195556a775f75851f46573c98e43d.tar.bz2
Merge branch 'nd/icase'
"git grep -i" has been taught to fold case in non-ascii locales correctly. * nd/icase: grep.c: reuse "icase" variable diffcore-pickaxe: support case insensitive match on non-ascii diffcore-pickaxe: Add regcomp_or_die() grep/pcre: support utf-8 gettext: add is_utf8_locale() grep/pcre: prepare locale-dependent tables for icase matching grep: rewrite an if/else condition to avoid duplicate expression grep/icase: avoid kwsset when -F is specified grep/icase: avoid kwsset on literal non-ascii strings test-regex: expose full regcomp() to the command line test-regex: isolate the bug test code grep: break down an "if" stmt in preparation for next changes
Diffstat (limited to 'quote.c')
-rw-r--r--quote.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/quote.c b/quote.c
index b281a8f..53b98a5 100644
--- a/quote.c
+++ b/quote.c
@@ -453,3 +453,40 @@ void tcl_quote_buf(struct strbuf *sb, const char *src)
}
strbuf_addch(sb, '"');
}
+
+void basic_regex_quote_buf(struct strbuf *sb, const char *src)
+{
+ char c;
+
+ if (*src == '^') {
+ /* only beginning '^' is special and needs quoting */
+ strbuf_addch(sb, '\\');
+ strbuf_addch(sb, *src++);
+ }
+ if (*src == '*')
+ /* beginning '*' is not special, no quoting */
+ strbuf_addch(sb, *src++);
+
+ while ((c = *src++)) {
+ switch (c) {
+ case '[':
+ case '.':
+ case '\\':
+ case '*':
+ strbuf_addch(sb, '\\');
+ strbuf_addch(sb, c);
+ break;
+
+ case '$':
+ /* only the end '$' is special and needs quoting */
+ if (*src == '\0')
+ strbuf_addch(sb, '\\');
+ strbuf_addch(sb, c);
+ break;
+
+ default:
+ strbuf_addch(sb, c);
+ break;
+ }
+ }
+}