added removeTrailingWhitespace

This commit is contained in:
fluxgen 2003-10-25 22:06:53 +00:00
parent ab2d5ca0c7
commit 233a4d85f4
2 changed files with 33 additions and 19 deletions

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: StringUtil.cc,v 1.7 2003/09/29 14:01:48 fluxgen Exp $
// $Id: StringUtil.cc,v 1.8 2003/10/25 22:06:53 fluxgen Exp $
#include "StringUtil.hh"
@ -89,7 +89,7 @@ string expandFilename(const std::string &filename) {
}
/**
@return string from last "." to end of string
@return string from last "." to end of string
*/
string findExtension(const std::string &filename) {
//get start of extension
@ -185,6 +185,19 @@ string::size_type removeFirstWhitespace(std::string &str) {
return first_pos;
}
string::size_type removeTrailingWhitespace(std::string &str) {
// strip trailing whitespace
string::size_type first_pos = str.find_first_not_of(" \t");
if (first_pos != string::npos) {
string::size_type last_pos = str.find_first_of(" \t", first_pos);
while (last_pos != string::npos) {
str.erase(last_pos);
last_pos = str.find_first_of(" \t", last_pos);
}
}
}
}; // end namespace StringUtil
}; // end namespace FbTk

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//$Id: StringUtil.hh,v 1.6 2003/09/29 14:01:48 fluxgen Exp $
//$Id: StringUtil.hh,v 1.7 2003/10/25 22:06:53 fluxgen Exp $
#ifndef FBTK_STRINGUTIL_HH
#define FBTK_STRINGUTIL_HH
@ -57,6 +57,7 @@ std::string basename(const std::string &basename);
/// removes the first whitespace characters of the string
std::string::size_type removeFirstWhitespace(std::string &str);
std::string::size_type removeTrailingWhitespace(std::string &str);
/// Breaks a string into tokens
template <typename Container>