[
  {
    "path": ".gitignore",
    "content": "*.o\n*.obj\nexample\nCMakeFiles\ncmake_install.cmake\nCMakeCache.txt\nCppVerbalExpressionsExample\nMakefile\n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7)\nPROJECT(CppVerbalExpressions)\n\nSET(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -O3 -std=c++11 -Wall -Wextra -Weffc++ -pedantic\")\nIF(IS_DIRECTORY /opt/boxen)\n\tSET(BOOST_ROOT /opt/boxen/homebrew)\nENDIF()\nFIND_PACKAGE(Boost 1.46.0 REQUIRED COMPONENTS regex)\n\nINCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS})\nADD_EXECUTABLE(CppVerbalExpressionsExample example.cpp)\nTARGET_LINK_LIBRARIES(CppVerbalExpressionsExample ${Boost_LIBRARIES})\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2013 whackashoe\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "CppVerbalExpressions\n====================\n\n\n## C++ Regular Expressions made easy\nVerbalExpressions is a C++11 Header library that helps to construct difficult regular expressions.\n\nThis C++ lib is based off of the (original) Javascript [VerbalExpressions](https://github.com/jehna/VerbalExpressions) library by [jehna](https://github.com/jehna/).\n\n## Other Implementations\nYou can see an up to date list of all ports on [VerbalExpressions.github.io](http://VerbalExpressions.github.io).\n- [Javascript](https://github.com/jehna/VerbalExpressions)\n- [Ruby](https://github.com/VerbalExpressions/RubyVerbalExpressions)\n- [C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions)\n- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)\n- [Java](https://github.com/VerbalExpressions/JavaVerbalExpressions)\n- [PHP](https://github.com/VerbalExpressions/PHPVerbalExpressions)\n\n## How to get started\n\nIn case you do not have C++11 compliant standard library you can still use boost.regex.\n\n## Examples\n\nHere's a couple of simple examples to give an idea of how VerbalExpressions works:\n\n### Testing if we have a valid URL\n\n```c++\n// Create an example of how to test for correctly formed URLs\nverex expr = verex()\n            .search_one_line()\n            .start_of_line()\n            .then( \"http\" )\n            .maybe( \"s\" )\n            .then( \"://\" )\n            .maybe( \"www.\" )\n            .anything_but( \" \" )\n            .end_of_line();\n\n// Use verex's test() function to find if it matches\nstd::cout << expr.test(\"https://www.google.com\") << std::endl;\n\n// Ouputs the actual expression used: ^(?:http)(?:s)?(?:://)(?:www.)?(?:[^ ]*)$\nstd::cout << expr << std::endl;\n```\n\n### Replacing strings\n\n```c++\n// Create a test string\nstd::string replaceMe = \"Replace bird with a duck\";\n// Create an expression that seeks for word \"bird\"\nverex expr2 = verex().find(\"bird\");\n// Execute the expression\nstd::cout << expr2.replace(replaceMe, \"duck\") << std::endl;\n```\n\n### Shorthand for string replace:\n\n```c++\nstd::cout << verex().find( \"red\" ).replace( \"We have a red house\", \"blue\" ) << std::endl;\n```\n\n\n\n\nHere you can find the API documentation for Verbal Expressions\n\n## Basic usage\nBasic usage of Verbal Expressions starts from the expression `verex()`. You can chain methods afterwards. Those are described under the \"terms\" section.\n\n```c++\nauto expr = verex();\n```\n\n## API\n\n### Terms\n* .anything()\n* .anything_but( const std::string & value )\n* .something()\n* .something_but(const std::string & value)\n* .end_of_line()\n* .find( const std::string & value )\n* .maybe( const std::string & value )\n* .start_of_line()\n* .then( const std::string & value )\n\n### Special characters and groups\n* .any( const std::string & value )\n* .any_of( const std::string & value )\n* .br()\n* .linebreak()\n* .range( const std::vector<std::pair<std::string, std::string>> & args )\n* .range( const std::std::string & a, const & std::string b )\n* .tab()\n* .word()\n\n### Modifiers\n* .with_any_case()\n* .search_one_line()\n* .search_global()\n\n### Functions\n* .replace( const std::string & source, const std::string & value )\n* .test()\n\n### Other\n* .add( expression )\n* .multiple( const std::string & value )\n* .alt()\n"
  },
  {
    "path": "example.cpp",
    "content": "#include \"verbalexpressions.hpp\"\n#include <iostream>\n#include <string>\n\nint main() {\n    using verex::verex;\n\n    // Create an example of how to test for correctly formed URLs\n    verex expr = verex()\n                .search_one_line()\n                .start_of_line()\n                .then( \"http\" )\n                .maybe( \"s\" )\n                .then( \"://\" )\n                .maybe( \"www.\" )\n                .anything_but( \" \" )\n                .end_of_line();\n\n    // Use VerEx's test() function to find if it matches\n    std::cout << (expr.test(\"https://www.google.com\") ? \"matches\" : \"doesn't match\") << std::endl;\n\n    // Ouputs the actual expression used\n    std::cout << expr << std::endl;\n\n\n    // Create a test string\n    std::string replaceMe = \"Replace bird with a duck\";\n    // Create an expression that seeks for word \"bird\"\n    verex expr2 = verex().find(\"bird\");\n    // Execute the expression\n    std::cout << expr2.replace(replaceMe, \"duck\") << std::endl;\n\n    // Shorthand string replace\n    std::cout << verex().find( \"red\" ).replace( \"We have a red house\", \"blue\" ) << std::endl;\n    return 0;\n}\n"
  },
  {
    "path": "verbalexpressions.hpp",
    "content": "/*!\n * VerbalExpressions C++ Library v0.1\n * https://github.com/whackashoe/C++VerbalExpressions\n *\n * The MIT License (MIT)\n *\n * Copyright (c) 2013 whackashoe\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n#ifndef VERBAL_EXPRESSIONS_H_\n#define VERBAL_EXPRESSIONS_H_\n\n\n#ifdef USE_BOOST\n#include <boost/regex.hpp>\nnamespace veregex = boost;\n#else\n#include <regex>\nnamespace veregex = std;\n#endif\n\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <utility>\n\nnamespace verex\n{\n\nclass verex\n{\nusing flag_type = veregex::regex::flag_type;\n\nprivate:\n    std::string prefixes;\n    std::string source;\n    std::string suffixes;\n    std::string pattern;\n    unsigned int modifiers;\n\n\n    enum Flags {\n        GLOBAL          = 1\n      , MULTILINE       = 2\n      , CASEINSENSITIVE = 4\n    };\n\n    friend std::ostream& operator<<(std::ostream &strm, verex &v)\n    {\n        return strm << v.pattern;\n    }\n\n    flag_type check_flags() const\n    {\n        return (modifiers & CASEINSENSITIVE) ? veregex::regex::icase : static_cast<flag_type>(0);\n    }\n\n    std::string reduce_lines(const std::string & value) const\n    {\n        const std::size_t pos = value.find(\"\\n\");\n\n        if(pos == std::string::npos) {\n            return value;\n        }\n\n        return value.substr(0, pos);\n    }\n\npublic:\n    verex() :\n          prefixes(\"\")\n        , source(\"\")\n        , suffixes(\"\")\n        , pattern(\"\")\n        , modifiers(0) {};\n\n    verex& operator=(const verex& ve) = default;\n    ~verex() = default;\n\n    verex & add(const std::string & value)\n    {\n        source = source + value;\n        pattern = prefixes + source + suffixes;\n        return (*this);\n    }\n\n    verex & start_of_line(const bool enable)\n    {\n        prefixes = enable ? \"^\" : \"\";\n        return add(\"\");\n    }\n\n    verex & start_of_line()\n    {\n        return start_of_line(true);\n    }\n\n    verex & end_of_line(const bool enable)\n    {\n        suffixes = enable ? \"$\" : \"\";\n        return add(\"\");\n    }\n\n    verex & end_of_line()\n    {\n        return end_of_line(true);\n    }\n\n    verex & then(const std::string & value)\n    {\n        return add(\"(?:\" + value + \")\");\n    }\n\n    verex & find(const std::string & value)\n    {\n        return then(value);\n    }\n\n    verex & maybe(const std::string & value)\n    {\n        return add(\"(?:\" + value + \")?\");\n    }\n\n    verex & anything()\n    {\n        return add(\"(?:.*)\");\n    }\n\n    verex & anything_but(const std::string & value)\n    {\n        return add(\"(?:[^\" + value + \"]*)\");\n    }\n\n    verex & something()\n    {\n        return add(\"(?:.+)\");\n    }\n\n    verex & something_but(const std::string & value)\n    {\n        return add(\"(?:[^\" + value + \"]+)\");\n    }\n\n    std::string replace(const std::string & source, const std::string & value)\n    {\n        return veregex::regex_replace(\n            source\n          , veregex::regex(pattern, check_flags())\n          , value\n        );\n    }\n\n    verex & linebreak()\n    {\n        return add(\"(?:(?:\\\\n)|(?:\\\\r\\\\n))\");\n    }\n\n    verex & br()\n    {\n        return linebreak();\n    }\n\n    verex & tab()\n    {\n        return add(\"\\\\t\");\n    }\n\n    verex & word()\n    {\n        return add(\"\\\\w+\");\n    }\n\n    verex & any_of(const std::string & value)\n    {\n        return add( \"[\" + value + \"]\" );\n    }\n\n    verex & any(const std::string & value)\n    {\n        return any_of(value);\n    }\n\n    verex & range(const std::vector<std::pair<std::string, std::string>> & args)\n    {\n        std::stringstream value;\n        value << \"[\";\n\n        for (const auto & item : args) {\n            const std::string from = item.first;\n            const std::string to   = item.second;\n\n            value << from << \"-\" << to;\n        }\n\n        value << \"]\";\n\n        return add(value.str());\n    }\n\n    verex & range(const std::string & a, const std::string & b)\n    {\n        return range({{a, b}});\n    }\n\n    verex & add_modifier(const char modifier)\n    {\n        switch (modifier) {\n            case 'i':\n                modifiers |= CASEINSENSITIVE;\n                break;\n            case 'm':\n                modifiers |= MULTILINE;\n                break;\n            case 'g':\n                modifiers |= GLOBAL;\n                break;\n            default:\n                break;\n        }\n\n        return (*this);\n    }\n\n    verex & remove_modifier(const char modifier)\n    {\n        switch (modifier) {\n            case 'i':\n                modifiers ^= CASEINSENSITIVE;\n                break;\n            case 'm':\n                modifiers ^= MULTILINE;\n                break;\n            case 'g':\n                modifiers ^= GLOBAL;\n                break;\n            default:\n                break;\n        }\n\n        return (*this);\n    }\n\n\n    verex & with_any_case(const bool enable)\n    {\n        if (enable) {\n            add_modifier('i');\n        } else {\n            remove_modifier('i');\n        }\n\n        return (*this);\n    }\n\n    verex & with_any_case()\n    {\n        return with_any_case(true);\n    }\n\n    verex & search_one_line(const bool enable)\n    {\n        if (enable) {\n            remove_modifier('m');\n        } else {\n            add_modifier('m');\n        }\n\n        return (*this);\n    }\n\n    verex & search_one_line()\n    {\n        return search_one_line(true);\n    }\n\n    verex & search_global(const bool enable)\n    {\n        if (enable) {\n            add_modifier('g');\n        } else {\n            remove_modifier('g');\n        }\n\n        return (*this);\n    }\n\n    verex & search_global()\n    {\n        return search_global(true);\n    }\n\n    verex & multiple(const std::string & value)\n    {\n        if (value.length() > 0 && value.at(0) != '*' && value.at(0) != '+') {\n            add(\"+\");\n        }\n\n        return add(value);\n    }\n\n    verex & alt(const std::string & value)\n    {\n        if (prefixes.find(\"(\") == std::string::npos) {\n            prefixes += \"(\";\n        }\n\n        if (suffixes.find(\")\") == std::string::npos) {\n            suffixes = \")\" + suffixes;\n        }\n\n        add(\")|(\");\n\n        return then(value);\n    }\n\n    bool test(const std::string & value)\n    {\n        const std::string to_test = (modifiers & MULTILINE) ? value : reduce_lines(value);\n\n        if (modifiers & GLOBAL) {\n            return veregex::regex_search(to_test, veregex::regex(pattern, check_flags()));\n        } else {\n            return veregex::regex_match(to_test, veregex::regex(pattern, check_flags()));\n        }\n    }\n};\n\n} // namespace verex\n\n#endif\n"
  }
]