//: C03:Trim.h // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // General tool to strip spaces from both ends. #ifndef TRIM_H #define TRIM_H #include #include inline std::string trim(const std::string& s) { if(s.length() == 0) return s; std::size_t beg = s.find_first_not_of(" \a\b\f\n\r\t\v"); std::size_t end = s.find_last_not_of(" \a\b\f\n\r\t\v"); if(beg == std::string::npos) // No non-spaces return ""; return std::string(s, beg, end - beg + 1); } #endif // TRIM_H ///:~