From 5da1d41ddfd91b8c6e2def1b0298261dd73c5b19 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 18 May 2016 10:17:05 +0200 Subject: [PATCH] Move case sensitivity option into glob2regex. --- lib/glob2regex/include/glob2regex/glob2regex.hpp | 2 +- lib/glob2regex/src/glob2regex.cpp | 4 ++-- lib/glob2regex/src/render_ast.cpp | 5 ++++- lib/glob2regex/src/render_ast.hpp | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/glob2regex/include/glob2regex/glob2regex.hpp b/lib/glob2regex/include/glob2regex/glob2regex.hpp index b247f85..6a751cb 100644 --- a/lib/glob2regex/include/glob2regex/glob2regex.hpp +++ b/lib/glob2regex/include/glob2regex/glob2regex.hpp @@ -22,7 +22,7 @@ #include namespace g2r { - std::string convert ( const std::string& parGlob ); + std::string convert ( const std::string& parGlob, bool parCaseSensitive=true ); } //namespace g2r #endif diff --git a/lib/glob2regex/src/glob2regex.cpp b/lib/glob2regex/src/glob2regex.cpp index e3d655b..eac480a 100644 --- a/lib/glob2regex/src/glob2regex.cpp +++ b/lib/glob2regex/src/glob2regex.cpp @@ -24,8 +24,8 @@ namespace g2r { namespace { } //unnamed namespace - std::string convert (const std::string& parGlob) { + std::string convert (const std::string& parGlob, bool parCaseSensitive) { const auto glob_ast = make_ast(parGlob); - return render_ast(glob_ast); + return render_ast(glob_ast, parCaseSensitive); } } //namespace g2r diff --git a/lib/glob2regex/src/render_ast.cpp b/lib/glob2regex/src/render_ast.cpp index d04b423..451fe0d 100644 --- a/lib/glob2regex/src/render_ast.cpp +++ b/lib/glob2regex/src/render_ast.cpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace ka = boost::spirit::karma; @@ -63,9 +64,11 @@ namespace g2r { } } //unnamed namespace - std::string render_ast (const GlobExpression& parAst) { + std::string render_ast (const GlobExpression& parAst, bool parCaseSensitive) { RegexGen gramm; std::ostringstream oss; + if (not parCaseSensitive) + oss << "(?i)"; oss << ka::format(gramm, parAst); oss << '$'; return oss.str(); diff --git a/lib/glob2regex/src/render_ast.hpp b/lib/glob2regex/src/render_ast.hpp index 118694b..c606921 100644 --- a/lib/glob2regex/src/render_ast.hpp +++ b/lib/glob2regex/src/render_ast.hpp @@ -23,7 +23,7 @@ #include namespace g2r { - std::string render_ast ( const GlobExpression& parAst ); + std::string render_ast ( const GlobExpression& parAst, bool parCaseSensitive ); } //namespace g2r #endif