Fix shader error when using non-ASCII characters in material
This commit is contained in:
@@ -88,6 +88,20 @@ const char* StringUtils::FindIgnoreCase(const char* str, const char* toFind)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void StringUtils::ConvertUTF162ASCII(const Char* from, char* to, int32 len)
|
||||
{
|
||||
if (!from || !to)
|
||||
return;
|
||||
for (int32 i = 0; i < len; i++)
|
||||
{
|
||||
Char c = from[i];
|
||||
if ((c == 0x09 || c == 0x0A || c == 0x0D || (0x20 <= c && c <= 0x7F)))
|
||||
to[i] = (char)c;
|
||||
else
|
||||
to[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void PrintUTF8Error(const char* from, uint32 fromLength)
|
||||
{
|
||||
LOG(Error, "Not a UTF-8 string. Length: {0}", fromLength);
|
||||
|
||||
@@ -150,6 +150,9 @@ public:
|
||||
// Converts characters from UTF-16 to ANSI
|
||||
static void ConvertUTF162ANSI(const Char* from, char* to, int32 len);
|
||||
|
||||
// Converts characters from UTF-16 to ASCII
|
||||
static void ConvertUTF162ASCII(const Char* from, char* to, int32 len);
|
||||
|
||||
// Convert characters from UTF-8 to UTF-16
|
||||
static void ConvertUTF82UTF16(const char* from, Char* to, int32 fromLength, int32& toLength);
|
||||
|
||||
|
||||
@@ -140,7 +140,9 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
|
||||
|
||||
// Write code
|
||||
_writer.Write(TEXT("{\n"));
|
||||
_writer.Write(*code);
|
||||
_writer.Write(code);
|
||||
if (!code.EndsWith(TEXT("\n")) && !code.EndsWith(TEXT(" ")))
|
||||
_writer.Write(TEXT("\n"));
|
||||
_writer.Write(TEXT("}\n"));
|
||||
|
||||
// Link output values to boxes
|
||||
|
||||
@@ -627,8 +627,9 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
if (in.Length() > 0)
|
||||
{
|
||||
tmp.EnsureCapacity(in.Length() + 1, false);
|
||||
StringUtils::ConvertUTF162ANSI(*in, tmp.Get(), in.Length());
|
||||
StringUtils::ConvertUTF162ASCII(*in, tmp.Get(), in.Length());
|
||||
source.WriteBytes(tmp.Get(), in.Length());
|
||||
tmp.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user