|
|
|
|
|
"use strict"; |
|
|
|
function getRelocatable(re) { |
|
|
|
if (!re.__matchAtRelocatable) { |
|
|
|
|
|
|
|
var source = re.source + "|()"; |
|
|
|
|
|
var flags = "g" + (re.ignoreCase ? "i" : "") + (re.multiline ? "m" : "") + (re.unicode ? "u" : "") |
|
|
|
|
|
; |
|
|
|
re.__matchAtRelocatable = new RegExp(source, flags); |
|
} |
|
return re.__matchAtRelocatable; |
|
} |
|
|
|
function matchAt(re, str, pos) { |
|
if (re.global || re.sticky) { |
|
throw new Error("matchAt(...): Only non-global regexes are supported"); |
|
} |
|
var reloc = getRelocatable(re); |
|
reloc.lastIndex = pos; |
|
var match = reloc.exec(str); |
|
|
|
|
|
if (match[match.length - 1] == null) { |
|
|
|
match.length = match.length - 1; |
|
return match; |
|
} else { |
|
return null; |
|
} |
|
} |
|
|
|
module.exports = matchAt; |