changeset 2261:236d8d7c7295

Fixing a bug in tokenization
author Grumpy7
date Sat, 08 Mar 2014 16:04:44 +0100
parents eab43c3d7767
children 037ad3678c0f f38f53397bc0
files Items.cpp texts.cpp
diffstat 2 files changed, 6 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Items.cpp	Thu Mar 06 00:41:04 2014 +0100
+++ b/Items.cpp	Sat Mar 08 16:04:44 2014 +0100
@@ -452,7 +452,7 @@
 	{
     test_string = strtok(NULL, "\r") + 1;
     auto tokens = Tokenize(test_string, '\t');
-    Assert(tokens.size() == 17, "Invalid number of tokens");
+    Assert(tokens.size() >= 17, "Invalid number of tokens");
     pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(tokens[0]);
     pSpecialEnchantments[i].pNameAdd= RemoveQuotes(tokens[1]);
     for (int i = 0; i < 12; i++)
@@ -507,9 +507,9 @@
       pItems[item_counter].uDamageDice=atoi(tokens2[0]);
       pItems[item_counter].uDamageRoll=atoi(tokens2[1]);
     }
-    else if (tolower(test_string[0]) != 's')
+    else if (tolower(tokens2[0][0]) != 's')
     {
-      pItems[item_counter].uDamageDice=atoi(test_string);
+      pItems[item_counter].uDamageDice=atoi(tokens2[0]);
       pItems[item_counter].uDamageRoll=1;
     }
     else
@@ -564,7 +564,6 @@
     item_counter++;
 	}
 
-
 	pRndItemsTXT_Raw = NULL;
 	uAllItemsCount = item_counter;
 	pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0);
@@ -646,7 +645,7 @@
 		{
 		test_string = strtok(NULL, "\r") + 1;
     auto tokens = Tokenize(test_string, '\t');
-    Assert(tokens.size() == 6, "Invalid number of tokens");
+    Assert(tokens.size() >= 6, "Invalid number of tokens");
     pSkillDesc[i] = RemoveQuotes(tokens[1]);
     pNormalSkillDesc[i] = RemoveQuotes(tokens[2]);
     pExpertSkillDesc[i] = RemoveQuotes(tokens[3]);
--- a/texts.cpp	Thu Mar 06 00:41:04 2014 +0100
+++ b/texts.cpp	Sat Mar 08 16:04:44 2014 +0100
@@ -9,31 +9,16 @@
 std::vector<char*> Tokenize( char* input, const char separator )
 {
   std::vector<char*> retVect;
-  char* lastInput = input;
+  retVect.push_back(input);
   while (*input)
   {
     if (*input == separator)
     {
-      if (lastInput != nullptr)
-      {
         *input = '\0';
-        retVect.push_back(lastInput);
-        lastInput = nullptr;
-      }
-    }
-    else
-    {
-      if (lastInput == nullptr)
-      {
-        lastInput = input;
-      }
+        retVect.push_back(input + 1);
     }
     ++input;
   }
-  if (lastInput != nullptr)
-  {
-    retVect.push_back(lastInput);
-  }
   return retVect;
 }