Avoid using uninitialized static wxString in wxOSX code
Global "sCR" and "sLF" string objects could have been not yet initialized when wxMacConvertNewlines{13To10,10To13}() were called as these functions can be (implicitly) used when initializing other static objects. Fix the problem by avoiding the use of these objects, as well of wxString::Replace(), entirely and just iterating over the string directly using a simple, and more efficient, for loop. Note the use of "auto&&": a more usual "auto&" can't be used with temporary wxUniCharRef created by dereferencing wxString iterators. Using just "auto" would have actually worked too, but modifying a value via a copy would seem surprising, so use "auto&&" as a hopefully slightly more clear alternative. Closes #19110.
This commit is contained in:
@@ -25,20 +25,25 @@
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CFData.h>
|
||||
|
||||
const wxString sCR((wxChar)13);
|
||||
const wxString sLF((wxChar)10);
|
||||
|
||||
wxString wxMacConvertNewlines13To10(const wxString& data)
|
||||
{
|
||||
wxString string(data);
|
||||
string.Replace(sCR, sLF);
|
||||
for (auto&& c: string)
|
||||
{
|
||||
if (c == '\r')
|
||||
c = '\n';
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
wxString wxMacConvertNewlines10To13(const wxString& data)
|
||||
{
|
||||
wxString string(data);
|
||||
string.Replace(sLF, sCR);
|
||||
for (auto&& c: string)
|
||||
{
|
||||
if (c == '\n')
|
||||
c = '\r';
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user