Option to trim a string

1 view
Skip to first unread message

Sunny

unread,
Mar 14, 2015, 1:49:31 PM3/14/15
to mozill...@googlegroups.com
While writing a script to fetch the number of commits in a given github repo, I encountered an issue.
The commit value was inside span tags.

<span class="num text-emphasized">
    8
</span>

I used ZestAssignStringDelimiter, like this

{
      "prefix": "<span class='num text-emphasized'>",
      "postfix": "</span>",
      "location": "BODY",
      "variableName": "commits",
      "index": 4,
      "enabled": true,
      "elementType": "ZestAssignStringDelimiters"
 }

and got commits = '      8  ', which isn't a number and ZestExpressionIsInteger fails to recognize it as an Integer.

When I try ZestExpressionEquals and compare it to '8', doesn't work.

I feel the need of a new property "trim", which would trim the left and right white-space around any string.
All the ZestAssign* statements could have this new property "trim" with Boolean value, default being false.

The above assignment statement would become,

{
      "prefix": "<span class='num text-emphasized'>",
      "postfix": "</span>",
      "location": "BODY",
      "variableName": "commits",
      "trim": true,
      "index": 4,
      "enabled": true,
      "elementType": "ZestAssignStringDelimiters"
 }

Thoughts?

Is there any other way to achieve what I am trying to achieve?

Simon Bennetts

unread,
Mar 20, 2015, 7:44:36 AM3/20/15
to mozill...@googlegroups.com
One option would be for the expression statements to always automatically trim variables before they are used.
So "  8 " would then be an integer and "  4  " would equal '8'.
It wouldnt require that many code changes.
What do you think?

But I'm also fine with us introducing a trim parameter if it would be useful in other situations :)

Cheers,

Simon

Sunny

unread,
Mar 20, 2015, 8:16:28 AM3/20/15
to mozill...@googlegroups.com
With auto-trimming of variables, there are chances of affecting statements like ZestExpressionLength. I think, introducing a trim parameter for String related statements would be a better option.

Sunny

unread,
Mar 20, 2015, 8:30:31 AM3/20/15
to mozill...@googlegroups.com
Parameter name - "trimWhitespace". False by default.

Sunny

unread,
Mar 24, 2015, 3:42:08 AM3/24/15
to mozill...@googlegroups.com
Added `trimWhitespace` support in zest-runner.js https://github.com/darkowlzz/zest-runner/commit/8d7359b344b7a899aa3d163afd24074c355a61dc
The option is available in ZestAssignString, ZestAssignStringDelimiter and ZestAssignRegexDelimiter.
Reply all
Reply to author
Forward
0 new messages