From ecd0c2981a5cb3d704864313e0e2ec68be4990fa Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Fri, 26 Oct 2018 08:34:47 +0200 Subject: [PATCH] Recognize [:graph:] & [:print:] classifications (#12) Passes 3 more of the original integration tests in tests.txt that had been previously commented out in 146667d. --- MAB.DotIgnore.Test/test_content/tests.txt | 6 +++--- MAB.DotIgnore/WildMatch.cs | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/MAB.DotIgnore.Test/test_content/tests.txt b/MAB.DotIgnore.Test/test_content/tests.txt index c60ce61..d14d86e 100644 --- a/MAB.DotIgnore.Test/test_content/tests.txt +++ b/MAB.DotIgnore.Test/test_content/tests.txt @@ -85,10 +85,10 @@ 1 1 5 [[:xdigit:]] 1 1 f [[:xdigit:]] 1 1 D [[:xdigit:]] -#1 1 _ [[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]] +1 1 _ [[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]] #1 1 … [^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]] -#1 1  [^[:alnum:][:alpha:][:blank:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]] -#1 1 . [^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]] +1 1  [^[:alnum:][:alpha:][:blank:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]] +1 1 . [^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]] 1 1 5 [a-c[:digit:]x-z] 1 1 b [a-c[:digit:]x-z] 1 1 y [a-c[:digit:]x-z] diff --git a/MAB.DotIgnore/WildMatch.cs b/MAB.DotIgnore/WildMatch.cs index 50c9274..9d9abd7 100644 --- a/MAB.DotIgnore/WildMatch.cs +++ b/MAB.DotIgnore/WildMatch.cs @@ -264,21 +264,21 @@ private static int Match(char[] pattern, char[] text, int p, int t, MatchFlags f if (Char.IsDigit(t_ch)) match = 1; } - // else if (CC_EQ(pattern, s, i, "graph")) - // { - // if (ISGRAPH(t_ch)) - // match = 1; - // } + else if (CC_EQ(pattern, s, i, "graph")) + { + if (ISGRAPH(t_ch)) + match = 1; + } else if (CC_EQ(pattern, s, i, "lower")) { if (Char.IsLower(t_ch)) match = 1; } - // else if (CC_EQ(pattern, s, i, "print")) - // { - // if (ISPRINT(t_ch)) - // match = 1; - // } + else if (CC_EQ(pattern, s, i, "print")) + { + if (ISPRINT(t_ch)) + match = 1; + } else if (CC_EQ(pattern, s, i, "punct")) { if (Char.IsPunctuation(t_ch)) @@ -335,5 +335,8 @@ static bool CC_EQ(char[] pattern, int s, int len, string @class) { return string.Compare(new String(pattern, s, len), @class, StringComparison.Ordinal) == 0; } + + static bool ISPRINT(char ch) => ch >= 0x20 && ch <= 0x7e; + static bool ISGRAPH(char ch) => ISPRINT(ch) && ch != 0x20; } }