Add OnigRegExp.test

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-09 12:57:20 -06:00
parent 9b0a00a478
commit ad4b3db439
2 changed files with 21 additions and 7 deletions

View File

@@ -36,7 +36,12 @@ public:
return resultArray;
}
CefRefPtr<CefV8Value> Test(CefRefPtr<CefV8Value> string, CefRefPtr<CefV8Value> index) {
OnigResult *result = [m_regex search:stringFromCefV8Value(string) start:index->GetIntValue()];
return CefV8Value::CreateBool(result);
}
CefRefPtr<CefV8Value> GetCaptureIndices(CefRefPtr<CefV8Value> string, CefRefPtr<CefV8Value> index) {
OnigResult *result = [m_regex search:stringFromCefV8Value(string) start:index->GetIntValue()];
if ([result count] == 0) return CefV8Value::CreateNull();
@@ -88,11 +93,6 @@ bool OnigRegexpExtension::Execute(const CefString& name,
retval = userData->GetCaptureIndices(string, index);
return true;
}
else if (name == "buildOnigRegExp") {
CefRefPtr<CefBase> userData = new OnigRegexpUserData(arguments[0]);
retval = CefV8Value::CreateObject(userData, NULL);
return true;
}
else if (name == "search") {
CefRefPtr<CefV8Value> string = arguments[0];
CefRefPtr<CefV8Value> index = arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
@@ -100,6 +100,18 @@ bool OnigRegexpExtension::Execute(const CefString& name,
retval = userData->Search(string, index);
return true;
}
else if (name == "test") {
CefRefPtr<CefV8Value> string = arguments[0];
CefRefPtr<CefV8Value> index = arguments.size() > 1 ? arguments[1] : CefV8Value::CreateInt(0);
OnigRegexpUserData *userData = (OnigRegexpUserData *)object->GetUserData().get();
retval = userData->Test(string, index);
return true;
}
else if (name == "buildOnigRegExp") {
CefRefPtr<CefBase> userData = new OnigRegexpUserData(arguments[0]);
retval = CefV8Value::CreateObject(userData, NULL);
return true;
}
else if (name == "getCaptureCount") {
OnigRegexpUserData *userData = (OnigRegexpUserData *)object->GetUserData().get();
retval = userData->CaptureCount();

View File

@@ -1,8 +1,9 @@
(function() {
native function buildOnigRegExp(source);
native function search(string, index);
native function getCaptureIndices(source, index);
native function getCaptureIndices(string, index);
native function getCaptureCount();
native function test(string);
function OnigRegExp(source) {
var regexp = buildOnigRegExp(source);
@@ -13,6 +14,7 @@
}
OnigRegExp.prototype.search = search;
OnigRegExp.prototype.test = test;
OnigRegExp.prototype.getCaptureIndices = getCaptureIndices;
OnigRegExp.prototype.getCaptureCount = getCaptureCount;