Skip to content

Commit

Permalink
Merge pull request #121 from ferd/otp20-unicode-support
Browse files Browse the repository at this point in the history
Add compile-time switch for OTP-20 string funcs
  • Loading branch information
lrascao authored Nov 1, 2017
2 parents fa1ec76 + f8f72b7 commit 4f086fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{platform_define, "^R1[4|5]", deprecated_crypto},
{platform_define, "^1[8|9]", rand_module},
{platform_define, "^2", rand_module},
{platform_define, "^2", unicode_str},
debug_info,
warnings_as_errors]}.

Expand Down
8 changes: 7 additions & 1 deletion src/ec_date.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ parse(Date, Now) ->
do_parse(Date, Now, []).

do_parse(Date, Now, Opts) ->
case filter_hints(parse(tokenise(string:to_upper(Date), []), Now, Opts)) of
case filter_hints(parse(tokenise(uppercase(Date), []), Now, Opts)) of
{error, bad_date} ->
erlang:throw({?MODULE, {bad_date, Date}});
{D1, T1} = {{Y, M, D}, {H, M1, S}}
Expand Down Expand Up @@ -728,6 +728,12 @@ pad6(X) when is_integer(X) ->
ltoi(X) ->
list_to_integer(X).

-ifdef(unicode_str).
uppercase(Str) -> string:uppercase(Str).
-else.
uppercase(Str) -> string:to_upper(Str).
-endif.

%%%===================================================================
%%% Tests
%%%===================================================================
Expand Down
13 changes: 11 additions & 2 deletions src/ec_git_vsn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ get_patch_count(RawRef) ->
parse_tags(Pattern) ->
Cmd = io_lib:format("git describe --abbrev=0 --match \"~s*\"", [Pattern]),
Tag = os:cmd(Cmd),
Vsn = string:substr(Tag, string:len(Pattern) + 1),
Vsn1 = string:strip(Vsn, left, $v),
Vsn = slice(Tag, len(Pattern) + 1),
Vsn1 = trim(Vsn, left, $v),
{Tag, Vsn1}.

-ifdef(unicode_str).
len(Str) -> string:length(Str).
trim(Str, Dir, Chars) -> string:trim(Str, Dir, Chars).
slice(Str, Len) -> string:slice(Str, Len).
-else.
len(Str) -> string:len(Str).
trim(Str, Dir, Chars) -> string:strip(Str, Dir, Chars).
slice(Str, Len) -> string:substr(Str, Len).
-endif.
10 changes: 9 additions & 1 deletion src/ec_talk.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ask_convert(Prompt, TransFun, Type, Default) ->
Default ->
[" (", io_lib:format("~p", [Default]) , ")"]
end, "> "])),
Data = string:strip(string:strip(io:get_line(NewPrompt)), both, $\n),
Data = trim(trim(io:get_line(NewPrompt)), both, $\n),
Ret = TransFun(Data),
case Ret of
no_data ->
Expand Down Expand Up @@ -197,6 +197,14 @@ get_string(String) ->
no_clue
end.

-ifdef(unicode_str).
trim(Str) -> string:trim(Str).
trim(Str, Dir, Chars) -> string:trim(Str, Dir, Chars).
-else.
trim(Str) -> string:strip(Str).
trim(Str, Dir, Chars) -> string:strip(Str, Dir, Chars).
-endif.

%%%====================================================================
%%% tests
%%%====================================================================
Expand Down

0 comments on commit 4f086fc

Please sign in to comment.