mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Merge branch 'master' of http://github.com/oy/teeworlds into Cleanup
This commit is contained in:
commit
e885fcb8a2
|
@ -1454,6 +1454,24 @@ int str_utf8_decode(const char **ptr)
|
|||
|
||||
}
|
||||
|
||||
int str_utf8_check(const char *str)
|
||||
{
|
||||
while(*str)
|
||||
{
|
||||
if((*str&0x80) == 0x0)
|
||||
str++;
|
||||
else if((*str&0xE0) == 0xC0 && (*(str+1)&0xC0) == 0x80)
|
||||
str += 2;
|
||||
else if((*str&0xF0) == 0xE0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80)
|
||||
str += 3;
|
||||
else if((*str&0xF8) == 0xF0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80 && (*(str+3)&0xC0) == 0x80)
|
||||
str += 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
unsigned str_quickhash(const char *str)
|
||||
{
|
||||
|
|
|
@ -1147,6 +1147,22 @@ int str_utf8_decode(const char **ptr);
|
|||
*/
|
||||
int str_utf8_encode(char *ptr, int chr);
|
||||
|
||||
/*
|
||||
Function: str_utf8_check
|
||||
Checks if a strings contains just valid utf8 characters.
|
||||
|
||||
Parameters:
|
||||
str - Pointer to a possible utf8 string.
|
||||
|
||||
Returns:
|
||||
0 - invalid characters found.
|
||||
1 - only valid characters found.
|
||||
|
||||
Remarks:
|
||||
- The string is treated as zero-terminated utf8 string.
|
||||
*/
|
||||
int str_utf8_check(const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -396,7 +396,28 @@ static void StrVariableCommand(IConsole::IResult *pResult, void *pUserData, int
|
|||
CStrVariableData *pData = (CStrVariableData *)pUserData;
|
||||
|
||||
if(pResult->NumArguments())
|
||||
str_copy(pData->m_pStr, pResult->GetString(0), pData->m_MaxSize);
|
||||
{
|
||||
const char *pString = pResult->GetString(0);
|
||||
if(!str_utf8_check(pString))
|
||||
{
|
||||
char Temp[4];
|
||||
int Length = 0;
|
||||
while(*pString)
|
||||
{
|
||||
int Size = str_utf8_encode(Temp, static_cast<const unsigned char>(*pString++));
|
||||
if(Length+Size < pData->m_MaxSize)
|
||||
{
|
||||
mem_copy(pData->m_pStr+Length, &Temp, Size);
|
||||
Length += Size;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
pData->m_pStr[Length] = 0;
|
||||
}
|
||||
else
|
||||
str_copy(pData->m_pStr, pString, pData->m_MaxSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
char aBuf[1024];
|
||||
|
|
|
@ -51,6 +51,8 @@ char *CLineReader::Get()
|
|||
if(m_aBuffer[m_BufferPos] == '\n' || m_aBuffer[m_BufferPos] == '\r')
|
||||
{
|
||||
// line found
|
||||
if(m_aBuffer[m_BufferPos] == '\r' && m_BufferPos+1 < m_BufferSize && m_aBuffer[m_BufferPos+1] == '\n')
|
||||
m_aBuffer[m_BufferPos++] = 0;
|
||||
m_aBuffer[m_BufferPos] = 0;
|
||||
m_BufferPos++;
|
||||
return &m_aBuffer[LineStart];
|
||||
|
|
Loading…
Reference in a new issue