mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Revert & use "str_utf8_truncate" instead
This commit is contained in:
parent
44c699b812
commit
b045a3d6ee
|
@ -3182,51 +3182,6 @@ int str_utf8_check(const char *str)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void str_utf8_copy(char *dst, const char *src, int dst_size)
|
||||
{
|
||||
char *end = dst + (dst_size-2);
|
||||
char *ptr = end;
|
||||
|
||||
strncpy(dst, src, dst_size);
|
||||
dst[dst_size-1] = 0;
|
||||
|
||||
// check whether we need to remove a broken utf8 character
|
||||
while(ptr > dst)
|
||||
{
|
||||
if((*ptr&0xC0) == 0x80)
|
||||
{
|
||||
ptr--;
|
||||
}
|
||||
else if((*ptr&0x80) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if((*ptr&0xE0) == 0xC0)
|
||||
{
|
||||
if(end-ptr != 1)
|
||||
*ptr = 0;
|
||||
return;
|
||||
}
|
||||
else if((*ptr&0xF0) == 0xE0)
|
||||
{
|
||||
if(end-ptr != 2)
|
||||
*ptr = 0;
|
||||
return;
|
||||
}
|
||||
else if((*ptr&0xF8) == 0xF0)
|
||||
{
|
||||
if(end-ptr != 3)
|
||||
*ptr = 0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
*ptr = 0;
|
||||
}
|
||||
|
||||
unsigned str_quickhash(const char *str)
|
||||
{
|
||||
|
|
|
@ -1918,23 +1918,6 @@ int str_utf16le_encode(char *ptr, int chr);
|
|||
*/
|
||||
int str_utf8_check(const char *str);
|
||||
|
||||
/*
|
||||
Function: str_utf8_copy
|
||||
Copies a utf8 string to a buffer.
|
||||
|
||||
Parameters:
|
||||
dst - Pointer to a buffer that shall receive the string.
|
||||
src - utf8 string to be copied.
|
||||
dst_size - Size of the buffer dst.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-terminated strings.
|
||||
- Guarantees that dst string will contain zero-termination.
|
||||
- Guarantees that dst always ends with a valid utf8 sequence.
|
||||
- Does not guarantee the entire string is a valid utf8 string.
|
||||
*/
|
||||
void str_utf8_copy(char *dst, const char *src, int dst_size);
|
||||
|
||||
/*
|
||||
Function: str_next_token
|
||||
Writes the next token after str into buf, returns the rest of the string.
|
||||
|
|
|
@ -24,9 +24,14 @@ void CInput::AddEvent(char *pText, int Key, int Flags)
|
|||
m_aInputEvents[m_NumEvents].m_Key = Key;
|
||||
m_aInputEvents[m_NumEvents].m_Flags = Flags;
|
||||
if(!pText)
|
||||
{
|
||||
m_aInputEvents[m_NumEvents].m_aText[0] = 0;
|
||||
}
|
||||
else
|
||||
str_utf8_copy(m_aInputEvents[m_NumEvents].m_aText, pText, sizeof(m_aInputEvents[m_NumEvents].m_aText));
|
||||
{
|
||||
int TextSize = sizeof(m_aInputEvents[m_NumEvents].m_aText);
|
||||
str_utf8_truncate(m_aInputEvents[m_NumEvents].m_aText, TextSize, pText, TextSize);
|
||||
}
|
||||
m_aInputEvents[m_NumEvents].m_InputCount = m_InputCounter;
|
||||
m_NumEvents++;
|
||||
}
|
||||
|
|
|
@ -168,14 +168,14 @@ bool CChat::OnInput(IInput::CEvent Event)
|
|||
if(Text[i] == '\n')
|
||||
{
|
||||
int max = minimum(i - Begin + 1, (int)sizeof(Line));
|
||||
str_utf8_copy(Line, Text + Begin, max);
|
||||
str_utf8_truncate(Line, max, Text + Begin, max);
|
||||
Begin = i+1;
|
||||
SayChat(Line);
|
||||
while(Text[i] == '\n') i++;
|
||||
}
|
||||
}
|
||||
int max = minimum(i - Begin + 1, (int)sizeof(Line));
|
||||
str_utf8_copy(Line, Text + Begin, max);
|
||||
str_utf8_truncate(Line, max, Text + Begin, max);
|
||||
Begin = i+1;
|
||||
m_Input.Add(Line);
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
|
|||
int Offset = str_length(pStr);
|
||||
int CharsLeft = StrSize - Offset - 1;
|
||||
char *pCur = pStr + Offset;
|
||||
str_utf8_copy(pCur, Text, CharsLeft);
|
||||
str_utf8_truncate(pCur, CharsLeft, Text, CharsLeft);
|
||||
for(int i = 0; i < CharsLeft; i++)
|
||||
{
|
||||
if(pCur[i] == 0)
|
||||
|
|
Loading…
Reference in a new issue