mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
16 lines
436 B
TypeScript
16 lines
436 B
TypeScript
import { IDENTIFIER } from '../util/character'
|
|
import { Trie } from '../util/operator-trie'
|
|
|
|
export function matchOperator (str: string, begin: number, trie: Trie, end = str.length) {
|
|
let node = trie
|
|
let i = begin
|
|
let info
|
|
while (node[str[i]] && i < end) {
|
|
node = node[str[i++]]
|
|
if (node['end']) info = node
|
|
}
|
|
if (!info) return -1
|
|
if (info['needBoundary'] && str.charCodeAt(i) & IDENTIFIER) return -1
|
|
return i
|
|
}
|