about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2010-10-01 00:55:16 +0200
committeroy <Tom_Adams@web.de>2010-10-01 00:55:16 +0200
commit67e9f03f23a454f273aeb6f83e338c057c3efb93 (patch)
treef6ec82e186ea23861b2eb2c3576e7b38c19dec52 /src/engine
parent2f388139c1e46d8cde32bd446b880e4225b06b35 (diff)
downloadzcatch-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.cpp23
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];