aboutsummaryrefslogtreecommitdiffstats
path: root/src/rlx_string.erl
diff options
context:
space:
mode:
authorFred Hebert <[email protected]>2017-11-01 15:40:09 -0400
committerFred Hebert <[email protected]>2017-11-01 15:40:09 -0400
commit7e78c133c7a373384411d9fd0e1366b14e4c31d8 (patch)
treeb15f294821ce2bcddf14f97cbae0e50beabebb57 /src/rlx_string.erl
parentfb91587091ad8a9da7c22598e962d0f21dcc17ee (diff)
downloadrelx-7e78c133c7a373384411d9fd0e1366b14e4c31d8.tar.gz
relx-7e78c133c7a373384411d9fd0e1366b14e4c31d8.tar.bz2
relx-7e78c133c7a373384411d9fd0e1366b14e4c31d8.zip
Support OTP-20 Unicode functions
Use either optional compilation or version-safe variants of the string functions. Prevents warnings when the switch to OTP-21 will happen.
Diffstat (limited to 'src/rlx_string.erl')
-rw-r--r--src/rlx_string.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/rlx_string.erl b/src/rlx_string.erl
new file mode 100644
index 0000000..1f9cc0c
--- /dev/null
+++ b/src/rlx_string.erl
@@ -0,0 +1,23 @@
+%% Compatibility module for the string API changes between
+%% OTP-19 and OTP-21, where Unicode support means the deprecation
+%% of a lot of string functions.
+-module(rlx_string).
+-export([concat/2, lexemes/2, join/2]).
+
+-ifdef(unicode_str).
+concat(Str1, Str2) -> unicode:characters_to_list([Str1,Str2]).
+lexemes(Str, Separators) -> string:lexemes(Str, Separators).
+-else.
+concat(Str1, Str2) -> string:concat(Str1, Str2).
+lexemes(Str, Separators) -> string:tokens(Str, Separators).
+-endif.
+
+%% string:join/2 copy; string:join/2 is getting obsoleted
+%% and replaced by lists:join/2, but lists:join/2 is too new
+%% for version support (only appeared in 19.0) so it cannot be
+%% used. Instead we just adopt join/2 locally and hope it works
+%% for most unicode use cases anyway.
+join([], Sep) when is_list(Sep) ->
+ [];
+join([H|T], Sep) ->
+ H ++ lists:append([Sep ++ X || X <- T]).