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: | 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)
Change History (5)
by , 8 years ago
comment:1 by , 8 years ago
Status: | new → assigned |
---|
I think it's a bug.
Similarly, if you change the input to TEST_???***_TEST
, you get an output of TEST_?_TEST
follow-up: 3 comment:2 by , 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.
comment:3 by , 8 years ago
Severity: | Problem → Not 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 , 8 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
Example to demonstrate the asterisk bug in string_algo