Boost C++ Libraries: Ticket #10131: [string_algo] trim_all_*() functions leaves a single asterisk in the string. https://svn.boost.org/trac10/ticket/10131 <p> I came along this problem while I wanted to reformat a string, to form a proper filename/path. Using string_algo's boost::trim_all* variants, I came across the problem when the originating string contained asterisk characters. The trim function would *always* leave at least one asterisk in the resulting string. </p> <p> Example source string: <code>"TEST_**???***_TEST"</code> </p> <p> Desired result is: <code>"TEST__TEST"</code> </p> <p> Using trim_all_*() </p> <pre class="wiki">result = trim_all_copy_if(source_string, is_any_of("\\/:*?\"&lt;&gt;|")); </pre><p> result: </p> <pre class="wiki">"TEST_*_TEST" </pre><p> escaping the asterisk in the predicate did not help: </p> <pre class="wiki">result = trim_all_copy_if(source_string, is_any_of("\\/:\\*?\"&lt;&gt;|")); </pre><p> same result: </p> <pre class="wiki">"TEST_*_TEST" </pre><p> However when using a trim_fill_*() variant with an empty replacement string: </p> <pre class="wiki">result = trim_fill_copy_if(test_sequence, "", is_any_of("\\/:*?\"&lt;&gt;|")); </pre><p> It did deliver the desired result: </p> <pre class="wiki">"TEST__TEST" </pre><p> This unexpected behavior of trim_all_*() is IMHO a bug. If not, it should probably be added to the documentation. </p> <p> example code attached. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10131 Trac 1.4.3 wburkhardt@… Wed, 18 Jun 2014 09:45:50 GMT attachment set https://svn.boost.org/trac10/ticket/10131 https://svn.boost.org/trac10/ticket/10131 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> Example to demonstrate the asterisk bug in string_algo </p> Ticket Marshall Clow Wed, 18 Jun 2014 09:59:04 GMT status changed https://svn.boost.org/trac10/ticket/10131#comment:1 https://svn.boost.org/trac10/ticket/10131#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I think it's a bug. Similarly, if you change the input to <code>TEST_???***_TEST</code>, you get an output of <code>TEST_?_TEST</code> </p> Ticket Steven Watanabe Thu, 26 Feb 2015 22:01:46 GMT <link>https://svn.boost.org/trac10/ticket/10131#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10131#comment:2</guid> <description> <p> This is definitely not a bug. The function is behaving exactly as expected. From the documentation, "trim_all removes all trailing and leading spaces from a sequence (string). In addition, spaces in the middle of the sequence are truncated to just one character." In this case, you're defining "whitespace" to be a set of characters. It sounds like the function that you really want is std::remove_copy_if. </p> </description> <category>Ticket</category> </item> <item> <author>Willi Burkhardt <wburkhardt@…></author> <pubDate>Fri, 27 Feb 2015 07:44:20 GMT</pubDate> <title>severity changed https://svn.boost.org/trac10/ticket/10131#comment:3 https://svn.boost.org/trac10/ticket/10131#comment:3 <ul> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Not Applicable</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10131#comment:2" title="Comment 2">steven_watanabe</a>: </p> <blockquote class="citation"> <p> This is definitely not a bug. The function is behaving exactly as expected. From the documentation, "trim_all removes all trailing and leading spaces from a sequence (string). In addition, spaces in the middle of the sequence are truncated to just one character." In this case, you're defining "whitespace" to be a set of characters. It sounds like the function that you really want is std::remove_copy_if. </p> </blockquote> <p> I agree. Despite having opened this bug 8 months ago, I cannot see this as a bug today. Not even for the documentation. As you state: "The function is behaving exactly as expected." I change the severity to "Not Applicable" as I cannot close the ticket myself. </p> Ticket Marshall Clow Fri, 27 Feb 2015 16:35:30 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10131#comment:4 https://svn.boost.org/trac10/ticket/10131#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket