This commit is contained in:
Branimir Karadžić
2017-12-09 17:54:52 -08:00
parent d2bcdc5c0d
commit e3993fd7e9
3 changed files with 20 additions and 4 deletions

View File

@@ -215,8 +215,11 @@ namespace bx
/// Skip non-whitespace.
const char* strnws(const char* _str);
/// Skip word.
const char* strword(const char* _str);
/// Returns pointer to first character after word.
const char* strSkipWord(const char* _str, int32_t _max = INT32_MAX);
/// Returns StringView of word or empty.
StringView strWord(const StringView& _str);
/// Find matching block.
const char* strmb(const char* _str, char _open, char _close);

View File

@@ -531,12 +531,19 @@ namespace bx
return _str;
}
const char* strword(const char* _str)
const char* strSkipWord(const char* _str, int32_t _max)
{
for (char ch = *_str++; isAlphaNum(ch) || '_' == ch; ch = *_str++) {};
for (char ch = *_str++; 0 < _max && (isAlphaNum(ch) || '_' == ch); ch = *_str++, --_max) {};
return _str-1;
}
StringView strWord(const StringView& _str)
{
const char* ptr = _str.getPtr();
const char* term = strSkipWord(ptr, _str.getLength() );
return StringView(ptr, term);
}
const char* strmb(const char* _str, char _open, char _close)
{
int count = 0;

View File

@@ -389,3 +389,9 @@ TEST_CASE("Trim", "")
bx::FilePath uri("/555333/podmac/");
REQUIRE(0 == bx::strCmp(bx::strTrim(uri.getPath(), "/"), "555333/podmac") );
}
TEST_CASE("strWord", "")
{
REQUIRE(bx::strWord(" abvgd-1389.0").isEmpty() );
REQUIRE(0 == bx::strCmp(bx::strWord("abvgd-1389.0"), "abvgd") );
}