summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanne Kangas <janne.kangas@qt.io>2019-10-31 14:17:47 +0200
committerJanne Kangas <janne.kangas@qt.io>2019-11-06 10:57:57 +0200
commit488189a2cc418991ad3da9b64ba665d4e0696a6d (patch)
tree7c978a8a80768fa6b0c7536aa0bbe9aef269ab9c
parent82a6d571a7b4b23eeaa2d7ff610d917b10ae0294 (diff)
Store line feeds as substitute characters in UIP
To avoid using real line breaks in UIP file for string-typed values, replace \n sequence with a non-printable unicode char at file save. Revert this at file load. Change-Id: I736003d85c74a560fe9adc68957a8988ad70d2e9 Task-id: QT3DS-3993 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp
index 3953f20d..1fca9152 100644
--- a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp
+++ b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp
@@ -976,9 +976,15 @@ struct SComposerSerializerImpl : public IComposerSerializer
} else {
m_TempBuffer.clear();
WCharTWriter theWriter(m_TempBuffer);
- WStrOps<SValue>().ToBuf(theValue, theWriter);
-
- if (GetValueType(theValue) == DataModelDataType::String || m_TempBuffer.size()) {
+ if (theValueType == DataModelDataType::String || !theValue.empty()) {
+ // QT3DS-3993: store line feeds as replacement chars in UIP
+ if (theValueType == DataModelDataType::String) {
+ TDataStrPtr strPtr = get<TDataStrPtr>(theValue);
+ auto strValue = QString::fromWCharArray(strPtr->GetData());
+ strValue.replace("\n", LINE_BREAK_SUBSTITUTE);
+ theValue = std::make_shared<CDataStr>(CString::fromQString(strValue));
+ }
+ WStrOps<SValue>().ToBuf(theValue, theWriter);
char buffer[] = { 0, 0, 0, 0 };
m_TempBuffer.write(buffer, 4);
theValueStr.assign((const wchar_t *)m_TempBuffer.begin());
@@ -1007,8 +1013,13 @@ struct SComposerSerializerImpl : public IComposerSerializer
return SStringOrInt(std::make_shared<CDataStr>(inValue));
}
- if (inType == DataModelDataType::String)
- return std::make_shared<CDataStr>(inValue);
+ if (inType == DataModelDataType::String) {
+ // QT3DS-3993: store line feeds as replacement chars in UIP
+ auto valueStr = std::make_shared<CDataStr>(inValue);
+ auto val = QString::fromStdWString(valueStr->GetData());
+ val.replace(LINE_BREAK_SUBSTITUTE, "\n");
+ return std::make_shared<CDataStr>(CString::fromQString(val));
+ }
qt3ds::foundation::ConvertUTF(
reinterpret_cast<const qt3ds::foundation::TWCharEASTLConverter::TCharType *>(inValue), 0,