mirror of https://github.com/swig/swig
Skip the UTF-8 BOM of including files.
For avoiding illegal token error when parsing include files which have the UTF-8 BOM. Closes #75.
This commit is contained in:
parent
9efaf954c7
commit
f55ff50dd5
|
@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 2.0.11 (in progress)
|
||||
============================
|
||||
|
||||
2013-08-29: wsfulton
|
||||
Pull Git patch #75: Handle UTF-8 files with BOM at beginning of file. Was giving an
|
||||
'Illegal token' syntax error.
|
||||
|
||||
2013-08-29: wsfulton
|
||||
[C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function.
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
%module bom_utf8
|
||||
|
||||
/* Test for UTF8 BOM at start of file */
|
||||
%inline %{
|
||||
struct NotALotHere {
|
||||
int n;
|
||||
};
|
||||
%}
|
||||
|
|
@ -552,7 +552,8 @@ C_TEST_CASES += \
|
|||
typedef_struct \
|
||||
typemap_subst \
|
||||
union_parameter \
|
||||
unions
|
||||
unions \
|
||||
utf8_bom
|
||||
|
||||
|
||||
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
||||
|
|
|
@ -163,7 +163,8 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
|
|||
String *filename;
|
||||
List *spath = 0;
|
||||
char *cname;
|
||||
int i, ilen;
|
||||
int i, ilen, nbytes;
|
||||
char bom[3];
|
||||
|
||||
if (!directories)
|
||||
directories = NewList();
|
||||
|
@ -191,6 +192,14 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
|
|||
if (f) {
|
||||
Delete(lastpath);
|
||||
lastpath = filename;
|
||||
|
||||
/* Skip the UTF-8 BOM if it's present */
|
||||
nbytes = fread(bom, 1, 3, f);
|
||||
if (nbytes == 3 && bom[0] == (char)0xEF && bom[1] == (char)0xBB && bom[2] == (char)0xBF) {
|
||||
/* skip */
|
||||
} else {
|
||||
fseek(f, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue