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
4 changed files with 25 additions and 2 deletions
|
|
@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.11 (in progress)
|
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
|
2013-08-29: wsfulton
|
||||||
[C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function.
|
[C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function.
|
||||||
|
|
||||||
|
|
|
||||||
9
Examples/test-suite/bom_utf8.i
Normal file
9
Examples/test-suite/bom_utf8.i
Normal file
|
|
@ -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 \
|
typedef_struct \
|
||||||
typemap_subst \
|
typemap_subst \
|
||||||
union_parameter \
|
union_parameter \
|
||||||
unions
|
unions \
|
||||||
|
utf8_bom
|
||||||
|
|
||||||
|
|
||||||
# Multi-module C++ test cases . (Can be run individually using make testcase.multicpptest)
|
# 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;
|
String *filename;
|
||||||
List *spath = 0;
|
List *spath = 0;
|
||||||
char *cname;
|
char *cname;
|
||||||
int i, ilen;
|
int i, ilen, nbytes;
|
||||||
|
char bom[3];
|
||||||
|
|
||||||
if (!directories)
|
if (!directories)
|
||||||
directories = NewList();
|
directories = NewList();
|
||||||
|
|
@ -191,6 +192,14 @@ static FILE *Swig_open_file(const_String_or_char_ptr name, int sysfile, int use_
|
||||||
if (f) {
|
if (f) {
|
||||||
Delete(lastpath);
|
Delete(lastpath);
|
||||||
lastpath = filename;
|
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;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue