Render news without STL functions (fixes #1693)

This commit is contained in:
def 2019-04-29 22:55:12 +02:00
parent 0fffd7705f
commit e1c9033300
3 changed files with 15 additions and 9 deletions

View file

@ -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;

View file

@ -2,8 +2,6 @@
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/array.h>
#include <sstream>
#include <string>
#include <math.h>
@ -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);
}
}
}

View file

@ -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)