00001
00002
00003 #ifndef TRIM_SPACES_H
00004 #define TRIM_SPACES_H
00005
00006 #include <locale>
00007 #include <string>
00008 #include <string.h>
00009
00013 std::string trim_spaces(const char* psz, std::locale loc=std::locale::classic())
00014 {
00015 std::string out;
00016 size_t l = strlen(psz);
00017 if (l)
00018 {
00019 const char* start = psz;
00020 while(*start && std::isspace(*start, loc))
00021 ++start;
00022 const char* end = psz + l-1;
00023 while(end >= start && std::isspace(*end, loc))
00024 --end;
00025
00026 if (start <= end)
00027 out.append(start, end - start +1);
00028 }
00029 return out;
00030 }
00031
00032 #endif TRIM_SPACES_H