Addressed Issue #402. cIniFile can now process UTF-8 files that have a
Byte Order Marker, BOM.
This commit is contained in:
parent
a5b8d35845
commit
8c34b2d974
@ -83,7 +83,12 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
|
||||
}
|
||||
}
|
||||
|
||||
while (getline(f, line))
|
||||
if (getline(f, line))
|
||||
{
|
||||
// Removes UTF-8 Byte Order Markers (BOM) if, present.
|
||||
RemoveBom(line);
|
||||
|
||||
do
|
||||
{
|
||||
// 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.
|
||||
@ -155,7 +160,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
|
||||
break;
|
||||
}
|
||||
} // switch (line[pLeft])
|
||||
} // while (getline())
|
||||
} while (getline(f, line)); // do
|
||||
|
||||
f.close();
|
||||
if (names.size() == 0)
|
||||
@ -169,6 +174,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -824,3 +830,19 @@ 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 char BOM[] = { 0xEF, 0xBB, 0xBF };
|
||||
|
||||
// The BOM sequence, if present, is always the first three characters of the input.
|
||||
if (a_line.compare(0, 3, BOM) == 0)
|
||||
{
|
||||
a_line.erase(0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -51,6 +51,8 @@ private:
|
||||
/// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is
|
||||
AString CheckCase(const AString & s) const;
|
||||
|
||||
/// Removes the UTF-8 BOMs (Byte order makers), if present.
|
||||
void RemoveBom(AString & a_line) const;
|
||||
public:
|
||||
enum errors
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user