Add native StringToI64 (#2449)

* Add native StringToInt64Ex

* Delete useless test code

* Rename native StringToInt64Ex to StringToI64

* Add documentation for out-of-bounds situations.
This commit is contained in:
F1F88
2026-09-03 21:42:52 -07:00
committed by GitHub
parent e078b2b542
commit bea10f0fb1
4 changed files with 196 additions and 0 deletions
+18
View File
@@ -211,6 +211,10 @@ native int StringToIntEx(const char[] str, int &result, int nBase=10);
/**
* Converts a string to a 64-bit integer.
*
* @note If the value is outside the range of representable values,
* If the value is positive, this function will return INT64_MAX.
* If the value is negative, this function will return INT64_MIN.
*
* @param str String to convert.
* @param result Array to store the upper and lower
* 32-bits of the 64-bit integer.
@@ -219,6 +223,20 @@ native int StringToIntEx(const char[] str, int &result, int nBase=10);
*/
native int StringToInt64(const char[] str, int result[2], int nBase=10);
/**
* Converts a string to an int64 type value.
*
* @note If the value is outside the range of representable values,
* If the value is positive, this function will return INT64_MAX.
* If the value is negative, this function will return INT64_MIN.
*
* @param str String to convert.
* @param nBase Numerical base to use. 10 is default.
* @param nConsumed Number of characters consumed.
* @return int64 conversion of string, or 0 on failure.
*/
native int64 StringToI64(const char[] str, int nBase=10, int &nConsumed=0);
/**
* Converts an integer to a string.
*
+14
View File
@@ -141,3 +141,17 @@ stock void AssertStrArrayEq(const char[] text, const char[][] value, const char[
}
PrintToServer("[%d] %s: '%s' arrays are equal OK", TestNumber, TestContext, text);
}
stock void AssertInt64Eq(const char[] text, int64 value, int64 expected)
{
TestNumber++;
if (value == expected)
{
PrintToServer("[%d] %s: %s == %ld OK", TestNumber, TestContext, text, expected);
}
else
{
PrintToServer("[%d] %s FAIL: %s should be %ld, got %ld", TestNumber, TestContext, text, expected, value);
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
}
}