1
0

Reworked RemoveBom to use unsigned chars and reverted the logic changes in WriteFile. Should work fine now.

This commit is contained in:
narroo 2014-02-16 09:25:32 -05:00
parent 03fd3b556a
commit 6eefd54d45

View File

@ -83,18 +83,23 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
}
}
if (getline(f, line))
{
// Removes UTF-8 Byte Order Markers (BOM) if, present.
RemoveBom(line);
bool IsFirstLine = true;
do
while (getline(f, line))
{
// To be compatible with Win32, check for existence of '\r'.
// Win32 files have the '\r' and Unix files don't at the end of a line.
// Note that the '\r' will be written to INI files from
// Unix so that the created INI file can be read under Win32
// without change.
// Removes UTF-8 Byte Order Markers (BOM) if, present.
if (IsFirstLine)
{
RemoveBom(line);
IsFirstLine = false;
}
size_t lineLength = line.length();
if (lineLength == 0)
{
@ -160,7 +165,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
break;
}
} // switch (line[pLeft])
} while (getline(f, line)); // do
} // while(getline(f, line))
f.close();
if (names.size() == 0)
@ -172,9 +177,9 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
{
WriteFile(FILE_IO_PREFIX + a_FileName);
}
return true;
}
}
@ -833,15 +838,24 @@ AString cIniFile::CheckCase(const AString & s) const
void cIniFile::RemoveBom(AString & a_line) const
{
// The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF ( In Unicode Latin I:  )
static const AString BOM = "" + 0xEF + 0xBB + 0xBF;
// The BOM sequence for UTF-8 is 0xEF,0xBB,0xBF
static unsigned const char BOM[] = { 0xEF, 0xBB, 0xBF };
// The BOM sequence, if present, is always th e first three characters of the input.
if (a_line.compare(0, 3, BOM) == 0)
const AString ref = a_line.substr(0, 3);
// If any of the first three chars do not match, return and do nothing.
for (int i = 0; i < 3; ++i)
{
if (static_cast<unsigned char>(ref[i]) != BOM[i])
{
return;
}
}
// First three characters match; erase them.
a_line.erase(0, 3);
}
}