Modify

Opened 10 years ago

Last modified 6 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.

Attachments (0)

Change History (14)

comment:1 Changed 10 years ago by OlafvdSpek@…

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

comment:2 Changed 8 years ago by olafvdspek@…

Pavol?

comment:3 Changed 8 years ago by anonymous

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 Changed 8 years ago by anonymous

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

comment:5 Changed 8 years ago by Pavol Droba

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 Changed 7 years ago by olafvdspek@…

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 Changed 7 years ago by anonymous

Pavol?

comment:8 Changed 7 years ago by anonymous

Milestone: Boost 1.36.0Boost 1.46.0

comment:9 Changed 7 years ago by olafvdspek@…

Hi Pavol,

What's the status of this issue?

comment:10 Changed 6 years ago by Marshall Clow

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

comment:11 Changed 6 years ago by Marshall Clow

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 Changed 6 years ago by Olaf van der Spek <olafvdspek@…>

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 Changed 6 years ago by Marshall Clow

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 Changed 6 years ago by Olaf van der Spek <olafvdspek@…>

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Marshall Clow.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.