Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving strings from C source code
    primarykey
    data
    text
    <p>Can anyone point me to a program that strips off strings from C source code? Example</p> <pre><code>#include &lt;stdio.h&gt; static const char *place = "world"; char * multiline_str = "one \ two \ three\n"; int main(int argc, char *argv[]) { printf("Hello %s\n", place); printf("The previous line says \"Hello %s\"\n", place); return 0; } </code></pre> <p>becomes</p> <pre><code>#include &lt;stdio.h&gt; static const char *place = ; char * multiline_str = ; int main(int argc, char *argv[]) { printf(, place); printf(, place); return 0; } </code></pre> <p>What I am looking for is a program very much like <a href="http://www.bdc.cx/software/stripcmt/" rel="nofollow noreferrer">stripcmt</a> only that I want to strip strings and not comments.</p> <p>The reason that I am looking for an already developed program and not just some handy regular expression is because when you start considering all corner cases (quotes within strings, multi-line strings etc) things typically start to be (much) more complex than it first appears. And there are limits on what REs can achieve, I suspect it is not possible for this task. If you do think you have an <em>extremely</em> robust regular expression feel free to submit, but please no naive <code>sed 's/"[^"]*"//g'</code> like suggestions.</p> <p>(No need for special handling of (possibly un-ended) strings within comments, those will be removed first)</p> <p>Support for multi-line strings with embedded newlines is not important (not legal C), but strings spanning multiple lines ending with \ at the end must be supported.</p> <p>This is almost the same as the <a href="https://stackoverflow.com/questions/914913/regular-expression-for-stripping-strings-from-source-code">some</a> <a href="https://stackoverflow.com/questions/676296/how-to-tokenize-parse-string-literals-from-javascript-source-code">other</a> <a href="https://stackoverflow.com/questions/965667/regex-to-parse-c-source-code-to-find-all-strings">questions</a>, but I found no reference to any tools.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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