Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. std::string stripnonalp(std::string input_string)
  2. {
  3.     std::string output_string = "";
  4.     bool lastwasspace = 0;
  5.  
  6.     for (char current_letter : input_string)
  7.     {
  8.         current_letter = tolower(current_letter);
  9.  
  10.         if (lastwasspace == false)
  11.         {
  12.             if((current_letter == ' ') || (current_letter == '\n') || (current_letter == '\r'))
  13.             {
  14.                 lastwasspace = true;
  15.                 output_string += " ";
  16.             }
  17.  
  18.             if(current_letter == '\'')
  19.                 output_string += "'";
  20.  
  21.             if((current_letter >= 'a') && (current_letter <= 'z'))
  22.                 output_string += current_letter;
  23.         }
  24.  
  25.  
  26.         if (lastwasspace == true)
  27.         {
  28.             if(current_letter == '\'')
  29.             {
  30.                 output_string += "'";
  31.                 lastwasspace = false;
  32.             }
  33.  
  34.             if((current_letter >= 'a') && (current_letter <= 'z'))
  35.             {
  36.                 output_string += current_letter;
  37.                 lastwasspace = false;
  38.             }
  39.         }
  40.     }
  41.     return output_string;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement