Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7371 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Apr 26, 2006, 2:12:45 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: better completion-algos

Location:
trunk/src/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_completion.cc

    r7344 r7371  
    6363
    6464  PRINTF(5)("AutoComplete on input\n");
    65   this->emptyCompletionList();
     65  this->clearCompletionList();
    6666
    6767  // Check if we are in a input. eg. the supplied string "class " and now we complete either function or object
     
    135135  if (clList != NULL)
    136136  {
    137     if (!this->addToCompleteList(clList, classBegin, SHELLC_CLASS))
     137    if (!this->addToCompleteList(*clList, classBegin, SHELLC_CLASS))
    138138      return false;
    139139  }
     
    157157    if (classID == CL_SHELL_COMMAND_CLASS)
    158158      type = SHELLC_CLASS;
    159     if (!this->addToCompleteList(boList, objectBegin, type))
     159    if (!this->addToCompleteList(*boList, objectBegin, type))
    160160      return false;
    161161  }
     
    175175  ShellCommandClass::getCommandListOfClass(className, &fktList);
    176176  //printf("%s\n", boList->firstElement()->getName());
    177   if (!this->addToCompleteList(&fktList, functionBegin, SHELLC_FUNCTION))
     177  if (!this->addToCompleteList(fktList, functionBegin, SHELLC_FUNCTION))
    178178    return false;
    179179  return true;
     
    190190  ShellCommandClass::getCommandListOfAlias(&aliasList);
    191191  //printf("%s\n", boList->firstElement()->getName());
    192   if (!this->addToCompleteList(&aliasList, aliasBegin, SHELLC_ALIAS))
     192  if (!this->addToCompleteList(aliasList, aliasBegin, SHELLC_ALIAS))
    193193    return false;
    194194  return true;
     
    265265 * !! The strings MUST NOT be deleted !!
    266266 */
    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;
     267bool ShellCompletion::addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, SHELLC_TYPE type)
     268{
    271269  unsigned int searchLength = completionBegin.size();
    272270
    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++)
    275273  {
    276274    if ((*string).size() >= searchLength &&
    277           !strncasecmp((*string).c_str(), completionBegin.c_str(), searchLength))
     275          !nocaseCmp(*string, completionBegin, searchLength))
    278276    {
     277      printf ("%s\n", (*string).c_str());
    279278      ShellC_Element newElem;
    280       newElem.name = (*string).c_str();
     279      newElem.name = (*string);
    281280      newElem.type = type;
    282281      this->completionList.push_back(newElem);
     
    292291 * !! The strings MUST NOT be deleted !!
    293292 */
    294 bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>* inputList, const std::string& completionBegin, SHELLC_TYPE type)
    295 {
    296   if (inputList == NULL)
    297     return false;
     293bool ShellCompletion::addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, SHELLC_TYPE type)
     294{
    298295  unsigned int searchLength = completionBegin.size();
    299296
    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++)
    302299  {
    303300    if ((*bo)->getName() != NULL &&
    304301        strlen((*bo)->getName()) >= searchLength &&
    305           !strncasecmp((*bo)->getName(), completionBegin.c_str(), searchLength))
     302          !nocaseCmp((*bo)->getName(), completionBegin, searchLength))
    306303    {
    307304      ShellC_Element newElem;
     
    320317 * This is done at the beginning of each completion-run
    321318 */
    322 void ShellCompletion::emptyCompletionList()
     319void ShellCompletion::clearCompletionList()
    323320{
    324321  this->completionList.clear();
  • trunk/src/lib/shell/shell_completion.h

    r7343 r7371  
    2020#endif
    2121
    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 Element
    35 };
    3622
    3723//! A class for ...
    3824class 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  };
    3940
    4041 public:
     
    5556                       const std::string& addBack = "", const std::string& addFront = "");
    5657
    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();
    6062
    6163  static const char* ShellCompletion::typeToString(SHELLC_TYPE type);
  • trunk/src/lib/util/helper_functions.cc

    r7221 r7371  
    115115 * @param s2 second string
    116116 */
    117 int nocase_cmp(const std::string& s1, const std::string& s2)
     117int nocaseCmp(const std::string& s1, const std::string& s2)
    118118{
    119119  std::string::const_iterator it1=s1.begin();
     
    137137}
    138138
     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 */
     146int 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  
    2121
    2222
    23 int           nocase_cmp(const std::string& s1, const std::string& s2);
     23int           nocaseCmp(const std::string& s1, const std::string& s2);
     24int           nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len);
    2425
    2526
Note: See TracChangeset for help on using the changeset viewer.