diff options
| author | oy <Tom_Adams@web.de> | 2010-10-01 00:55:16 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-10-01 00:55:16 +0200 |
| commit | 67e9f03f23a454f273aeb6f83e338c057c3efb93 (patch) | |
| tree | f6ec82e186ea23861b2eb2c3576e7b38c19dec52 /src/engine | |
| parent | 2f388139c1e46d8cde32bd446b880e4225b06b35 (diff) | |
| download | zcatch-67e9f03f23a454f273aeb6f83e338c057c3efb93.tar.gz zcatch-67e9f03f23a454f273aeb6f83e338c057c3efb93.zip | |
when setting a config string variable check if it's a utf8 string and encode it if the check fails. Closes #10
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/shared/console.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index dc2e1a25..808b64ed 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -383,7 +383,28 @@ static void StrVariableCommand(IConsole::IResult *pResult, void *pUserData) 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]; |