summaryrefslogtreecommitdiffstats
path: root/src/BlockID.cpp
diff options
context:
space:
mode:
authortycho <work.tycho@gmail.com>2015-05-24 13:56:56 +0200
committertycho <work.tycho@gmail.com>2015-05-24 13:56:56 +0200
commitdae9e5792a4f030ae9e748548a16a89790fbd311 (patch)
tree2142b8c4deb9f2c7ad096b8b0ec93fefccd8d8f1 /src/BlockID.cpp
parentMerge branch 'master' into PreventNewWarnings (diff)
downloadcuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.tar
cuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.tar.gz
cuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.tar.bz2
cuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.tar.lz
cuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.tar.xz
cuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.tar.zst
cuberite-dae9e5792a4f030ae9e748548a16a89790fbd311.zip
Diffstat (limited to 'src/BlockID.cpp')
-rw-r--r--src/BlockID.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/BlockID.cpp b/src/BlockID.cpp
index 7f0db3cfc..775d60a68 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);
}