Chris's Wiki :: blog/programming/GoSscanfTrailingText Commentshttps://utcc.utoronto.ca/~cks/space/blog/programming/GoSscanfTrailingText?atomcommentsDWiki2016-12-08T17:23:03ZRecent comments in Chris's Wiki :: blog/programming/GoSscanfTrailingText.By Chris Siebenmann on /blog/programming/GoSscanfTrailingTexttag:CSpace:blog/programming/GoSscanfTrailingText:f1343dca5ba28548a3ebe2f7be7a02a7c20fc1f2Chris Siebenmann<div class="wikitext"><p>The simple answer is that when you're calling <code>fmt.Sscanf()</code> in
particular, there is no buffer. All you have is the input string,
and <code>Sscanf</code> doesn't tell you where it stopped parsing so you can use
the rest of the string for something; effectively <code>Sscanf</code> consumes
the entire string. If someone stuffs newlines in that string when you
aren't expecting them to be there, as you aren't if you're using the
ending newline to create an error on trailing text, that's perverse input.</p>
<p>(In my specific case, the input string is the (Unix) command line
arguments to a program. Embedding a newline in command line arguments
is definitely being perverse; many scripts and commands will malfunction
in various fun ways if you do it.)</p>
</div>2016-12-08T17:23:03ZBy Brendan Long on /blog/programming/GoSscanfTrailingTexttag:CSpace:blog/programming/GoSscanfTrailingText:34f93d3fd345e43f51a3f044a3f5c40033411d74Brendan Longhttps://www.brendanlong.com<div class="wikitext"><p>I'm confused about why you consider "10:15\n and more" to be perverse input. Shouldn't the "and more" be left in the buffer to be used as later input date? For example, if your script had a y/n question after the time input, then "10:15\ny" would be valid input (and potentially useful for scripting).</p>
</div>2016-12-08T17:13:21Z