diff --git uppsrc/Core/Util.cpp uppsrc/Core/Util.cpp --- uppsrc/Core/Util.cpp +++ uppsrc/Core/Util.cpp @@ -664,6 +664,22 @@ static VectorMap>& sGSerialize() return h; } +String GetLineEndings(const String& data, const String& default_eol) +{ + int q = data.ReverseFind("\n"); + if(q >= 0) { + if(data.Mid(q - 1, 1) == "\r") + return "\r\n"; + else + return "\n"; + } +#if 0 + else if(data.ReverseFind("\r") >= 0) + return "\r"; +#endif + return default_eol; +} + void RegisterGlobalConfig(const char *name) { Mutex::Lock __(sGCfgLock); diff --git uppsrc/Core/Util.h uppsrc/Core/Util.h --- uppsrc/Core/Util.h +++ uppsrc/Core/Util.h @@ -449,6 +449,8 @@ bool LoadFromString(T& x, const String& s) { return Load(x, ss); } +String GetLineEndings(const String& data, const String& default_eol = "\r\n"); + void RegisterGlobalConfig(const char *name); void RegisterGlobalSerialize(const char *name, Event WhenSerialize); void RegisterGlobalConfig(const char *name, Event<> WhenFlush); diff --git uppsrc/IconDes/ImlFile.cpp uppsrc/IconDes/ImlFile.cpp --- uppsrc/IconDes/ImlFile.cpp +++ uppsrc/IconDes/ImlFile.cpp @@ -185,8 +185,11 @@ void ScanIML(CParser& parser, Array& out_images, } } +String ImlEOL("\r\n"); + bool LoadIml(const String& data, Array& img, int& format) { + ImlEOL = GetLineEndings(data); CParser p(data); format = 0; try { @@ -277,7 +280,7 @@ static void PutOctalString(Stream& out, const char *b, const char *e, bool split int64 start = out.GetPos(); while(b < e) { if(split && out.GetPos() >= start + 200u) { - out.Put("\"\r\n\t\""); + out << "\"" << ImlEOL << "\t\""; start = out.GetPos(); } if((byte)*b >= ' ' && *b != '\x7F' && *b != '\xFF') { @@ -299,7 +302,7 @@ String SaveIml(const Array& iml, int format) { for(int i = 0; i < iml.GetCount(); i++) { const ImlImage& c = iml[i]; if(c.exp) - out << "IMAGE_META(\"exp\", \"\")\r\n"; + out << "IMAGE_META(\"exp\", \"\")" << ImlEOL; String name = c.name; Image buffer = c.image; if(IsNull(name)) @@ -314,7 +317,7 @@ String SaveIml(const Array& iml, int format) { out.PutLine("\tIMAGE_SCAN(\"\")"); out.Put("\tIMAGE_SCAN("); PutOctalString(out, scan.Begin(), scan.End(), true); - out.Put(")\r\n"); + out << ")" << ImlEOL; last = i + 1; } } @@ -331,11 +334,11 @@ String SaveIml(const Array& iml, int format) { ASSERT(!datastrm.IsError()); String s = datastrm.GetResult(); PutOctalString(out, s.Begin(), s.End()); - out.Put(")\r\n"); + out << ")" << ImlEOL; } } else { - out << "PREMULTIPLIED\r\n"; + out << "PREMULTIPLIED" << ImlEOL; Index std_name; for(int i = 0; i < iml.GetCount(); i++) { const ImlImage& c = iml[i]; @@ -351,8 +354,8 @@ String SaveIml(const Array& iml, int format) { out << "__DARK"; out << ")"; if(c.exp) - out << " IMAGE_META(\"exp\", \"\")\r\n"; - out << "\r\n"; + out << " IMAGE_META(\"exp\", \"\")" << ImlEOL; + out << ImlEOL; } int ii = 0; while(ii < iml.GetCount()) { @@ -372,7 +375,7 @@ String SaveIml(const Array& iml, int format) { bn++; } String bs = PackImlData(bimg); - out << "\r\nIMAGE_BEGIN_DATA\r\n"; + out << ImlEOL << "IMAGE_BEGIN_DATA" << ImlEOL; bs.Cat(0, ((bs.GetCount() + 31) & ~31) - bs.GetCount()); const byte *s = bs; for(int n = bs.GetCount() / 32; n--;) { @@ -381,9 +384,9 @@ String SaveIml(const Array& iml, int format) { if(j) out << ','; out << (int)*s++; } - out << ")\r\n"; + out << ")" << ImlEOL; } - out << "IMAGE_END_DATA(" << bs.GetCount() << ", " << bn << ")\r\n"; + out << "IMAGE_END_DATA(" << bs.GetCount() << ", " << bn << ")" << ImlEOL; } } return out.GetResult(); diff --git uppsrc/ide/LayDes/LayDes.h uppsrc/ide/LayDes/LayDes.h --- uppsrc/ide/LayDes/LayDes.h +++ uppsrc/ide/LayDes/LayDes.h @@ -276,6 +276,9 @@ public: virtual void Layout() override; virtual bool HotKey(dword key) override; + static String EOL; + static void SetEOL(const String& le) { EOL = le; } + private: bool DoKey(dword key, int count); bool DoHotKey(dword key); diff --git uppsrc/ide/LayDes/item.cpp uppsrc/ide/LayDes/item.cpp --- uppsrc/ide/LayDes/item.cpp +++ uppsrc/ide/LayDes/item.cpp @@ -212,7 +212,7 @@ String LayoutItem::Save(int i, int y) const else out << "\tITEM(" << type << ", "; String var = variable.IsEmpty() ? Format("dv___%d", i) : variable; - out << var << ", " << SaveProperties(y) << ")\r\n"; + out << var << ", " << SaveProperties(y) << ")" << LayDes::EOL; return out; } diff --git uppsrc/ide/LayDes/layfile.cpp uppsrc/ide/LayDes/layfile.cpp --- uppsrc/ide/LayDes/layfile.cpp +++ uppsrc/ide/LayDes/layfile.cpp @@ -107,6 +107,7 @@ bool LayDes::Load(const char *file, byte _charset) newfile = false; filetime = in.GetTime(); fileerror.Clear(); + SetEOL(GetLineEndings(layfile)); try { CParser p(layfile); if(p.Char('#') && p.Id("ifdef")) { @@ -129,6 +130,7 @@ bool LayDes::Load(const char *file, byte _charset) else { newfile = true; filetime = Null; + SetEOL("\r\n"); } search <<= Null; SyncLayoutList(); @@ -149,7 +151,7 @@ void LayDes::Save() String r; for(int i = 0; i < layout.GetCount(); i++) { layout[i].SetCharset(charset); - r << layout[i].Save(0) << "\r\n"; + r << layout[i].Save(0) << LayDes::EOL; } layfile = r; if(!SaveChangedFileFinish(filename, r)) diff --git uppsrc/ide/LayDes/layout.cpp uppsrc/ide/LayDes/layout.cpp --- uppsrc/ide/LayDes/layout.cpp +++ uppsrc/ide/LayDes/layout.cpp @@ -94,11 +94,11 @@ void LayoutData::Read(CParser& p) String LayoutData::Save(int y) { String out; - out << "LAYOUT(" << name << ", " << size.cx << ", " << size.cy << ")\r\n"; + out << "LAYOUT(" << name << ", " << size.cx << ", " << size.cy << ")" << LayDes::EOL; for(int i = 0; i < item.GetCount(); i++) { out << item[i].Save(i, y); } - out << "END_LAYOUT\r\n"; + out << "END_LAYOUT" << LayDes::EOL; return out; } @@ -107,10 +107,10 @@ String LayoutData::Save(const Vector& sel, int y) Vector cs(sel, 1); Sort(cs); String out; - out << "LAYOUT(" << name << ", " << size.cx << ", " << size.cy << ")\r\n"; + out << "LAYOUT(" << name << ", " << size.cx << ", " << size.cy << ")" << LayDes::EOL; for(int i = 0; i < cs.GetCount(); i++) out << item[cs[i]].Save(cs[i], y); - out << "END_LAYOUT\r\n"; + out << "END_LAYOUT" << LayDes::EOL; return out; } diff --git uppsrc/ide/LayDes/laywin.cpp uppsrc/ide/LayDes/laywin.cpp --- uppsrc/ide/LayDes/laywin.cpp +++ uppsrc/ide/LayDes/laywin.cpp @@ -278,6 +278,8 @@ bool LayDes::HotKey(dword key) StaticRect::HotKey(key); } +String LayDes::EOL("\r\n"); + LayDes::LayDes() { charset = CHARSET_UTF8;