NIF для ICU
02/11/2011 12:09
Михаил Уваров начал работу над библиотекой i18n, которая позволяет вызывать функции из библиотеки ICU, используя NIF. Если вы не знаете, что такое ICU, вам сюда: http://site.icu-project.org/
Детально про библиотеку можно почитать тут: https://github.com/freeakk/i18n
Примеры использования:
Модификация регистра
S=i18n_string:from_utf8(<<"the quick brown Fox jumps over the lazy Dog.">>). i18n_string:to_utf8(i18n_string:to_upper(S)). i18n_string:to_utf8(i18n_string:to_title(S)). I=i18n_iterator:open(sentence). i18n_string:to_utf8(i18n_string:to_title(I, S)).
Поиск
CS = i18n_collation:open([secondary]).
CT = i18n_collation:open().
S = i18n:from("abcd ABCD").
P = i18n:from("a").
SCSP = i18n_search:open(CS, P).
SCTP = i18n_search:open(CT, P).
i18n_search:index(SCSP, S).
i18n_search:index(SCTP, S).
i18n_search:match_all(SCSP, S).Collation на основе правил
R1 = i18n_collation:open().
R2 = i18n_collation:open_rules(i18n:from("& g <<< ca")).
F = fun(R, L) ->
lists:map(fun i18n:to/1,
i18n_collation:sort(R,
lists:map(fun i18n:from/1, L))) end.
L = ["ca", "h", "f", "cà"].
{F(R1, L), F(R2, L)}.
{[<<"ca">>,<<"cà ">>,<<"f">>,<<"h">>],
[<<"cà ">>,<<"f">>,<<"ca">>,<<"h">>]}где
io:format("~ts", [<<"cà ">>]).
càИзвлечение слов
1> lists:map(fun i18n:to/1,
i18n_string:split(i18n_iterator:open(word_only),
i18n:from("This string contains 5 words."))).
[<<"This">>,<<"string">>,<<"contains">>,<<"5">>,<<"words">>]
