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'.
|
// 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.
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
} // switch (line[pLeft])
|
} // switch (line[pLeft])
|
||||||
} // while (getline())
|
} while (getline(f, line)); // do
|
||||||
|
|
||||||
f.close();
|
f.close();
|
||||||
if (names.size() == 0)
|
if (names.size() == 0)
|
||||||
@ -168,6 +173,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
|
|||||||
WriteFile(FILE_IO_PREFIX + a_FileName);
|
WriteFile(FILE_IO_PREFIX + a_FileName);
|
||||||
}
|
}
|
||||||
return true;
|
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
|
/// If the object is case-insensitive, returns s as lowercase; otherwise returns s as-is
|
||||||
AString CheckCase(const AString & s) const;
|
AString CheckCase(const AString & s) const;
|
||||||
|
|
||||||
|
/// Removes the UTF-8 BOMs (Byte order makers), if present.
|
||||||
|
void RemoveBom(AString & a_line) const;
|
||||||
public:
|
public:
|
||||||
enum errors
|
enum errors
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user