diff --git a/src/base/system.c b/src/base/system.c index 20b36dcf8..547309b53 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -3135,7 +3135,11 @@ unsigned str_quickhash(const char *str) static const char *str_token_get(const char *str, const char *delim, int *length) { - str += strspn(str, delim); + size_t len = strspn(str, delim); + if(len > 1) + str++; + else + str += len; if(!*str) return NULL; diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index dbe250955..061fc0ba5 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -2,8 +2,6 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include -#include -#include #include @@ -901,19 +899,21 @@ void CMenus::RenderNews(CUIRect MainView) CUIRect Label; - std::istringstream f(Client()->m_aNews); - std::string line; - while(std::getline(f, line)) + const char *pStr = Client()->m_aNews; + char aLine[256]; + while((pStr = str_next_token(pStr, "\n", aLine, sizeof(aLine)))) { - if(line.size() > 0 && line.at(0) == '|' && line.at(line.size()-1) == '|') + const int Len = str_length(aLine); + if(Len > 0 && aLine[0] == '|' && aLine[Len-1] == '|') { MainView.HSplitTop(30.0f, &Label, &MainView); - UI()->DoLabelScaled(&Label, Localize(line.substr(1, line.size()-2).c_str()), 20.0f, -1); + aLine[Len-1] = '\0'; + UI()->DoLabelScaled(&Label, aLine + 1, 20.0f, -1); } else { MainView.HSplitTop(20.0f, &Label, &MainView); - UI()->DoLabelScaled(&Label, line.c_str(), 15.f, -1, MainView.w-30.0f); + UI()->DoLabelScaled(&Label, aLine, 15.f, -1, MainView.w-30.0f); } } } diff --git a/src/test/str.cpp b/src/test/str.cpp index fb64bf4d9..ed92c8da9 100644 --- a/src/test/str.cpp +++ b/src/test/str.cpp @@ -171,6 +171,8 @@ TEST(Str, InList) EXPECT_FALSE(str_in_list("abc,xyz", ",", "abcdef")); EXPECT_FALSE(str_in_list("", ",", "")); EXPECT_FALSE(str_in_list("", ",", "xyz")); + + EXPECT_TRUE(str_in_list("FOO,,BAR", ",", "")); } TEST(Str, StrFormat)