mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add OnigRegExp.test
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user