Opened 8 years ago

Closed 8 years ago

#10131 closed Bugs (invalid)

[string_algo] trim_all_*() functions leaves a single asterisk in the string.

Reported by: wburkhardt@… Owned by: Marshall Clow
Milestone: To Be Determined Component: string_algo
Version: Boost 1.55.0 Severity: Not Applicable
Keywords: Cc:

Description

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.

Example source string: "TEST_**???***_TEST"

Desired result is: "TEST__TEST"

Using trim_all_*()

result = trim_all_copy_if(source_string, is_any_of("\\/:*?\"<>|"));

result:

"TEST_*_TEST"

escaping the asterisk in the predicate did not help:

result = trim_all_copy_if(source_string, is_any_of("\\/:\\*?\"<>|"));

same result:

"TEST_*_TEST"

However when using a trim_fill_*() variant with an empty replacement string:

result = trim_fill_copy_if(test_sequence, "", is_any_of("\\/:*?\"<>|"));

It did deliver the desired result:

"TEST__TEST"

This unexpected behavior of trim_all_*() is IMHO a bug. If not, it should probably be added to the documentation.

example code attached.

Attachments (1)

main.cpp (713 bytes ) - added by wburkhardt@… 8 years ago.
Example to demonstrate the asterisk bug in string_algo

Download all attachments as: .zip

Change History (5)

by wburkhardt@…, 8 years ago

Attachment: main.cpp added

Example to demonstrate the asterisk bug in string_algo

comment:1 by Marshall Clow, 8 years ago

Status: newassigned

I think it's a bug. Similarly, if you change the input to TEST_???***_TEST, you get an output of TEST_?_TEST

comment:2 by Steven Watanabe, 8 years ago

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.

in reply to:  2 comment:3 by Willi Burkhardt <wburkhardt@…>, 8 years ago

Severity: ProblemNot Applicable

Replying to steven_watanabe:

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.

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.

comment:4 by Marshall Clow, 8 years ago

Resolution: invalid
Status: assignedclosed
Note: See TracTickets for help on using tickets.