diff --git a/Source/Engine/Platform/Base/StringUtilsBase.cpp b/Source/Engine/Platform/Base/StringUtilsBase.cpp index 96f0fd2dc..750758b33 100644 --- a/Source/Engine/Platform/Base/StringUtilsBase.cpp +++ b/Source/Engine/Platform/Base/StringUtilsBase.cpp @@ -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); diff --git a/Source/Engine/Platform/StringUtils.h b/Source/Engine/Platform/StringUtils.h index faa8127f8..dad84bd64 100644 --- a/Source/Engine/Platform/StringUtils.h +++ b/Source/Engine/Platform/StringUtils.h @@ -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); diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp index 73e4ee31a..481cf2df7 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Material.cpp @@ -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 diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp index 707c24416..685aa1040 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.cpp @@ -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(); } } }