Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Jerry Coffin, I just got back from appointment from Lexington. This version has been tested. I apologize for the first version which I hastily wrote in a rush to get to my dentist in Lexington. </p> <pre><code>void iterative_trim_whitespace(const char* src, char* target){ bool firstspace(true); while (*src != '\x0'){ if (firstspace){ *target++ = *src++; } else{ src++; } if (firstspace &amp;&amp; isspace(*(src - 1))){ firstspace = false; } else{ firstspace = true; } } *target = '\x0'; } </code></pre> <hr> <pre><code>void iterative_trim_whitespace_revised(const char* src, char* target){ bool firstspace(true); int ct(0); while (*src != '\x0'){ if (firstspace){ *target++ = *src++; } else{ src += ct - 2; } if (firstspace){ char *x = (char *)src - 1; ct = 1; bool sentinel(false); while(isspace(*(x + (ct - 1)))){ ct += 1; sentinel = true; } if (sentinel){ firstspace = false; } } else{ ct = 1; firstspace = true; } } *target = '\x0'; } </code></pre> <hr> <p>void iterative_trim_whitespace_friday_5Timesfaster(const char* src, char* target){ bool firstspace(true); int ct(0); while (*src != '\x0'){ if (firstspace){ *target++ = *src++; } else{ src += ct - 2; }</p> <pre><code> if (firstspace){ char *x = (char *)src - 1; ct = 1; bool sentinel(false); while(*(x + (ct - 1)) == ' '){ ct += 1; sentinel = true; } if (sentinel){ firstspace = false; } } else{ ct = 1; firstspace = true; } } *target = '\x0'; </code></pre> <p>}</p> <p>// Here is our ProjectDirector's version from this morning // TrimLeading() and TrimTrailing are additional inline functions</p> <p>void iterative_trim_whitespace_ProjectDirector(const char* src, char* target){</p> <pre><code>int out=0; for (int i=0;src[i]!= '\x0';i++) { if (src[i] != ' ' || src[i+1] != ' '){ target[out++]=src[i]; } } target[out]= '\x0'; </code></pre> <p>}</p>
 

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