Main Page | Class List | File List | Class Members | File Members

trim_spaces.h

Go to the documentation of this file.
00001 // trim_spaces.h
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

Generated on Sun Jun 26 13:43:46 2005 for pingem by  doxygen 1.4.3