diff options
author | Hans Bolinder <[email protected]> | 2012-12-03 12:34:04 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2013-01-02 10:15:17 +0100 |
commit | b941448860fc2220695d04d8b8806509cb053b5a (patch) | |
tree | 3ec103a7bd6791eedac019d536649a3f459e0567 /lib/edoc/src/edoc_extract.erl | |
parent | 300c5466a7c9cfe3ed22bba2a88ba21058406402 (diff) | |
download | otp-b941448860fc2220695d04d8b8806509cb053b5a.tar.gz otp-b941448860fc2220695d04d8b8806509cb053b5a.tar.bz2 otp-b941448860fc2220695d04d8b8806509cb053b5a.zip |
[edoc] Introduce Unicode support for source files
Diffstat (limited to 'lib/edoc/src/edoc_extract.erl')
-rw-r--r-- | lib/edoc/src/edoc_extract.erl | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/edoc/src/edoc_extract.erl b/lib/edoc/src/edoc_extract.erl index 5a79e127f6..dcab816f54 100644 --- a/lib/edoc/src/edoc_extract.erl +++ b/lib/edoc/src/edoc_extract.erl @@ -226,7 +226,7 @@ add_macro_defs(Defs0, Opts, Env) -> %% lines of text before the first tag are ignored. `Env' is an %% environment created by {@link edoc_lib:get_doc_env/4}. Upon error, %% `Reason' is an atom returned from the call to {@link -%% //kernel/file:read_file/1}. +%% //kernel/file:read_file/1} or the atom 'invalid_unicode'. %% %% See {@link text/4} for options. @@ -235,7 +235,13 @@ add_macro_defs(Defs0, Opts, Env) -> file(File, Context, Env, Opts) -> case file:read_file(File) of {ok, Bin} -> - {ok, text(binary_to_list(Bin), Context, Env, Opts, File)}; + Enc = edoc_lib:read_encoding(File,[{in_comment_only, false}]), + case catch unicode:characters_to_list(Bin, Enc) of + String when is_list(String) -> + {ok, text(String, Context, Env, Opts, File)}; + _ -> + {error, invalid_unicode} + end; {error, _} = Error -> Error end. @@ -306,12 +312,14 @@ get_module_info(Forms, File) -> Exports = ordsets:from_list(get_list_keyval(exports, L)), Attributes = ordsets:from_list(get_list_keyval(attributes, L)), Records = get_list_keyval(records, L), + Encoding = edoc_lib:read_encoding(File, []), #module{name = Name, parameters = Vars, functions = Functions, exports = ordsets:intersection(Exports, Functions), attributes = Attributes, - records = Records}. + records = Records, + encoding = Encoding}. get_list_keyval(Key, L) -> case lists:keyfind(Key, 1, L) of |