Support OTP-21's unicode-only constraints
Functions start being available in OTP-20, so to get rid of warnings, a conditional compilation flag is set there. The cspan function has no direct equivalent, but can be worked around. Likely heavier work would be required around its usage where strings are not handled as lists, but only through 'string' functions. However this will still cover most cases and get rid of compile-time warnings for now.
This commit is contained in:
parent
68fe326f2c
commit
76fc2dcdc8
@ -11,5 +11,7 @@
|
||||
warn_export_vars,
|
||||
warn_exported_vars,
|
||||
warn_missing_spec,
|
||||
warn_untyped_record, debug_info]}.
|
||||
warn_untyped_record, debug_info,
|
||||
{platform_define, "^2", unicode_str}
|
||||
]}.
|
||||
{xref_checks, [undefined_function_calls]}.
|
||||
|
1
rebar.lock
Normal file
1
rebar.lock
Normal file
@ -0,0 +1 @@
|
||||
[].
|
@ -442,7 +442,7 @@ to_type(integer, Arg) ->
|
||||
to_type(float, Arg) ->
|
||||
list_to_float(Arg);
|
||||
to_type(boolean, Arg) ->
|
||||
LowerArg = string:to_lower(Arg),
|
||||
LowerArg = lowercase(Arg),
|
||||
case is_arg_true(LowerArg) of
|
||||
true ->
|
||||
true;
|
||||
@ -500,7 +500,7 @@ is_implicit_arg(_Type, _Arg) ->
|
||||
|
||||
-spec is_boolean_arg(string()) -> boolean().
|
||||
is_boolean_arg(Arg) ->
|
||||
LowerArg = string:to_lower(Arg),
|
||||
LowerArg = lowercase(Arg),
|
||||
is_arg_true(LowerArg) orelse is_arg_false(LowerArg).
|
||||
|
||||
|
||||
@ -619,7 +619,7 @@ usage_cmd_line(ProgramName, OptSpecList, CmdLineTail) ->
|
||||
%% already wrapped according to the maximum MaxLineLength.
|
||||
-spec usage_cmd_line_options(MaxLineLength :: non_neg_integer(), [option_spec()], CmdLineTail :: string()) -> iolist().
|
||||
usage_cmd_line_options(MaxLineLength, OptSpecList, CmdLineTail) ->
|
||||
usage_cmd_line_options(MaxLineLength, OptSpecList ++ string:tokens(CmdLineTail, " "), [], 0, []).
|
||||
usage_cmd_line_options(MaxLineLength, OptSpecList ++ lexemes(CmdLineTail, " "), [], 0, []).
|
||||
|
||||
usage_cmd_line_options(MaxLineLength, [OptSpec | Tail], LineAcc, LineAccLength, Acc) ->
|
||||
Option = [$\s | lists:flatten(usage_cmd_line_option(OptSpec))],
|
||||
@ -790,7 +790,7 @@ wrap_text_line(Length, [_ | _] = Help, Acc, Count, CurrentLineAcc) ->
|
||||
%% Look for the first whitespace character in the current (reversed) line
|
||||
%% buffer to get a wrapped line. If there is no whitespace just cut the
|
||||
%% line at the position corresponding to the maximum length.
|
||||
{NextLineAcc, WrappedLine} = case string:cspan(CurrentLineAcc, " \t") of
|
||||
{NextLineAcc, WrappedLine} = case cspan(CurrentLineAcc, " \t") of
|
||||
WhitespacePos when WhitespacePos < Count ->
|
||||
lists:split(WhitespacePos, CurrentLineAcc);
|
||||
_ ->
|
||||
@ -933,3 +933,15 @@ to_string(Atom) when is_atom(Atom) ->
|
||||
atom_to_list(Atom);
|
||||
to_string(Value) ->
|
||||
io_lib:format("~p", [Value]).
|
||||
|
||||
%% OTP-20/21 conversion to unicode string module
|
||||
-ifdef(unicode_str).
|
||||
lowercase(Str) -> string:lowercase(Str).
|
||||
lexemes(Str, Separators) -> string:lexemes(Str, Separators).
|
||||
cspan(Str, Chars) -> length(element(1,string:take(Str, Chars, true))).
|
||||
-else.
|
||||
lowercase(Str) -> string:to_lower(Str).
|
||||
lexemes(Str, Separators) -> string:tokens(Str, Separators).
|
||||
cspan(Str, Chars) -> string:cspan(Str, Chars).
|
||||
-endif.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user