diff options
author | Magnus Lidén <[email protected]> | 2014-07-02 09:59:15 +0200 |
---|---|---|
committer | Magnus Lidén <[email protected]> | 2014-07-02 09:59:15 +0200 |
commit | 3edf161fa05cb1b16d8d3f98c6666d9b71293535 (patch) | |
tree | ff18c236ae06984ddd2fcf758c001d8a59fc4522 /lib/edoc/src | |
parent | a6de62be5de44b249bc2d1c963c0c31bed5d32d0 (diff) | |
parent | fbc5f26d8f00277aca13fd97a0eef2423446c249 (diff) | |
download | otp-3edf161fa05cb1b16d8d3f98c6666d9b71293535.tar.gz otp-3edf161fa05cb1b16d8d3f98c6666d9b71293535.tar.bz2 otp-3edf161fa05cb1b16d8d3f98c6666d9b71293535.zip |
Merge branch 'maint'
Diffstat (limited to 'lib/edoc/src')
-rw-r--r-- | lib/edoc/src/edoc.erl | 35 |
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} -> |