Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>mine uses a single regex to look for cases where trimming is necessary, and uses that regex's results to determine desired substring bounds:</p> <pre><code>var illmatch= /^(\s*)(?:.*?)(\s*)$/ function strip(me){ var match= illmatch.exec(me) if(match &amp;&amp; (match[1].length || match[2].length)){ me= me.substring(match[1].length, p.length-match[2].length) } return me } </code></pre> <p>the one design decision that went into this was using a substring to perform the final capture. s/\?:// (make the middle term capturing) and and the replacement fragment becomes:</p> <pre><code> if(match &amp;&amp; (match[1].length || match[3].length)){ me= match[2] } </code></pre> <p>there's two performance bets I made in these impls:</p> <ol> <li><p>does the substring implementation copy the original string's data? if so, in the first, when a string needs to be trimmed there is a double traversal, first in the regex (which may, hopefully be partial), and second in the substring extraction. hopefully a substring implementation only references the original string, so operations like substring can be nearly free. <em>cross fingers</em></p></li> <li><p>how good is the capture in the regex impl? the middle term, the output value, could potentially be very long. i wasn't ready to bank that all regex impls' capturing wouldn't balk at a couple hundred KB input capture, but i also did not test (too many runtimes, sorry!). the second ALWAYS runs a capture; if your engine can do this without taking a hit, perhaps using some of the above string-roping-techniques, for sure USE IT!</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload