Modify

Ticket #1808 (new Feature Requests)

Opened 6 years ago

Last modified 2 years ago

Trim middle

Reported by: Olaf van der Spek Owned by: marshall
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

Change History

comment:1 Changed 6 years ago by OlafvdSpek@…

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

comment:2 Changed 4 years ago by olafvdspek@…

Pavol?

comment:3 Changed 4 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 4 years ago by anonymous

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

comment:5 Changed 4 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 4 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 3 years ago by anonymous

Pavol?

comment:8 Changed 3 years ago by anonymous

  • Milestone changed from Boost 1.36.0 to Boost 1.46.0

comment:9 Changed 3 years ago by olafvdspek@…

Hi Pavol,

What's the status of this issue?

comment:10 Changed 2 years ago by marshall

  • Owner changed from pavol_droba to marshall
  • Component changed from string_algo to algorithm

comment:11 Changed 2 years ago by marshall

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 2 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 2 years ago by marshall

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 2 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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
Author


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

 
Note: See TracTickets for help on using tickets.