Exemplo n.º 1
0
InputEventManager::VirtualMapData* InputEventManager::findVirtualMap(const char* description)
{
   char desc[256];
   desc[0] = 0;
   dStrncpy(desc, description, 255);
   dStrlwr(desc);

   return mVirtualMap.retreive(desc);
}
Exemplo n.º 2
0
const char *stristr(const char *szStringToBeSearched, const char *szSubstringToSearchFor)
{
   const char *pPos = NULL;
   char *szCopy1 = NULL;
   char *szCopy2 = NULL;

   // verify parameters
   if ( szStringToBeSearched == NULL ||
        szSubstringToSearchFor == NULL )
   {
      return szStringToBeSearched;
   }

   // empty substring - return input (consistent with strstr)
   if (strlen(szSubstringToSearchFor) == 0 ) {
      return szStringToBeSearched;
   }

   szCopy1 = dStrlwr(strdup(szStringToBeSearched));
   szCopy2 = dStrlwr(strdup(szSubstringToSearchFor));

   if ( szCopy1 == NULL || szCopy2 == NULL  ) {
      // another option is to raise an exception here
      free((void*)szCopy1);
      free((void*)szCopy2);
      return NULL;
   }

   pPos = strstr((const char*)szCopy1, (const char*)szCopy2);

   if ( pPos != NULL ) {
      // map to the original string
      pPos = szStringToBeSearched + (pPos - szCopy1);
   }

   free((void*)szCopy1);
   free((void*)szCopy2);

   return pPos;
} // stristr(...)
Exemplo n.º 3
0
      U32 getOrCreateHashNoCase() const
      {
         if( mHashNoCase == U32_MAX)
         {
            PROFILE_SCOPE(StringData_getOrCreateHashNoCase);
            UTF8 *lower = new UTF8[ mLength + 1 ];
            dStrncpy( lower, utf8(), mLength );
            lower[ mLength ] = 0;
            dStrlwr( lower );
            mHashNoCase = Torque::hash( (const U8*)lower, mLength, 0 );
            delete [] lower;
         }

         return mHashNoCase;
      }
Exemplo n.º 4
0
void InputEventManager::addVirtualMap(const char* description, InputEventType type, InputObjectInstances code)
{
   // Make sure the description is lower case
   char desc[256];
   desc[0] = 0;
   dStrncpy(desc, description, 255);
   dStrlwr(desc);

   VirtualMapData* data = new VirtualMapData();
   data->type = type;
   data->code = code;
   data->desc = StringTable->insert(desc);

   mVirtualMap.insert(data, desc);
   mActionCodeMap.insertUnique(data->code, *data);
}
Exemplo n.º 5
0
void InputEventManager::buildVirtualMap()
{
   char desc[256];
   VirtualMapData* data;

   for (U32 j = 0; gVirtualMap[j].code != 0xFFFFFFFF; j++)
   {
      // Make sure the description is lower case
      desc[0] = 0;
      dStrncpy(desc, gVirtualMap[j].pDescription, 255);
      dStrlwr(desc);

      data = new VirtualMapData();
      data->type = gVirtualMap[j].type;
      data->code = gVirtualMap[j].code;
      data->desc = StringTable->insert(desc);

      mVirtualMap.insert(data, desc);
      mActionCodeMap.insertUnique(data->code, *data);
   }
}
Exemplo n.º 6
0
/// Search for a StringData.
/// Search for the position of the needle in the haystack.
/// Default mode is StrCase | StrLeft, mode also accepts StrNoCase and StrRight.
/// If pos is non-zero, then in mode StrLeft the search starts at (hay + pos) and
/// in mode StrRight the search starts at (hay + pos - 1)
/// @return Returns a pointer to the StringData in the haystack or 0
static const char* StrFind(const char* hay, const char* needle, S32 pos, U32 mode)
{
   if (mode & String::Right)
   {
      const char  *he = hay;

      if (pos)
      {
         he += pos - 1;
      }
      else
      {
         while (*he)
            he++;
      }

      if (mode & String::NoCase)
      {
         AutoPtr<char,DeleteString> ln(dStrlwr(dStrdup(needle)));
         for (; he >= hay; he--)
         {
            if (dTolower(*he) == *ln)
            {
               U32 i = 0;
               while (ln[i] && ln[i] == dTolower(he[i]))
                  i++;
               if (!ln[i])
                  return he;
               if (!hay[i])
                  return 0;
            }
         }
      }
      else
      {
         for (; he >= hay; he--)
         {
            if (*he == *needle)
            {
               U32 i = 0;
               while (needle[i] && needle[i] == he[i])
                  i++;
               if (!needle[i])
                  return he;
               if (!hay[i])
                  return 0;
            }
         }
      }
      return 0;
   }
   else
   {
      if (mode & String::NoCase)
      {
         AutoPtr<char,DeleteString> ln(dStrlwr(dStrdup(needle)));
         for (hay += pos; *hay; hay++)
         {
            if (dTolower(*hay) == *ln)
            {
               U32 i = 0;
               while (ln[i] && ln[i] == dTolower(hay[i]))
                  i++;
               if (!ln[i])
                  return hay;
               if (!hay[i])
                  return 0;
            }
         }
      }
      else
      {
         for (hay += pos; *hay; hay++)
         {
            if (*hay == *needle)
            {
               U32 i = 0;
               while (needle[i] && needle[i] == hay[i])
                  i++;
               if (!needle[i])
                  return hay;
               if (!hay[i])
                  return 0;
            }
         }
      }
   }

   return 0;
}