Renaming string functions.

This commit is contained in:
Branimir Karadžić
2017-04-22 14:34:01 -07:00
parent aa1888a979
commit 47f14e7655
10 changed files with 86 additions and 84 deletions

View File

@@ -127,10 +127,10 @@ namespace bx
bool toBool(const char* _str);
/// String compare.
int32_t strncmp(const char* _lhs, const char* _rhs, int32_t _max = INT32_MAX);
int32_t strCmp(const char* _lhs, const char* _rhs, int32_t _max = INT32_MAX);
/// Case insensitive string compare.
int32_t strincmp(const char* _lhs, const char* _rhs, int32_t _max = INT32_MAX);
int32_t strCmpI(const char* _lhs, const char* _rhs, int32_t _max = INT32_MAX);
///
int32_t strLen(const char* _str, int32_t _max = INT32_MAX);
@@ -143,16 +143,16 @@ namespace bx
int32_t strCat(char* _dst, int32_t _dstSize, const char* _src, int32_t _num = INT32_MAX);
///
const char* strnchr(const char* _str, char _ch, int32_t _max = INT32_MAX);
const char* strFind(const char* _str, char _ch, int32_t _max = INT32_MAX);
///
const char* strnrchr(const char* _str, char _ch, int32_t _max = INT32_MAX);
const char* strRFind(const char* _str, char _ch, int32_t _max = INT32_MAX);
/// Find substring in string. Limit search to _size.
const char* strnstr(const char* _str, const char* _find, int32_t _max = INT32_MAX);
const char* strFind(const char* _str, const char* _find, int32_t _max = INT32_MAX);
/// Find substring in string. Case insensitive. Limit search to _max.
const char* stristr(const char* _str, const char* _find, int32_t _max = INT32_MAX);
const char* strFindI(const char* _str, const char* _find, int32_t _max = INT32_MAX);
/// Find new line. Returns pointer after new line terminator.
const char* strnl(const char* _str);

View File

@@ -245,11 +245,11 @@ namespace bx
const char* arg = findOption(_short, _long, 1);
if (NULL != arg)
{
if ('0' == *arg || (0 == strincmp(arg, "false") ) )
if ('0' == *arg || (0 == strCmpI(arg, "false") ) )
{
_value = false;
}
else if ('0' != *arg || (0 == strincmp(arg, "true") ) )
else if ('0' != *arg || (0 == strCmpI(arg, "true") ) )
{
_value = true;
}
@@ -293,7 +293,7 @@ namespace bx
}
else if (NULL != _long
&& '-' == *arg
&& 0 == strincmp(arg+1, _long) )
&& 0 == strCmpI(arg+1, _long) )
{
if (0 == _skip)
{

View File

@@ -67,22 +67,22 @@ extern "C" char* strcat(char* _dst, const char* _src)
extern "C" const char* strchr(const char* _str, int _ch)
{
return bx::strnchr(_str, _ch);
return bx::strFind(_str, _ch);
}
extern "C" int32_t strcmp(const char* _lhs, const char* _rhs)
{
return bx::strncmp(_lhs, _rhs);
return bx::strCmp(_lhs, _rhs);
}
extern "C" int32_t strncmp(const char* _lhs, const char* _rhs, size_t _max)
{
return bx::strncmp(_lhs, _rhs, _max);
return bx::strCmp(_lhs, _rhs, _max);
}
extern "C" const char* strstr(const char* _str, const char* _find)
{
return bx::strnstr(_str, _find);
return bx::strFind(_str, _find);
}
extern "C" void qsort(void* _base, size_t _num, size_t _size, bx::ComparisonFn _fn)

View File

@@ -124,12 +124,12 @@ namespace bx
return 0 == _max ? 0 : fn(*_lhs) - fn(*_rhs);
}
int32_t strncmp(const char* _lhs, const char* _rhs, int32_t _max)
int32_t strCmp(const char* _lhs, const char* _rhs, int32_t _max)
{
return strCmp<toNoop>(_lhs, _rhs, _max);
}
int32_t strincmp(const char* _lhs, const char* _rhs, int32_t _max)
int32_t strCmpI(const char* _lhs, const char* _rhs, int32_t _max)
{
return strCmp<toLower>(_lhs, _rhs, _max);
}
@@ -172,7 +172,7 @@ namespace bx
return strCopy(&_dst[len], max-len, _src, _num);
}
const char* strnchr(const char* _str, char _ch, int32_t _max)
const char* strFind(const char* _str, char _ch, int32_t _max)
{
for (int32_t ii = 0, len = strLen(_str, _max); ii < len; ++ii)
{
@@ -185,7 +185,7 @@ namespace bx
return NULL;
}
const char* strnrchr(const char* _str, char _ch, int32_t _max)
const char* strRFind(const char* _str, char _ch, int32_t _max)
{
for (int32_t ii = strLen(_str, _max); 0 < ii; --ii)
{
@@ -239,12 +239,12 @@ namespace bx
return NULL;
}
const char* strnstr(const char* _str, const char* _find, int32_t _max)
const char* strFind(const char* _str, const char* _find, int32_t _max)
{
return strStr<toNoop>(_str, _max, _find, INT32_MAX);
}
const char* stristr(const char* _str, const char* _find, int32_t _max)
const char* strFindI(const char* _str, const char* _find, int32_t _max)
{
return strStr<toLower>(_str, _max, _find, INT32_MAX);
}
@@ -253,13 +253,13 @@ namespace bx
{
for (; '\0' != *_str; _str += strLen(_str, 1024) )
{
const char* eol = strnstr(_str, "\r\n", 1024);
const char* eol = strFind(_str, "\r\n", 1024);
if (NULL != eol)
{
return eol + 2;
}
eol = strnstr(_str, "\n", 1024);
eol = strFind(_str, "\n", 1024);
if (NULL != eol)
{
return eol + 1;
@@ -273,13 +273,13 @@ namespace bx
{
for (; '\0' != *_str; _str += strLen(_str, 1024) )
{
const char* eol = strnstr(_str, "\r\n", 1024);
const char* eol = strFind(_str, "\r\n", 1024);
if (NULL != eol)
{
return eol;
}
eol = strnstr(_str, "\n", 1024);
eol = strFind(_str, "\n", 1024);
if (NULL != eol)
{
return eol;
@@ -349,8 +349,8 @@ namespace bx
const char* findIdentifierMatch(const char* _str, const char* _word)
{
int32_t len = strLen(_word);
const char* ptr = strnstr(_str, _word);
for (; NULL != ptr; ptr = strnstr(ptr + len, _word) )
const char* ptr = strFind(_str, _word);
for (; NULL != ptr; ptr = strFind(ptr + len, _word) )
{
if (ptr != _str)
{
@@ -534,7 +534,7 @@ namespace bx
toUpperUnsafe(str, len);
}
const char* dot = strnchr(str, '.');
const char* dot = strFind(str, '.');
if (NULL != dot)
{
const int32_t precLen = int32_t(
@@ -888,10 +888,10 @@ namespace bx
const char* baseName(const char* _filePath)
{
const char* bs = strnrchr(_filePath, '\\');
const char* fs = strnrchr(_filePath, '/');
const char* bs = strRFind(_filePath, '\\');
const char* fs = strRFind(_filePath, '/');
const char* slash = (bs > fs ? bs : fs);
const char* colon = strnrchr(_filePath, ':');
const char* colon = strRFind(_filePath, ':');
const char* basename = slash > colon ? slash : colon;
if (NULL != basename)
{

View File

@@ -61,5 +61,5 @@ TEST(macros)
CHECK_EQUAL(5, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
CHECK_EQUAL(6, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
CHECK_EQUAL(0, bx::strncmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
CHECK_EQUAL(0, bx::strCmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
}

View File

@@ -206,7 +206,7 @@ void simd_check_string(const char* _str, bx::simd128_t _a)
SIMD_DBG("%s %s", _str, test);
CHECK(0 == bx::strncmp(_str, test) );
CHECK(0 == bx::strCmp(_str, test) );
}
TEST_CASE("simd_swizzle", "")

View File

@@ -23,13 +23,13 @@ TEST_CASE("quickSort", "")
{
const char* lhs = *(const char**)_lhs;
const char* rhs = *(const char**)_rhs;
return bx::strncmp(lhs, rhs);
return bx::strCmp(lhs, rhs);
});
REQUIRE(0 == bx::strncmp(str[0], "jabuka") );
REQUIRE(0 == bx::strncmp(str[1], "jagoda") );
REQUIRE(0 == bx::strncmp(str[2], "kruska") );
REQUIRE(0 == bx::strncmp(str[3], "malina") );
REQUIRE(0 == bx::strCmp(str[0], "jabuka") );
REQUIRE(0 == bx::strCmp(str[1], "jagoda") );
REQUIRE(0 == bx::strCmp(str[2], "kruska") );
REQUIRE(0 == bx::strCmp(str[3], "malina") );
int8_t byte[128];
bx::RngMwc rng;

View File

@@ -41,15 +41,15 @@ TEST_CASE("strCopy", "")
REQUIRE(num == 0);
num = bx::strCopy(dst, 3, "blah", 3);
REQUIRE(0 == bx::strncmp(dst, "bl") );
REQUIRE(0 == bx::strCmp(dst, "bl") );
REQUIRE(num == 2);
num = bx::strCopy(dst, sizeof(dst), "blah", 3);
REQUIRE(0 == bx::strncmp(dst, "bla") );
REQUIRE(0 == bx::strCmp(dst, "bla") );
REQUIRE(num == 3);
num = bx::strCopy(dst, sizeof(dst), "blah");
REQUIRE(0 == bx::strncmp(dst, "blah") );
REQUIRE(0 == bx::strCmp(dst, "blah") );
REQUIRE(num == 4);
}
@@ -61,72 +61,74 @@ TEST_CASE("strCat", "")
REQUIRE(4 == bx::strCopy(dst, 5, "copy") );
REQUIRE(3 == bx::strCat(dst, 8, "cat") );
REQUIRE(0 == bx::strncmp(dst, "copycat") );
REQUIRE(0 == bx::strCmp(dst, "copycat") );
REQUIRE(1 == bx::strCat(dst, BX_COUNTOF(dst), "------", 1) );
REQUIRE(3 == bx::strCat(dst, BX_COUNTOF(dst), "cat") );
REQUIRE(0 == bx::strncmp(dst, "copycat-cat") );
REQUIRE(0 == bx::strCmp(dst, "copycat-cat") );
}
TEST_CASE("strincmp", "")
TEST_CASE("strCmpI", "")
{
REQUIRE(0 == bx::strincmp("test", "test") );
REQUIRE(0 == bx::strincmp("test", "testestes", 4) );
REQUIRE(0 == bx::strincmp("testestes", "test", 4) );
REQUIRE(0 != bx::strincmp("preprocess", "platform") );
REQUIRE(0 == bx::strCmpI("test", "test") );
REQUIRE(0 == bx::strCmpI("test", "testestes", 4) );
REQUIRE(0 == bx::strCmpI("testestes", "test", 4) );
REQUIRE(0 != bx::strCmpI("preprocess", "platform") );
const char* abvgd = "abvgd";
const char* abvgx = "abvgx";
const char* empty = "";
REQUIRE(0 == bx::strincmp(abvgd, abvgd) );
REQUIRE(0 == bx::strincmp(abvgd, abvgx, 4) );
REQUIRE(0 == bx::strCmpI(abvgd, abvgd) );
REQUIRE(0 == bx::strCmpI(abvgd, abvgx, 4) );
REQUIRE(0 > bx::strincmp(abvgd, abvgx) );
REQUIRE(0 > bx::strincmp(empty, abvgd) );
REQUIRE(0 > bx::strCmpI(abvgd, abvgx) );
REQUIRE(0 > bx::strCmpI(empty, abvgd) );
REQUIRE(0 < bx::strincmp(abvgx, abvgd) );
REQUIRE(0 < bx::strincmp(abvgd, empty) );
REQUIRE(0 < bx::strCmpI(abvgx, abvgd) );
REQUIRE(0 < bx::strCmpI(abvgd, empty) );
}
TEST_CASE("strnchr", "")
TEST_CASE("strRFind", "")
{
const char* test = "test";
REQUIRE(NULL == bx::strnchr(test, 's', 0) );
REQUIRE(NULL == bx::strnchr(test, 's', 2) );
REQUIRE(&test[2] == bx::strnchr(test, 's') );
REQUIRE(NULL == bx::strRFind(test, 's', 0) );
REQUIRE(NULL == bx::strRFind(test, 's', 1) );
REQUIRE(&test[2] == bx::strRFind(test, 's') );
}
TEST_CASE("strnrchr", "")
{
const char* test = "test";
REQUIRE(NULL == bx::strnrchr(test, 's', 0) );
REQUIRE(NULL == bx::strnrchr(test, 's', 1) );
REQUIRE(&test[2] == bx::strnrchr(test, 's') );
}
TEST_CASE("stristr", "")
TEST_CASE("strFindI", "")
{
const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
REQUIRE(NULL == bx::stristr(test, "quick", 8) );
REQUIRE(NULL == bx::stristr(test, "quick1") );
REQUIRE(&test[4] == bx::stristr(test, "quick", 9) );
REQUIRE(&test[4] == bx::stristr(test, "quick") );
REQUIRE(NULL == bx::strFindI(test, "quick", 8) );
REQUIRE(NULL == bx::strFindI(test, "quick1") );
REQUIRE(&test[4] == bx::strFindI(test, "quick", 9) );
REQUIRE(&test[4] == bx::strFindI(test, "quick") );
}
TEST_CASE("strnstr", "")
TEST_CASE("strFind", "")
{
const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
{
const char* test = "test";
REQUIRE(NULL == bx::strnstr(test, "quick", 8) );
REQUIRE(NULL == bx::strnstr(test, "quick1") );
REQUIRE(NULL == bx::strnstr(test, "quick", 9) );
REQUIRE(NULL == bx::strnstr(test, "quick") );
REQUIRE(NULL == bx::strFind(test, 's', 0) );
REQUIRE(NULL == bx::strFind(test, 's', 2) );
REQUIRE(&test[2] == bx::strFind(test, 's') );
}
REQUIRE(NULL == bx::strnstr(test, "Quick", 8) );
REQUIRE(NULL == bx::strnstr(test, "Quick1") );
REQUIRE(&test[4] == bx::strnstr(test, "Quick", 9) );
REQUIRE(&test[4] == bx::strnstr(test, "Quick") );
{
const char* test = "The Quick Brown Fox Jumps Over The Lazy Dog.";
REQUIRE(NULL == bx::strFind(test, "quick", 8) );
REQUIRE(NULL == bx::strFind(test, "quick1") );
REQUIRE(NULL == bx::strFind(test, "quick", 9) );
REQUIRE(NULL == bx::strFind(test, "quick") );
REQUIRE(NULL == bx::strFind(test, "Quick", 8) );
REQUIRE(NULL == bx::strFind(test, "Quick1") );
REQUIRE(&test[4] == bx::strFind(test, "Quick", 9) );
REQUIRE(&test[4] == bx::strFind(test, "Quick") );
}
}
template<typename Ty>
@@ -135,7 +137,7 @@ static bool testToString(Ty _value, const char* _expected)
char tmp[1024];
int32_t num = bx::toString(tmp, BX_COUNTOF(tmp), _value);
int32_t len = (int32_t)bx::strLen(_expected);
if (0 == bx::strncmp(tmp, _expected)
if (0 == bx::strCmp(tmp, _expected)
&& num == len)
{
return true;
@@ -199,7 +201,7 @@ TEST_CASE("StringView", "")
st.append("test", 2);
REQUIRE(10 == st.getLength() );
REQUIRE(0 == bx::strncmp(st.getPtr(), "testtestte") );
REQUIRE(0 == bx::strCmp(st.getPtr(), "testtestte") );
st.clear();
REQUIRE(0 == st.getLength() );

View File

@@ -46,7 +46,7 @@ static bool test(const char* _input, int32_t _argc, ...)
for (int32_t ii = 0; ii < _argc; ++ii)
{
const char* arg = va_arg(argList, const char*);
if (0 != bx::strncmp(argv[ii], arg) )
if (0 != bx::strCmp(argv[ii], arg) )
{
return false;
}

View File

@@ -20,7 +20,7 @@ TEST_CASE("vsnprintf truncated", "Truncated output buffer.")
char buffer[7];
REQUIRE(10 == bx::snprintf(buffer, BX_COUNTOF(buffer), "Ten chars!") );
REQUIRE(0 == bx::strncmp(buffer, "Ten ch") );
REQUIRE(0 == bx::strCmp(buffer, "Ten ch") );
}
static bool test(const char* _expected, const char* _format, ...)
@@ -35,7 +35,7 @@ static bool test(const char* _expected, const char* _format, ...)
bool result = true
&& len == max-1
&& 0 == bx::strncmp(_expected, temp)
&& 0 == bx::strCmp(_expected, temp)
;
if (!result)