From 9e0f9f2ee7f854665c6fbf442ea8339bbce17ecb Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Tue, 24 Feb 2009 11:43:13 +0000 Subject: Escape-sequence validation in place (for nodes). --- strings.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'strings.c') diff --git a/strings.c b/strings.c index 2b7cd4fc..3e9415c5 100644 --- a/strings.c +++ b/strings.c @@ -35,6 +35,50 @@ extern char *strptime(const char *, const char *, struct tm *); #endif + +size_t +mdoc_isescape(const char *p) +{ + size_t c; + + if ('\\' != *p++) + return(0); + + switch (*p) { + case ('\\'): + /* FALLTHROUGH */ + case ('\''): + /* FALLTHROUGH */ + case ('`'): + /* FALLTHROUGH */ + case ('-'): + /* FALLTHROUGH */ + case (' '): + /* FALLTHROUGH */ + case ('.'): + /* FALLTHROUGH */ + case ('e'): + return(2); + case ('('): + if (0 == *++p) + return(0); + if (0 == *++p) + return(0); + return(4); + case ('['): + break; + default: + return(0); + } + + for (c = 3, p++; *p && ']' != *p; p++, c++) + if (isspace(*p)) + break; + + return(*p == ']' ? c : 0); +} + + int mdoc_iscdelim(char p) { -- cgit