00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "whitespacescrub.h"
00012
00013 using namespace deml;
00014
00018 string WhitespaceScrub::leading(string str){
00019 for(short i = 0; i < (short)str.size(); i++)
00020 {
00021 if(!isspace(str[i]))
00022 return str.substr(i);
00023 }
00024 }
00025
00029 string WhitespaceScrub::trailing(string str){
00030 for(short i = (str.size() - 1); i > 0; i--)
00031 {
00032 if(!isspace(str[i]))
00033 {
00034 str.resize(i + 1);
00035 return str;
00036 }
00037 }
00038 }
00039
00045 string WhitespaceScrub::all(string str)
00046 {
00047 string chopped = leading(trailing(str));
00048 string scrubbed = "";
00049
00050 for(short i = 0; i < (short)chopped.size(); i++)
00051 {
00052 char c = chopped[i];
00053 if(!isspace(c))
00054 scrubbed.push_back(c);
00055 else
00056 {
00057 scrubbed.push_back(' ');
00058 for(; i < (short)chopped.size(); i++)
00059 {
00060 c = chopped[i];
00061 if(!isspace(c))
00062 {
00063 scrubbed.push_back(c);
00064 break;
00065 }
00066 }
00067 }
00068 }
00069
00070 return scrubbed;
00071 }
00072
00076 string WhitespaceScrub::zealous(string str){
00077 string scrubbed = "";
00078
00079 for(short i=0; i < (short)str.size(); i++)
00080 {
00081 char c = str[i];
00082 if(!isspace(c))
00083 {
00084 scrubbed.push_back(c);
00085 }
00086 }
00087
00088 return scrubbed;
00089 }
00090
00094 vector<string> WhitespaceScrub::tokens(string str)
00095 {
00096 vector<string> tokenList;
00097 string token = "";
00098 bool inWord = false;
00099
00100 str.push_back(' ');
00101
00102 for(short i=0; i < (short)str.size(); i++)
00103 {
00104 char c = str[i];
00105 if(!isspace(c))
00106 {
00107 token.push_back(c);
00108 inWord = true;
00109 }
00110 else if(inWord)
00111 {
00112 inWord = false;
00113 tokenList.push_back(token);
00114 token = "";
00115 }
00116 }
00117
00118 return tokenList;
00119 }
00120