aboutsummaryrefslogtreecommitdiffstats
path: root/lib/edoc/src
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/edoc/src
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/edoc/src')
-rw-r--r--lib/edoc/src/edoc.erl35
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/edoc/src/edoc.erl b/lib/edoc/src/edoc.erl
index a87a8471e3..983f04e8b6 100644
--- a/lib/edoc/src/edoc.erl
+++ b/lib/edoc/src/edoc.erl
@@ -696,15 +696,44 @@ read_source_2(Name, Opts) ->
%% The line of the dot token will be copied to the integer token.
parse_file(Name, Includes, Macros) ->
- case epp:open(Name, Includes, Macros) of
- {ok, Epp} ->
- try {ok, parse_file(Epp)}
+ case parse_file(utf8, Name, Includes, Macros) of
+ invalid_unicode ->
+ parse_file(latin1, Name, Includes, Macros);
+ Ret ->
+ Ret
+ end.
+
+parse_file(DefEncoding, Name, Includes, Macros) ->
+ Options = [{name, Name},
+ {includes, Includes},
+ {macros, Macros},
+ {default_encoding, DefEncoding}],
+ case epp:open([extra | Options]) of
+ {ok, Epp, Extra} ->
+ try parse_file(Epp) of
+ Forms ->
+ Encoding = proplists:get_value(encoding, Extra),
+ case find_invalid_unicode(Forms) of
+ invalid_unicode when Encoding =/= utf8 ->
+ invalid_unicode;
+ _ ->
+ {ok, Forms}
+ end
after _ = epp:close(Epp)
end;
Error ->
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.
+
parse_file(Epp) ->
case scan_and_parse(Epp) of
{ok, Form} ->