]> git.saurik.com Git - cydia.git/blobdiff - CyteKit/PerlCompatibleRegEx.hpp
Revert "Do not double log fetch errors."
[cydia.git] / CyteKit / PerlCompatibleRegEx.hpp
index 3bd5e7650e4af7cc1726ec8828c383d060a55fa4..38a9462a3a97a497437d5f7a4cbf1f17b47cdfca 100644 (file)
@@ -42,7 +42,8 @@
 
 #include <pcre.h>
 
-#include "CyteKit/NSString-Cyte.h"
+#include "CyteKit/UCPlatform.h"
+#include "CyteKit/stringWithUTF8Bytes.h"
 
 class Pcre {
   private:
@@ -55,15 +56,20 @@ class Pcre {
   public:
     Pcre() :
         code_(NULL),
-        study_(NULL)
+        study_(NULL),
+        data_(NULL)
     {
     }
 
-    Pcre(const char *regex) :
+    Pcre(const char *regex, NSString *data = nil) :
         code_(NULL),
-        study_(NULL)
+        study_(NULL),
+        data_(NULL)
     {
         this->operator =(regex);
+
+        if (data != nil)
+            this->operator ()(data);
     }
 
     void operator =(const char *regex) {
@@ -101,8 +107,17 @@ class Pcre {
     }
 
     bool operator ()(const char *data, size_t size) {
-        data_ = data;
-        return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
+        if (pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0) {
+            data_ = data;
+            return true;
+        } else {
+            data_ = NULL;
+            return false;
+        }
+    }
+
+    operator bool() const {
+        return data_ != NULL;
     }
 
     NSString *operator ->*(NSString *format) const {