1: #include <iostream> 
   2: #include <string> 
   3: 
   4: #if defined ( DEBUG ) 
   5: #define DEBUG_CODE( code_to_put_into_source ) { code_to_put_into_source } 
   6: #else 
   7: #define DEBUG_CODE( code_to_put_into_source ) 
   8: #endif 
   9: 
  10: #include <libintl.h> 
  11: #define _(String) gettext (String) 
  12: #include <locale.h> // for setlocale --> see > man 3 setlocale 
  13: 
  14: using namespace std;
  15: 
  16: 
  17: //-----------------------------------------------------------
  18: // Trims white spaces on end and on beginning of string
  19: //-----------------------------------------------------------
  20: inline void
  21: Trim_White_Spaces( std::string & string_to_trim )
  22: {
  23: //DEBUG_CODE( cerr << "Trim_White_Spaces: string = \"" << string_to_trim << "\" 1" << endl; )
  24:     // Trim leading white spaces    
  25:     string::size_type nowhite = string_to_trim.find_first_not_of( " \t\n\r\b\f\v" );
  26:     string_to_trim.erase( 0, nowhite );
  27: //DEBUG_CODE( cerr << "Trim_White_Spaces: string = \"" << string_to_trim << "\" 2" << endl; )
  28:     // Trim trailing white spaces
  29:     nowhite = string_to_trim.find_last_not_of( " \t\n\r\b\f\v" );
  30:     string_to_trim.erase( nowhite + 1 );
  31: //DEBUG_CODE( cerr << "Trim_White_Spaces: string = \"" << string_to_trim << "\" 3" << endl; )
  32: }
  33: 
  34: 
  35: // -----------------------------------------------------------
  36: // 
  37: // -----------------------------------------------------------
  38: int main( void )
  39: {
  40:     // Important settings for translation BEGIN
  41:     char * lang = setlocale ( LC_MESSAGES, "" );
  42:     cerr << "Lang = " << lang << endl;
  43:     bindtextdomain ( "trimString", "/usr/share/locale" );
  44:     textdomain ( "trimString" );
  45:     // Important settings for translation END
  46: 
  47:     std::string string2trim = _("  \r \n \tToday was my birthday.    I am 16 years old.\t ");
  48:     cout << endl;
  49:     cout << "Before trim: \n" << string2trim << endl;
  50:     cout << endl;
  51:     Trim_White_Spaces( string2trim );
  52:     cout << "After trim: \n" << string2trim << endl;
  53:     cout << endl;
  54:     
  55: return 0;   
  56: }
  57: 
  58: