diff --git a/docs/html/utils.html b/docs/html/utils.html index 788e54a..faeb7f4 100644 --- a/docs/html/utils.html +++ b/docs/html/utils.html @@ -10,6 +10,10 @@

Miscellaneous utility functions.

string strip (string)

Strip extra whitespace from both ends of the string, and remove line breaks anywhere in the string.

+

string trim (string)

+

Compatible implementation of String.prototype.trim(). Strips whitespace +from the beginning and end of the string, but doesn't remove any +whitespace inside the string like strip() does.

void extend (object a, object b)

Combine the properties of both objects into one. The properties from object 'b' are inserted into 'a'.

diff --git a/docs/utils.md b/docs/utils.md index 6acc66f..26b2d7a 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -5,6 +5,12 @@ Strip extra whitespace from both ends of the string, and remove line breaks anywhere in the string. +## string trim (string) + +Compatible implementation of `String.prototype.trim()`. Strips whitespace +from the beginning and end of the string, but doesn't remove any +whitespace inside the string like `strip()` does. + ## void extend (object a, object b) Combine the properties of both objects into one. The properties from diff --git a/src/brain.coffee b/src/brain.coffee index d82e88e..cebba4d 100644 --- a/src/brain.coffee +++ b/src/brain.coffee @@ -91,7 +91,7 @@ class Brain processCallTags: (reply, scope, async) -> reply = reply.replace(/\{__call__\}/g, "") reply = reply.replace(/\{\/__call__\}/g, "") - callRe = /(.+?)<\/call>/ig + callRe = /([\s\S]+?)<\/call>/ig argsRe = /{__call_arg__}([^{]*){\/__call_arg__}/ig giveup = 0 @@ -109,7 +109,7 @@ class Brain if not match break - text = utils.strip(match[1]) + text = utils.trim(match[1]) # get subroutine name subroutineNameMatch = (/(\S+)/ig).exec(text) diff --git a/src/utils.coffee b/src/utils.coffee index 569d64c..765352b 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -18,7 +18,19 @@ exports.strip = (text) -> text = text.replace(/^[\s\t]+/, "") \ .replace(/[\s\t]+$/, "") \ - .replace(/[\x0D\x0A]+/, ""); + .replace(/[\x0D\x0A]+/, "") + return text + +## +# string trim (string) +# +# Compatible implementation of `String.prototype.trim()`. Strips whitespace +# from the beginning and end of the string, but doesn't remove any +# whitespace inside the string like `strip()` does. +## +exports.trim = (text) -> + text = text.replace(/^[\x0D\x0A\s\t]+/, "") \ + .replace(/[\x0D\x0A\s\t]+$/, "") return text ## @@ -138,7 +150,7 @@ exports.clone = (obj) -> # Determines if obj looks like a promise ## exports.isAPromise = (obj) -> - return obj and obj.then and obj.catch and obj.finally and - typeof obj.then is 'function' and + return obj and obj.then and obj.catch and obj.finally and + typeof obj.then is 'function' and typeof obj.catch is 'function' and - typeof obj.finally is 'function' \ No newline at end of file + typeof obj.finally is 'function'