mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-22 00:19:24 +03:00
Optimization attempt: Captures contain start/end position instead of text
This commit is contained in:
parent
f559ad73a7
commit
c6c4d6413e
@ -50,9 +50,8 @@ public:
|
||||
|
||||
CefRefPtr<CefV8Value> BuildCaptureTree(OnigResult *result, int &index) {
|
||||
int currentIndex = index++;
|
||||
NSString *text = [result stringAt:currentIndex];
|
||||
int startPosition = [result locationAt:currentIndex];
|
||||
int endPosition = startPosition + [text length];
|
||||
int endPosition = startPosition + [result lengthAt:currentIndex];
|
||||
|
||||
CefRefPtr<CefV8Value> childCaptures;
|
||||
|
||||
@ -65,11 +64,17 @@ public:
|
||||
childCaptures->SetValue(childCaptures->GetArrayLength(), BuildCaptureTree(result, index));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CefRefPtr<CefV8Value> tree = CefV8Value::CreateObject(NULL, NULL);
|
||||
|
||||
tree->SetValue("index", CefV8Value::CreateInt(currentIndex), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
tree->SetValue("text", CefV8Value::CreateString([text UTF8String]), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
tree->SetValue("position", CefV8Value::CreateInt(startPosition), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
tree->SetValue("start", CefV8Value::CreateInt(startPosition), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
tree->SetValue("end", CefV8Value::CreateInt(endPosition), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
|
||||
if (currentIndex == 0) {
|
||||
tree->SetValue("text", CefV8Value::CreateString([[result stringAt:currentIndex] UTF8String]), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
|
||||
if (childCaptures.get()) tree->SetValue("captures", childCaptures, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
return tree;
|
||||
}
|
||||
|
@ -13,27 +13,28 @@ describe "OnigRegExp", ->
|
||||
expect(result).toBeNull()
|
||||
|
||||
describe ".getCaptureTree(string, index)", ->
|
||||
it "returns match with nested capture groups organized into a tree", ->
|
||||
fit "returns match with nested capture groups organized into a tree", ->
|
||||
regex = new OnigRegExp("a((bc)d)e(f(g)(h))(?=ij)")
|
||||
tree = regex.getCaptureTree("abcdefghij")
|
||||
expect(tree).toEqual
|
||||
text: "abcdefgh"
|
||||
index: 0
|
||||
position: 0
|
||||
start: 0
|
||||
end: 8
|
||||
captures: [
|
||||
{
|
||||
text: "bcd"
|
||||
index: 1
|
||||
position: 1
|
||||
captures: [{ text: "bc", index: 2, position: 1 }]
|
||||
start: 1
|
||||
end: 4
|
||||
captures: [{ index: 2, start: 1, end: 3 }]
|
||||
},
|
||||
{
|
||||
text: "fgh"
|
||||
index: 3
|
||||
position: 5
|
||||
start: 5
|
||||
end: 8
|
||||
captures: [
|
||||
{ text: "g", index: 4, position: 6 }
|
||||
{ text: "h", index: 5, position: 7 }
|
||||
{ index: 4, start: 6, end: 7 }
|
||||
{ index: 5, start: 7, end: 8 }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user