Fixed broken function Token::getCharAt() (#7073)
This commit is contained in:
parent
297f2c78bd
commit
0370c66e41
|
@ -703,23 +703,25 @@ std::string Token::getCharAt(const Token *tok, std::size_t index)
|
||||||
{
|
{
|
||||||
assert(tok != nullptr);
|
assert(tok != nullptr);
|
||||||
|
|
||||||
const std::string strValue(tok->strValue());
|
std::string::const_iterator it = tok->str().begin() + 1U;
|
||||||
const char *str = strValue.c_str();
|
const std::string::const_iterator end = tok->str().end() - 1U;
|
||||||
|
|
||||||
while (*str) {
|
while (it != end) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
std::string ret;
|
if (*it == '\0')
|
||||||
if (*str == '\\') {
|
return "\\0";
|
||||||
ret = *str;
|
|
||||||
++str;
|
std::string ret(1, *it);
|
||||||
|
if (*it == '\\') {
|
||||||
|
++it;
|
||||||
|
ret += *it;
|
||||||
}
|
}
|
||||||
ret += *str;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*str == '\\')
|
if (*it == '\\')
|
||||||
++str;
|
++it;
|
||||||
++str;
|
++it;
|
||||||
--index;
|
--index;
|
||||||
}
|
}
|
||||||
assert(index == 0);
|
assert(index == 0);
|
||||||
|
|
|
@ -4033,7 +4033,7 @@ private:
|
||||||
ASSERT_EQUALS("'\\0' ;", tok("\"hello\"[5] ;"));
|
ASSERT_EQUALS("'\\0' ;", tok("\"hello\"[5] ;"));
|
||||||
ASSERT_EQUALS("'\\0' ;", tok("\"\"[0] ;"));
|
ASSERT_EQUALS("'\\0' ;", tok("\"\"[0] ;"));
|
||||||
ASSERT_EQUALS("'\\0' ;", tok("\"\\0\"[0] ;"));
|
ASSERT_EQUALS("'\\0' ;", tok("\"\\0\"[0] ;"));
|
||||||
ASSERT_EQUALS("'\n' ;", tok("\"hello\\nworld\"[5] ;"));
|
ASSERT_EQUALS("'\\n' ;", tok("\"hello\\nworld\"[5] ;"));
|
||||||
ASSERT_EQUALS("'w' ;", tok("\"hello\nworld\"[6] ;"));
|
ASSERT_EQUALS("'w' ;", tok("\"hello\nworld\"[6] ;"));
|
||||||
ASSERT_EQUALS("\"hello\" [ 7 ] ;", tok("\"hello\"[7] ;"));
|
ASSERT_EQUALS("\"hello\" [ 7 ] ;", tok("\"hello\"[7] ;"));
|
||||||
ASSERT_EQUALS("\"hello\" [ -1 ] ;", tok("\"hello\"[-1] ;"));
|
ASSERT_EQUALS("\"hello\" [ -1 ] ;", tok("\"hello\"[-1] ;"));
|
||||||
|
|
Loading…
Reference in New Issue