From 757258dd98e319dc999902856ed84d6f9e1c411e Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 30 Jul 2012 18:21:57 -0600 Subject: [PATCH] Include 'indices' property on OnigRegExp result with capture group indices --- Atom/src/OnigRegexpExtension.mm | 5 +++++ spec/stdlib/onig-regexp-spec.coffee | 1 + 2 files changed, 6 insertions(+) diff --git a/Atom/src/OnigRegexpExtension.mm b/Atom/src/OnigRegexpExtension.mm index f524d6f93..2ecb84ae0 100644 --- a/Atom/src/OnigRegexpExtension.mm +++ b/Atom/src/OnigRegexpExtension.mm @@ -20,11 +20,16 @@ public: if ([result count] == 0) return CefV8Value::CreateNull(); CefRefPtr resultArray = CefV8Value::CreateArray(); + CefRefPtr indicesArray = CefV8Value::CreateArray(); + for (int i = 0; i < [result count]; i++) { resultArray->SetValue(i, CefV8Value::CreateString([[result stringAt:i] UTF8String])); + indicesArray->SetValue(i, CefV8Value::CreateInt([result locationAt:i])); } resultArray->SetValue("index", CefV8Value::CreateInt([result locationAt:0]), V8_PROPERTY_ATTRIBUTE_NONE); + resultArray->SetValue("indices", indicesArray, V8_PROPERTY_ATTRIBUTE_NONE); + return resultArray; } diff --git a/spec/stdlib/onig-regexp-spec.coffee b/spec/stdlib/onig-regexp-spec.coffee index b6b8cd9d8..dffd414d9 100644 --- a/spec/stdlib/onig-regexp-spec.coffee +++ b/spec/stdlib/onig-regexp-spec.coffee @@ -5,6 +5,7 @@ describe "OnigRegExp", -> result = regex.search("----a123----") expect(result).toEqual ["a123", "123"] expect(result.index).toBe 4 + expect(result.indices).toEqual [4, 5] it "returns null if it does not match", -> regex = new OnigRegExp("\\w(\\d+)")