diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-16 21:28:33 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-16 21:28:33 +0800 |
commit | 702218008ee2b6d708d6b2821cdef80736bb3224 (patch) | |
tree | d55ff7ce88187082378e7d8e4c2f3aad14d23b4e /Godeps/_workspace/src/github.com/obscuren/otto/builtin_regexp.go | |
parent | 202362d9258335c695eb75f55f4be74a50a1af33 (diff) | |
download | go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.gz go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.bz2 go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.lz go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.xz go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.zst go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.zip |
Add versioned dependencies from godep
Diffstat (limited to 'Godeps/_workspace/src/github.com/obscuren/otto/builtin_regexp.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/obscuren/otto/builtin_regexp.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/obscuren/otto/builtin_regexp.go b/Godeps/_workspace/src/github.com/obscuren/otto/builtin_regexp.go new file mode 100644 index 000000000..29d009dc2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/obscuren/otto/builtin_regexp.go @@ -0,0 +1,65 @@ +package otto + +import ( + "fmt" +) + +// RegExp + +func builtinRegExp(call FunctionCall) Value { + pattern := call.Argument(0) + flags := call.Argument(1) + if object := pattern._object(); object != nil { + if object.class == "RegExp" && flags.IsUndefined() { + return pattern + } + } + return toValue_object(call.runtime.newRegExp(pattern, flags)) +} + +func builtinNewRegExp(self *_object, _ Value, argumentList []Value) Value { + return toValue_object(self.runtime.newRegExp( + valueOfArrayIndex(argumentList, 0), + valueOfArrayIndex(argumentList, 1), + )) +} + +func builtinRegExp_toString(call FunctionCall) Value { + thisObject := call.thisObject() + source := toString(thisObject.get("source")) + flags := []byte{} + if toBoolean(thisObject.get("global")) { + flags = append(flags, 'g') + } + if toBoolean(thisObject.get("ignoreCase")) { + flags = append(flags, 'i') + } + if toBoolean(thisObject.get("multiline")) { + flags = append(flags, 'm') + } + return toValue_string(fmt.Sprintf("/%s/%s", source, flags)) +} + +func builtinRegExp_exec(call FunctionCall) Value { + thisObject := call.thisObject() + target := toString(call.Argument(0)) + match, result := execRegExp(thisObject, target) + if !match { + return NullValue() + } + return toValue_object(execResultToArray(call.runtime, target, result)) +} + +func builtinRegExp_test(call FunctionCall) Value { + thisObject := call.thisObject() + target := toString(call.Argument(0)) + match, _ := execRegExp(thisObject, target) + return toValue_bool(match) +} + +func builtinRegExp_compile(call FunctionCall) Value { + // This (useless) function is deprecated, but is here to provide some + // semblance of compatibility. + // Caveat emptor: it may not be around for long. + return UndefinedValue() +} |