aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/robertkrimen/otto/builtin_regexp.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-03-23 04:45:56 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-03-23 04:45:56 +0800
commit3133372a6a81c91528afbde58e22b3f9df257d03 (patch)
tree16778611a22c9fd249a94c88660cb0c6d297ce9b /Godeps/_workspace/src/github.com/robertkrimen/otto/builtin_regexp.go
parent59eab49cb849ca93b9608763f4842654e8044d0f (diff)
parent85acdadcfa99ea5c74907029cb63919cc0302c1a (diff)
downloadgo-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar
go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.gz
go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.bz2
go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.lz
go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.xz
go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.zst
go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.zip
Merge pull request #536 from zsfelfoldi/develop
using robertkrimen/otto, godeps updated
Diffstat (limited to 'Godeps/_workspace/src/github.com/robertkrimen/otto/builtin_regexp.go')
-rw-r--r--Godeps/_workspace/src/github.com/robertkrimen/otto/builtin_regexp.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/robertkrimen/otto/builtin_regexp.go b/Godeps/_workspace/src/github.com/robertkrimen/otto/builtin_regexp.go
new file mode 100644
index 000000000..99422510d
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/robertkrimen/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, 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 := thisObject.get("source").string()
+ flags := []byte{}
+ if thisObject.get("global").bool() {
+ flags = append(flags, 'g')
+ }
+ if thisObject.get("ignoreCase").bool() {
+ flags = append(flags, 'i')
+ }
+ if thisObject.get("multiline").bool() {
+ flags = append(flags, 'm')
+ }
+ return toValue_string(fmt.Sprintf("/%s/%s", source, flags))
+}
+
+func builtinRegExp_exec(call FunctionCall) Value {
+ thisObject := call.thisObject()
+ target := call.Argument(0).string()
+ 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 := call.Argument(0).string()
+ 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 Value{}
+}