Changeset 7371 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Apr 26, 2006, 2:12:45 AM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_completion.cc
r7344 r7371 63 63 64 64 PRINTF(5)("AutoComplete on input\n"); 65 this-> emptyCompletionList();65 this->clearCompletionList(); 66 66 67 67 // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object … … 135 135 if (clList != NULL) 136 136 { 137 if (!this->addToCompleteList( clList, classBegin, SHELLC_CLASS))137 if (!this->addToCompleteList(*clList, classBegin, SHELLC_CLASS)) 138 138 return false; 139 139 } … … 157 157 if (classID == CL_SHELL_COMMAND_CLASS) 158 158 type = SHELLC_CLASS; 159 if (!this->addToCompleteList( boList, objectBegin, type))159 if (!this->addToCompleteList(*boList, objectBegin, type)) 160 160 return false; 161 161 } … … 175 175 ShellCommandClass::getCommandListOfClass(className, &fktList); 176 176 //printf("%s\n", boList->firstElement()->getName()); 177 if (!this->addToCompleteList( &fktList, functionBegin, SHELLC_FUNCTION))177 if (!this->addToCompleteList(fktList, functionBegin, SHELLC_FUNCTION)) 178 178 return false; 179 179 return true; … … 190 190 ShellCommandClass::getCommandListOfAlias(&aliasList); 191 191 //printf("%s\n", boList->firstElement()->getName()); 192 if (!this->addToCompleteList( &aliasList, aliasBegin, SHELLC_ALIAS))192 if (!this->addToCompleteList(aliasList, aliasBegin, SHELLC_ALIAS)) 193 193 return false; 194 194 return true; … … 265 265 * !! The strings MUST NOT be deleted !! 266 266 */ 267 bool ShellCompletion::addToCompleteList(const std::list<std::string>* inputList, const std::string& completionBegin, SHELLC_TYPE type) 268 { 269 if (inputList == NULL) 270 return false; 267 bool ShellCompletion::addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, SHELLC_TYPE type) 268 { 271 269 unsigned int searchLength = completionBegin.size(); 272 270 273 list<std::string>::const_iterator string;274 for (string = inputList ->begin(); string != inputList->end(); string++)271 std::list<std::string>::const_iterator string; 272 for (string = inputList.begin(); string != inputList.end(); string++) 275 273 { 276 274 if ((*string).size() >= searchLength && 277 ! strncasecmp((*string).c_str(), completionBegin.c_str(), searchLength))275 !nocaseCmp(*string, completionBegin, searchLength)) 278 276 { 277 printf ("%s\n", (*string).c_str()); 279 278 ShellC_Element newElem; 280 newElem.name = (*string) .c_str();279 newElem.name = (*string); 281 280 newElem.type = type; 282 281 this->completionList.push_back(newElem); … … 292 291 * !! The strings MUST NOT be deleted !! 293 292 */ 294 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>* inputList, const std::string& completionBegin, SHELLC_TYPE type) 295 { 296 if (inputList == NULL) 297 return false; 293 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, SHELLC_TYPE type) 294 { 298 295 unsigned int searchLength = completionBegin.size(); 299 296 300 list<BaseObject*>::const_iterator bo;301 for(bo = inputList ->begin(); bo != inputList->end(); bo++)297 std::list<BaseObject*>::const_iterator bo; 298 for(bo = inputList.begin(); bo != inputList.end(); bo++) 302 299 { 303 300 if ((*bo)->getName() != NULL && 304 301 strlen((*bo)->getName()) >= searchLength && 305 ! strncasecmp((*bo)->getName(), completionBegin.c_str(), searchLength))302 !nocaseCmp((*bo)->getName(), completionBegin, searchLength)) 306 303 { 307 304 ShellC_Element newElem; … … 320 317 * This is done at the beginning of each completion-run 321 318 */ 322 void ShellCompletion:: emptyCompletionList()319 void ShellCompletion::clearCompletionList() 323 320 { 324 321 this->completionList.clear(); -
trunk/src/lib/shell/shell_completion.h
r7343 r7371 20 20 #endif 21 21 22 //! an enumerator for different types the Shell can complete.23 typedef enum {24 SHELLC_NONE = 0,25 SHELLC_CLASS = 1,26 SHELLC_OBJECT = 2,27 SHELLC_FUNCTION = 4,28 SHELLC_ALIAS = 8,29 } SHELLC_TYPE;30 31 //! A struct for ShellElements (these are used as containers to identify an Input for what it is)32 struct ShellC_Element{33 std::string name; //!< the Name of the Element to be completed.34 SHELLC_TYPE type; //!< the type of the Element35 };36 22 37 23 //! A class for ... 38 24 class ShellCompletion { 25 26 //! an enumerator for different types the Shell can complete. 27 typedef enum { 28 SHELLC_NONE = 0, 29 SHELLC_CLASS = 1, 30 SHELLC_OBJECT = 2, 31 SHELLC_FUNCTION = 4, 32 SHELLC_ALIAS = 8, 33 } SHELLC_TYPE; 34 35 //! A struct for ShellElements (these are used as containers to identify an Input for what it is) 36 struct ShellC_Element{ 37 std::string name; //!< the Name of the Element to be completed. 38 SHELLC_TYPE type; //!< the type of the Element 39 }; 39 40 40 41 public: … … 55 56 const std::string& addBack = "", const std::string& addFront = ""); 56 57 57 bool addToCompleteList(const std::list<std::string>* inputList, const std::string& completionBegin, SHELLC_TYPE type); 58 bool addToCompleteList(const std::list<BaseObject*>* inputList, const std::string& completionBegin, SHELLC_TYPE type); 59 void emptyCompletionList(); 58 59 bool addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, SHELLC_TYPE type); 60 bool addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, SHELLC_TYPE type); 61 void clearCompletionList(); 60 62 61 63 static const char* ShellCompletion::typeToString(SHELLC_TYPE type); -
trunk/src/lib/util/helper_functions.cc
r7221 r7371 115 115 * @param s2 second string 116 116 */ 117 int nocase _cmp(const std::string& s1, const std::string& s2)117 int nocaseCmp(const std::string& s1, const std::string& s2) 118 118 { 119 119 std::string::const_iterator it1=s1.begin(); … … 137 137 } 138 138 139 140 /** 141 * @brief compares two strings without ignoring the case 142 * @param s1 first string 143 * @param s2 second string 144 * @param len how far from the beginning to start. 145 */ 146 int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len) 147 { 148 std::string::const_iterator it1=s1.begin(); 149 std::string::const_iterator it2=s2.begin(); 150 151 //stop when either string's end has been reached 152 while ( (it1!=s1.end()) && (it2!=s2.end()) && len-- > 0) 153 { 154 if(::toupper(*it1) != ::toupper(*it2)) //letters differ? 155 // return -1 to indicate smaller than, 1 otherwise 156 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 157 //proceed to the next character in each string 158 ++it1; 159 ++it2; 160 } 161 return 0; 162 } 163 -
trunk/src/lib/util/helper_functions.h
r7221 r7371 21 21 22 22 23 int nocase_cmp(const std::string& s1, const std::string& s2); 23 int nocaseCmp(const std::string& s1, const std::string& s2); 24 int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len); 24 25 25 26
Note: See TracChangeset
for help on using the changeset viewer.