00001 #include "utils.h"
00002
00003 void chomp(std::string &str)
00004 {
00005 size_t nSpacesBegin = 0, nSpacesEnd = 0;
00006 for (size_t i = 0;
00007 i < str.length() &&
00008 ((str[i] == '\t') || (str[i] == ' ') || (str[i] == '\n') || (str[i] == '\r'));
00009 ++i) {
00010 ++nSpacesBegin;
00011 }
00012 for (size_t i = str.size() - 1;
00013 i >= nSpacesBegin &&
00014 ((str[i] == '\t') || (str[i] == ' ') || (str[i] == '\n') || (str[i] == '\r'));
00015 --i) {
00016 ++nSpacesEnd;
00017 }
00018 if (nSpacesBegin != 0) {
00019 str = str.substr(nSpacesBegin);
00020 }
00021 if (nSpacesEnd != 0) {
00022 str = str.substr(0, str.length() - nSpacesEnd);
00023 }
00024 }