aboutsummaryrefslogtreecommitdiffstats
path: root/lib/syntax_tools/src/epp_dodger.erl
diff options
context:
space:
mode:
authorMagnus Lidén <[email protected]>2014-07-02 09:42:19 +0200
committerMagnus Lidén <[email protected]>2014-07-02 09:42:19 +0200
commitfbc5f26d8f00277aca13fd97a0eef2423446c249 (patch)
tree2128e7a886d14c27f05bd63af068f875b6f839ef /lib/syntax_tools/src/epp_dodger.erl
parentd2ade9b27432a1f7342e231d0d8b12467c3d3d77 (diff)
parenta7176f9186ffd7eb2b26daca2264d425383cf6a7 (diff)
downloadotp-fbc5f26d8f00277aca13fd97a0eef2423446c249.tar.gz
otp-fbc5f26d8f00277aca13fd97a0eef2423446c249.tar.bz2
otp-fbc5f26d8f00277aca13fd97a0eef2423446c249.zip
Merge branch 'maint-17' into maint
Diffstat (limited to 'lib/syntax_tools/src/epp_dodger.erl')
-rw-r--r--lib/syntax_tools/src/epp_dodger.erl28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/syntax_tools/src/epp_dodger.erl b/lib/syntax_tools/src/epp_dodger.erl
index 131be4e8e4..7e12eab1b5 100644
--- a/lib/syntax_tools/src/epp_dodger.erl
+++ b/lib/syntax_tools/src/epp_dodger.erl
@@ -184,9 +184,27 @@ quick_parse_file(File, Options) ->
parse_file(File, fun quick_parse/3, Options ++ [no_fail]).
parse_file(File, Parser, Options) ->
+ case do_parse_file(utf8, File, Parser, Options) of
+ {ok, Forms}=Ret ->
+ case find_invalid_unicode(Forms) of
+ none ->
+ Ret;
+ invalid_unicode ->
+ case epp:read_encoding(File) of
+ utf8 ->
+ Ret;
+ _ ->
+ do_parse_file(latin1, File, Parser, Options)
+ end
+ end;
+ Else ->
+ Else
+ end.
+
+do_parse_file(DefEncoding, File, Parser, Options) ->
case file:open(File, [read]) of
{ok, Dev} ->
- _ = epp:set_encoding(Dev),
+ _ = epp:set_encoding(Dev, DefEncoding),
try Parser(Dev, 1, Options)
after ok = file:close(Dev)
end;
@@ -194,6 +212,14 @@ parse_file(File, Parser, Options) ->
Error
end.
+find_invalid_unicode([H|T]) ->
+ case H of
+ {error, {_Line, file_io_server, invalid_unicode}} ->
+ invalid_unicode;
+ _Other ->
+ find_invalid_unicode(T)
+ end;
+find_invalid_unicode([]) -> none.
%% =====================================================================
%% @spec parse(IODevice) -> {ok, Forms} | {error, errorinfo()}