How can I ignore certain strings in my string centring function?
<p><em>N.B: Directly connected to a <a href="https://stackoverflow.com/questions/20097537/count-occurrence-of-a-set-of-characters-and-subtract-spaces-from-the-string">problem I had a few years ago</a>, but I'd like to resolve the first issue there which wasn't otherwise part of the question, so please don't flag it as a duplicate of my earlier question.</em></p>

<p>I have a <a href="https://stackoverflow.com/a/17513466/2422013">string centring function</a> that centres the given string according to the given width (which is 113 characters):</p>

<pre><code>std::string center(std::string input, int width = 113) { 
    return std::string((width - input.length()) / 2, ' ') + input;
}
</code></pre>

<p>I am using a game SDK in order to create a gameserver modification, and this game SDK supports coloured strings in the game's command console, which are denoted using a dollar sign and a number from 0-9 (i.e, <code>$1</code>) and are not printed in the console itself.</p>

<p>The string centring function above treats these markers as part of the total string, so I want to add the total amount of characters these markers take up to the width so that the string is actually centred.</p>

<p>I have tried modifying the function:</p>

<pre><code>std::string centre(std::string input, int width = 113) { 
    std::ostringstream pStream;
    for(std::string::size_type i = 0; i &lt; input.size(); ++i) {
        if (i+1 &gt; input.length()) break;
        pStream &lt;&lt; input[i] &lt;&lt; input[i+1];
        CryLogAlways(pStream.str().c_str());
        if (pStream.str() == "$1" || pStream.str() == "$2" || pStream.str() == "$3" || pStream.str() == "$4" || pStream.str() == "$5" || pStream.str() == "$6" || pStream.str() == "$7" || pStream.str() == "$8" || pStream.str() == "$9" || pStream.str() == "$0")
            width = width+2;
        pStream.clear();
    }
    return std::string((width - input.length()) / 2, ' ') + input;
}
</code></pre>

<p>The goal of the above function is to iterate through the string, add the current character and the next to an <code>ostringstream</code>, and evaluate the <code>ostringstream</code>.</p>

<p>This didn't exactly do as I wanted:</p>

<pre><code>&lt;16:58:57&gt; 8I
&lt;16:58:57&gt; 8IIn
&lt;16:58:57&gt; 8IInnc
&lt;16:58:57&gt; 8IInncco
&lt;16:58:57&gt; 8IInnccoom
&lt;16:58:57&gt; 8IInnccoommi
&lt;16:58:57&gt; 8IInnccoommiin
&lt;16:58:57&gt; 8IInnccoommiinng
&lt;16:58:57&gt; 8IInnccoommiinngg 
&lt;16:58:57&gt; 8IInnccoommiinngg  C
&lt;16:58:57&gt; 8IInnccoommiinngg  CCo
&lt;16:58:57&gt; 8IInnccoommiinngg  CCoon
&lt;16:58:57&gt; 8IInnccoommiinngg  CCoonnn
&lt;16:58:57&gt; 8IInnccoommiinngg  CCoonnnne
</code></pre>

<p><em>(snippet from server log)</em></p>

<p>Here's a brief summary of the issue:</p>

<p><a href="https://i.stack.imgur.com/ZbPptl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZbPptl.jpg" alt="enter image description here"></a></p>

<p>I think I might be missing how iteration works; what am I missing, and how can I make this function work in the way I want it to?</p>