Commit 1b3c96b9 authored by Jan Möbius's avatar Jan Möbius
Browse files

Added trim functions and use it in ply reader

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@466 fdac6126-5c0c-442c-9429-916003d36597
parent ee710c80
...@@ -132,6 +132,43 @@ protected: ...@@ -132,6 +132,43 @@ protected:
}; };
/** \brief Trim left whitespace
*
* Removes whitespace at the beginning of the string
*
* @param _string input string
* @return trimmed string
*/
static inline std::string &left_trim(std::string &_string) {
_string.erase(_string.begin(), std::find_if(_string.begin(), _string.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return _string;
}
/** \brief Trim right whitespace
*
* Removes whitespace at the end of the string
*
* @param _string input string
* @return trimmed string
*/
static inline std::string &right_trim(std::string &_string) {
_string.erase(std::find_if(_string.rbegin(), _string.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _string.end());
return _string;
}
/** \brief Trim whitespace
*
* Removes whitespace at the beginning and end of the string
*
* @param _string input string
* @return trimmed string
*/
static inline std::string &trim(std::string &_string) {
return left_trim(right_trim(_string));
}
//============================================================================= //=============================================================================
} // namespace IO } // namespace IO
} // namespace OpenMesh } // namespace OpenMesh
......
...@@ -107,8 +107,7 @@ _PLYReader_::_PLYReader_() { ...@@ -107,8 +107,7 @@ _PLYReader_::_PLYReader_() {
bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) { bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) {
std::fstream in(_filename.c_str(), (options_.is_binary() ? std::ios_base::binary | std::ios_base::in std::fstream in(_filename.c_str(), (std::ios_base::binary | std::ios_base::in) );
: std::ios_base::in));
if (!in.is_open() || !in.good()) { if (!in.is_open() || !in.good()) {
omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl; omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
...@@ -833,7 +832,6 @@ _PLYReader_::ValueType get_property_type(std::string _string1, std::string _stri ...@@ -833,7 +832,6 @@ _PLYReader_::ValueType get_property_type(std::string _string1, std::string _stri
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool _PLYReader_::can_u_read(std::istream& _is) const { bool _PLYReader_::can_u_read(std::istream& _is) const {
// Clear per file options // Clear per file options
...@@ -846,6 +844,7 @@ bool _PLYReader_::can_u_read(std::istream& _is) const { ...@@ -846,6 +844,7 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
// read 1st line // read 1st line
std::string line; std::string line;
std::getline(_is, line); std::getline(_is, line);
trim(line);
//Check if this file is really a ply format //Check if this file is really a ply format
if (line != "PLY" && line != "ply") if (line != "PLY" && line != "ply")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment