Changeset 10308
- Timestamp:
- 04/07/11 15:45:13 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Readline.cc
r10275 r10308 169 169 170 170 // Trim Both leading and trailing spaces 171 const size_t start = str.find_first_not_of( " "); // Find the first character position after excluding leading blank spaces172 const size_t end = str.find_last_not_of( " "); // Find the first character position from reverse af171 const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces 172 const size_t end = str.find_last_not_of(' '); // Find the first character position from reverse af 173 173 174 174 // if all spaces or empty return an empty string 175 175 if (string::npos==start || string::npos==end) 176 return "";176 return string(); 177 177 178 178 return str.substr(start, end-start+1); 179 } 180 181 // -------------------------------------------------------------------------- 182 // 183 //! This wraps the given readline function such that the output can be 184 //! redirected from thr rl_outstream to the given C++ ostream. 185 //! 186 //! @param ostream 187 //! The stream to which the output should be redirected. 188 //! 189 //! @param function 190 //! Takes a function of type bool(*)() as argument 191 //! 192 //! @returns 193 //! The return value of the function 194 // 195 bool Readline::RedirectionWrapper(ostream &out, bool (*function)()) 196 { 197 FILE *save = SetStreamOut(tmpfile()); 198 const bool rc = function(); 199 FILE *file = SetStreamOut(save); 200 201 const bool empty = ftell(file)==0; 202 203 rewind(file); 204 205 if (empty) 206 { 207 out << " <empty>" << endl; 208 fclose(file); 209 return rc; 210 } 211 212 while (1) 213 { 214 const int c = getc(file); 215 if (feof(file)) 216 break; 217 out << (char)c; 218 } 219 out << endl; 220 221 fclose(file); 222 223 return rc; 179 224 } 180 225 … … 333 378 char *Readline::Compare(const string &str, const string &txt) 334 379 { 335 return str.substr(0, txt.length())==txt ? strndup(str.c_str(), str.length()) : 0; 380 /*return strncmp(str.c_str(), txt.c_str(), txt.length())==0 ? */ 381 return strncasecmp(str.c_str(), txt.c_str(), txt.length())==0 ? 382 strndup(str.c_str(), str.length()) : 0; 336 383 } 337 384 … … 814 861 { 815 862 HIST_ENTRY **next = history_list(); 863 864 if (!next) 865 return true; 816 866 817 867 for (; *next; next++) -
trunk/FACT++/src/Readline.h
r10275 r10308 9 9 public: 10 10 static std::string TrimSpaces(const char *buf); 11 static bool RedirectionWrapper(std::ostream &out, bool (*function)()); 11 12 12 13 protected:
Note:
See TracChangeset
for help on using the changeset viewer.