diff options
author | HaoTNN <haotnn@gmail.com> | 2015-06-03 01:08:57 +0200 |
---|---|---|
committer | HaoTNN <haotnn@gmail.com> | 2015-06-03 01:08:57 +0200 |
commit | 3142598dee31acc23c738a1a728638665c8940b8 (patch) | |
tree | 2eb837ed785678d536d677ff5020fabca089f2e5 /src/BlockID.cpp | |
parent | Merge remote-tracking branch 'upstream/master' (diff) | |
parent | Merge pull request #2182 from birkett/master (diff) | |
download | cuberite-3142598dee31acc23c738a1a728638665c8940b8.tar cuberite-3142598dee31acc23c738a1a728638665c8940b8.tar.gz cuberite-3142598dee31acc23c738a1a728638665c8940b8.tar.bz2 cuberite-3142598dee31acc23c738a1a728638665c8940b8.tar.lz cuberite-3142598dee31acc23c738a1a728638665c8940b8.tar.xz cuberite-3142598dee31acc23c738a1a728638665c8940b8.tar.zst cuberite-3142598dee31acc23c738a1a728638665c8940b8.zip |
Diffstat (limited to 'src/BlockID.cpp')
-rw-r--r-- | src/BlockID.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 7f0db3cfc..c598df0aa 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -96,8 +96,7 @@ public: else { // Not a resolvable string, try pure numbers: "45:6", "45^6" etc. - a_Item.m_ItemType = (short)atoi(Split[0].c_str()); - if ((a_Item.m_ItemType == 0) && (Split[0] != "0")) + if (!StringToInteger(Split[0], a_Item.m_ItemType)) { // Parsing the number failed return false; @@ -111,9 +110,8 @@ public: a_Item.m_ItemCount = 1; return true; } - - a_Item.m_ItemDamage = (short)atoi(Split[1].c_str()); - if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0")) + + if (!StringToInteger(Split[1], a_Item.m_ItemDamage)) { // Parsing the number failed return false; @@ -175,8 +173,16 @@ protected: { return; } - short ItemType = (short)atoi(Split[0].c_str()); - short ItemDamage = (Split.size() > 1) ? (short)atoi(Split[1].c_str()) : -1; + short ItemType; + if (!StringToInteger(Split[0], ItemType)) + { + ASSERT(!"Invalid item type"); + } + short ItemDamage = -1; + if (Split.size() > 1 && !StringToInteger(Split[1], ItemDamage)) + { + ASSERT(!"Invalid item damage"); + } m_Map[a_Name] = std::make_pair(ItemType, ItemDamage); } } ; @@ -288,11 +294,11 @@ AString ItemToFullString(const cItem & a_Item) eDimension StringToDimension(const AString & a_DimensionString) { // First try decoding as a number - int res = atoi(a_DimensionString.c_str()); - if ((res != 0) || (a_DimensionString == "0")) + int res; + if (StringToInteger(a_DimensionString, res)) { // It was a valid number - return (eDimension)res; + return static_cast<eDimension>(res); } // Decode using a built-in map: @@ -350,7 +356,7 @@ AString DimensionToString(eDimension a_Dimension) } // for i - DimensionMap[] // Not found - LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", (int)a_Dimension); + LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", static_cast<int>(a_Dimension)); return "Overworld"; } @@ -386,7 +392,7 @@ AString DamageTypeToString(eDamageType a_DamageType) // Unknown damage type: ASSERT(!"Unknown DamageType"); - return Printf("dtUnknown_%d", (int)a_DamageType); + return Printf("dtUnknown_%d", static_cast<int>(a_DamageType)); } @@ -397,11 +403,11 @@ AString DamageTypeToString(eDamageType a_DamageType) eDamageType StringToDamageType(const AString & a_DamageTypeString) { // First try decoding as a number: - int res = atoi(a_DamageTypeString.c_str()); - if ((res != 0) || (a_DamageTypeString == "0")) + int res; + if (!StringToInteger(a_DamageTypeString, res)) { // It was a valid number - return (eDamageType)res; + return static_cast<eDamageType>(res); } // Decode using a built-in map: @@ -462,7 +468,7 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString) } // for i - DamageTypeMap[] // Not found: - return (eDamageType)-1; + return static_cast<eDamageType>(-1); } |