Ensure that the compiler properly supports regex
authorKyle Fuller <redacted>
Wed, 15 Jun 2016 17:05:31 +0000 (10:05 -0700)
committerKyle Fuller <redacted>
Wed, 15 Jun 2016 17:05:31 +0000 (10:05 -0700)
.gitignore
Makefile
README.md
test-regex.cpp [new file with mode: 0644]

index 3ddf49984bbc630b3ef97e8b27b176fdd86cd3d8..1a36729eae9a2a3067a7d17592b635c9e3ba1a78 100644 (file)
@@ -1 +1,2 @@
-palaver.so
\ No newline at end of file
+palaver.so
+test-regex
index 71640d1e85c09c50fbecfac2458c9c63d68532be..e51c89c8575a3890bd9c0d5d2b7f1b56130adddd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
 PALAVER_VERSION := $(shell git describe --tags --always --dirty 2> /dev/null || cat VERSION)
 CXXFLAGS := -Wno-unknown-pragmas -DPALAVER_VERSION=\"$(PALAVER_VERSION)\"
 
-palaver.so: palaver.cpp
+palaver.so: test palaver.cpp
+       @echo "Building palaver.so"
        @CXXFLAGS="$(CXXFLAGS)" znc-buildmod palaver.cpp
 
 install: palaver.so
@@ -16,3 +17,9 @@ uninstall:
        @echo "Uninstall palaver from $(HOME)/.znc/modules"
        -rm -f $(HOME)/.znc/modules/palaver.so
 
+test-regex: test-regex.cpp
+       @c++ -std=c++11 test-regex.cpp -o test-regex
+
+.PHONY: test
+test: test-regex
+       @./test-regex
index 4c5bad134ac9844a60159eaba6d35ff5bb057793..d2d134f2e1a8e7634f7fe5ba11883adb74b0cfcb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -98,3 +98,10 @@ To solve this problem you can force IPv4 connections in ZNC using:
 ```
 /msg *status setbindhost 0.0.0.0
 ```
+
+###### Caught regex error
+
+This error indicates a problem with the C++ regex implementation in your C++
+compiler. Older versions of GCC have buggy implementations of regex and are
+incompatible with the module. GCC 4.9 or newer, and Clang are known to work.
+Please upgrade to a modern version.
diff --git a/test-regex.cpp b/test-regex.cpp
new file mode 100644 (file)
index 0000000..f3c77c6
--- /dev/null
@@ -0,0 +1,23 @@
+#include <iostream>
+#include <regex>
+
+
+int main(int argc, const char *argv[]) {
+    std::smatch match;
+    std::string message = "Hello nickname.";
+    std::string matcher = "\\bnickname\\b";
+
+    try {
+        std::regex expression = std::regex(matcher, std::regex_constants::ECMAScript | std::regex_constants::icase);
+        std::regex_search(message, match, expression);
+    } catch (std::regex_error& error) {
+        std::cout << "Your C++ compiler doesn't properly support regex. Please upgrade to GCC 4.9, Clang or newer.\n";
+        return 1;
+    }
+
+    if (match.empty()) {
+        return 1;
+    }
+
+    return 0;
+}
git clone https://git.99rst.org/PROJECT