summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2011-02-27 14:10:51 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2011-03-07 02:41:25 -0800
commit8ea598c0a2b2987291ae03132a5e7d63c9473b54 (patch)
treed5c6f6e0590bafd7df41e9f1059883f2e6a49bb1
parent8d2629089afbbfa7ea9e253377363dcb271b187f (diff)
Support regex formatting with Pcre.
-rw-r--r--MobileCydia.mm20
1 files changed, 8 insertions, 12 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 6731a59..ab75fc1 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -878,7 +878,7 @@ class Pcre {
delete matches_;
}
- NSString *operator [](size_t match) {
+ NSString *operator [](size_t match) const {
return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])];
}
@@ -892,8 +892,12 @@ class Pcre {
return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
}
- _finline size_t size() const {
- return capture_;
+ NSString *operator ->*(NSString *format) const {
+ id values[capture_];
+ for (int i(0); i != capture_; ++i)
+ values[i] = this->operator [](i + 1);
+
+ return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast<va_list>(values)] autorelease];
}
};
/* }}} */
@@ -4078,15 +4082,7 @@ static NSString *Warning_;
}
- (NSString *) divert:(NSString *)url {
- if (!pattern_(url))
- return nil;
-
- size_t count(pattern_.size());
- id values[count];
- for (size_t i(0); i != count; ++i)
- values[i] = pattern_[i + 1];
-
- return [[[NSString alloc] initWithFormat:format_ arguments:reinterpret_cast<va_list>(values)] autorelease];
+ return !pattern_(url) ? nil : pattern_->*format_;
}
- (NSString *) key {