- Timestamp:
- 04/10/11 10:15:14 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Readline.cc
r10331 r10343 155 155 // -------------------------------------------------------------------------- 156 156 // 157 //! This is a static helper to remove leading and trailing whitespaces.158 //!159 //! @param buf160 //! a pointer to the char array from which the whitespaces should be161 //! removed162 //!163 //! @returns164 //! a std::string with the whitespaces removed from buf165 //166 string Readline::TrimSpaces(const char *buf)167 {168 const string str(buf);169 170 // Trim Both leading and trailing spaces171 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 af173 174 // if all spaces or empty return an empty string175 if (string::npos==start || string::npos==end)176 return string();177 178 return str.substr(start, end-start+1);179 }180 181 // --------------------------------------------------------------------------182 //183 157 //! This wraps the given readline function such that the output can be 184 158 //! redirected from thr rl_outstream to the given C++ ostream. 185 159 //! 186 //! @param o stream160 //! @param out 187 161 //! The stream to which the output should be redirected. 188 162 //! … … 537 511 return; 538 512 513 int p = -1; 539 514 while (skip==2) 540 515 { 541 int p = history_search_pos(str.c_str(), 0, 0);516 p = history_search_pos(str.c_str(), 0, p+1); 542 517 if (p<0) 543 518 break; 544 519 545 delete remove_history(p); 520 // It seems like history_search_pos works more like 521 // history_search_prefix, therefore the identity is checked again 522 const HIST_ENTRY *e = history_get(p+1); 523 if (e && str==e->line) 524 delete remove_history(p); 546 525 } 547 526 … … 943 922 fprintf(rl_outstream, " Ctrl-left One word backward\n"); 944 923 fprintf(rl_outstream, " Ctrl-right One word forward\n"); 924 fprintf(rl_outstream, " Ctrl-d Quit\n"); 945 925 fprintf(rl_outstream, " Ctrl-y Delete line\n"); 946 926 fprintf(rl_outstream, " Alt-end/Ctrl-k Delete until the end of the line\n"); … … 1016 996 return false; 1017 997 1018 str = Trim Spaces(buf);998 str = Trim(buf); 1019 999 1020 1000 free(buf); … … 1044 1024 Shutdown(buf ? buf : ""); 1045 1025 1046 const string str = !buf || (rl_done && rl_pending_input ) ? ".q" : TrimSpaces(buf);1026 const string str = !buf || (rl_done && rl_pending_input==4) ? ".q" : Trim(buf); 1047 1027 1048 1028 free(buf); … … 1100 1080 { 1101 1081 rl_done = 1; 1102 rl_pending_input = 1;1103 } 1082 rl_pending_input = 4; // EOT (end of transmission, ctrl-d) 1083 } -
trunk/FACT++/src/Readline.h
r10331 r10343 8 8 { 9 9 public: 10 static std::string TrimSpaces(const char *buf);11 10 static bool RedirectionWrapper(std::ostream &out, bool (*function)()); 12 11
Note:
See TracChangeset
for help on using the changeset viewer.