mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #1692 from def-/pr-news
Render news without STL functions
This commit is contained in:
commit
5e356b5327
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue