QUERY: strip trailing whitespace ... woes :S

K

KevinGPO

I am wondering about what's the best and easiest way to strip trailing
whitespace from every single file in a folder, recursively.

I want to write a program/script so that you pass in a folder name and
it'll recursively go through all sub-folders and strips trailing
whitespace from every single file.

Trailing whitespace includes:

1. whitespaces at end of text lines, strip whitespace but retain text
2. whitespaces on empty lines, strip whitespace but leave the empty
line
 
R

Richard Herring

I am wondering about what's the best

Define "best". Fastest? Easiest to code?
and easiest

For the programmer or for the user?
way to strip trailing
whitespace from every single file in a folder, recursively.

I want to write a program/script so that you pass in a folder name and
it'll recursively go through all sub-folders and strips trailing
whitespace from every single file.

Standard C++ has no concept of "folder", "sub-folder" or even "every ...
file", so the solution is inevitably going to be platform-dependent and
off topic here. You might do better with a scripting language - for
example, perl has easy ways of applying operations to all matching
files.
Trailing whitespace includes:

1. whitespaces at end of text lines, strip whitespace but retain text
2. whitespaces on empty lines, strip whitespace but leave the empty
line

2 is just the special case of 1 when the text is of zero size. No need
to treat it specially.

std::string has lots of functions that might help - find_last_not_of,
for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top