Skip to content

Commit

Permalink
Merge pull request #109 from aichaos/bug/108-call-arg-newline
Browse files Browse the repository at this point in the history
Fix line breaks ruining call tag regexp
  • Loading branch information
kirsle committed May 5, 2016
2 parents 4045422 + 6bbfda3 commit 1e46bee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/html/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ <h1>Miscellaneous utility functions.</h1>
<h2>string strip (string)</h2>
<p>Strip extra whitespace from both ends of the string, and remove
line breaks anywhere in the string.</p>
<h2>string trim (string)</h2>
<p>Compatible implementation of <code>String.prototype.trim()</code>. Strips whitespace
from the beginning and end of the string, but doesn't remove any
whitespace inside the string like <code>strip()</code> does.</p>
<h2>void extend (object a, object b)</h2>
<p>Combine the properties of both objects into one. The properties from
object 'b' are inserted into 'a'.</p>
Expand Down
6 changes: 6 additions & 0 deletions docs/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/brain.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Brain
processCallTags: (reply, scope, async) ->
reply = reply.replace(/\{__call__\}/g, "<call>")
reply = reply.replace(/\{\/__call__\}/g, "</call>")
callRe = /<call>(.+?)<\/call>/ig
callRe = /<call>([\s\S]+?)<\/call>/ig
argsRe = /{__call_arg__}([^{]*){\/__call_arg__}/ig

giveup = 0
Expand All @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions src/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down Expand Up @@ -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'
typeof obj.finally is 'function'

0 comments on commit 1e46bee

Please sign in to comment.