Opened 15 years ago

Last modified 11 years ago

#1808 new Feature Requests

Trim middle

Reported by: Olaf van der Spek Owned by: Marshall Clow
Milestone: Boost 1.46.0 Component: algorithm
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc:

Description

Could you add a function to trim 'internal' whitespace? I think two functions would be handy, one for single-line data and one for multi-line data. The single-line one would replace all internal whitespace by a single space character. The multi-line one would replace multiple empty lines by a single empty line and remove trailing whitespace from each line.

Change History (14)

comment:1 by OlafvdSpek@…, 15 years ago

I hate Trac! Anyway, my email address is OlafvdSpek@GMail.Com

comment:2 by olafvdspek@…, 12 years ago

Pavol?

comment:3 by anonymous, 12 years ago

Sorry for not responding. Generally I can offer you a deal: You code it and I can integrate it into the library. I agree that the function is useful. I would only suggest to call it compress_spaces.

comment:4 by anonymous, 12 years ago

Sounds fair. What should the multi-line version be called?

comment:5 by Pavol Droba, 12 years ago

Maybe the multi-line version is not realy necessary. You can replace it by two calls to the compress functions with different space specifications.

Also try to think, how to handle different line endings (<CR>,<LF>,<CR><LF>) If might be possible to define the compress function via means of find/replace framework. There is even one example in the library that does something similar.

Send me an email when you will have something to show at droba -at - topmail -dot- sk

comment:6 by olafvdspek@…, 12 years ago

return ::boost::algorithm::find_format_all_copy(
	::boost::trim_copy(v),
	::boost::algorithm::token_finder(boost::is_space(),	::boost::algorithm::token_compress_on),
	::boost::algorithm::const_formatter(" "))

comment:7 by anonymous, 12 years ago

Pavol?

comment:8 by anonymous, 12 years ago

Milestone: Boost 1.36.0Boost 1.46.0

comment:9 by olafvdspek@…, 12 years ago

Hi Pavol,

What's the status of this issue?

comment:10 by Marshall Clow, 11 years ago

Component: string_algoalgorithm
Owner: changed from Pavol Droba to Marshall Clow

comment:11 by Marshall Clow, 11 years ago

Is there some reason that boost::algorithm::trim_all doesn't do what you want?

        //! Trim All
        /*!
            Remove all leading and trailing spaces from the input and
            compress all other spaces to a single character.

comment:12 by Olaf van der Spek <olafvdspek@…>, 11 years ago

Hi Marshall,

trim_all is the response to this request. ;)

However, it's not quite right yet. It should compress all spaces to a single space, not a single character.

comment:13 by Marshall Clow, 11 years ago

And trim_fill (blah, " ") doesn't do that?

        //! Trim Fill
        /*!
            Remove all leading and trailing spaces from the input and
            replace all every block of consecutive spaces with a fill string
            defined by user.

I'm not trying to be a pain here, just trying to understand.

comment:14 by Olaf van der Spek <olafvdspek@…>, 11 years ago

Ah, yes, trim_fill was created to work around that problem. The original idea was for trim_all to do that from the start, without having to manually specify the 'fill' character/string.

Note: See TracTickets for help on using tickets.