Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Evil C:</p> <pre><code>#include &lt;stdio.h&gt; void strrev(char *p) { char *q = p; while(q &amp;&amp; *q) ++q; for(--q; p &lt; q; ++p, --q) *p = *p ^ *q, *q = *p ^ *q, *p = *p ^ *q; } int main(int argc, char **argv) { do { printf("%s ", argv[argc-1]); strrev(argv[argc-1]); printf("%s\n", argv[argc-1]); } while(--argc); return 0; } </code></pre> <p>(This is XOR-swap thing. Take care to note that you <em>must avoid</em> swapping with self, because a^a==0.)</p> <hr> <h2>Ok, fine, let's fix the UTF-8 chars...</h2> <pre><code>#include &lt;bits/types.h&gt; #include &lt;stdio.h&gt; #define SWP(x,y) (x^=y, y^=x, x^=y) void strrev(char *p) { char *q = p; while(q &amp;&amp; *q) ++q; /* find eos */ for(--q; p &lt; q; ++p, --q) SWP(*p, *q); } void strrev_utf8(char *p) { char *q = p; strrev(p); /* call base case */ /* Ok, now fix bass-ackwards UTF chars. */ while(q &amp;&amp; *q) ++q; /* find eos */ while(p &lt; --q) switch( (*q &amp; 0xF0) &gt;&gt; 4 ) { case 0xF: /* U+010000-U+10FFFF: four bytes. */ SWP(*(q-0), *(q-3)); SWP(*(q-1), *(q-2)); q -= 3; break; case 0xE: /* U+000800-U+00FFFF: three bytes. */ SWP(*(q-0), *(q-2)); q -= 2; break; case 0xC: /* fall-through */ case 0xD: /* U+000080-U+0007FF: two bytes. */ SWP(*(q-0), *(q-1)); q--; break; } } int main(int argc, char **argv) { do { printf("%s ", argv[argc-1]); strrev_utf8(argv[argc-1]); printf("%s\n", argv[argc-1]); } while(--argc); return 0; } </code></pre> <ul> <li>Why, yes, if the input is borked, this will cheerfully swap outside the place.</li> <li>Useful link when vandalising in the UNICODE: <a href="http://www.macchiato.com/unicode/chart/" rel="noreferrer">http://www.macchiato.com/unicode/chart/</a></li> <li>Also, UTF-8 over 0x10000 is untested (as I don't seem to have any font for it, nor the patience to use a hexeditor)</li> </ul> <p>Examples:</p> <pre><code>$ ./strrev Räksmörgås ░▒▓○◔◑◕● ░▒▓○◔◑◕● ●◕◑◔○▓▒░ Räksmörgås sågrömskäR ./strrev verrts/. </code></pre>
 

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