now_to_local_string/1, datetime_string_to_timestamp/1,
decode_base64/1, encode_base64/1, ip_to_list/1,
rsm_encode/1, rsm_encode/2, rsm_decode/1,
- binary_to_integer/1, binary_to_integer/2,
- integer_to_binary/1, integer_to_binary/2,
- atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1]).
+ binary_to_integer/1, binary_to_integer/2,
+ integer_to_binary/1, integer_to_binary/2,
+ atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1,
+ l2i/1, i2l/1, i2l/2]).
%% TODO: Remove once XEP-0091 is Obsolete
%% TODO: Remove once XEP-0091 is Obsolete
children = [{xmlcdata, i2l(Count)}]}
| Arr].
-i2l(I) when is_integer(I) -> integer_to_binary(I).
-
-type tz() :: {binary(), {integer(), integer()}} | {integer(), integer()} | utc.
%% Timezone = utc | {Sign::string(), {Hours, Minutes}} | {Hours, Minutes}
atom_to_binary(A) ->
erlang:atom_to_binary(A, utf8).
+
+
+l2i(I) when is_integer(I) -> I;
+l2i(L) when is_binary(L) -> binary_to_integer(L).
+
+i2l(I) when is_integer(I) -> integer_to_binary(I);
+i2l(L) when is_binary(L) -> L.
+
+i2l(I, N) when is_integer(I) -> i2l(i2l(I), N);
+i2l(L, N) when is_binary(L) ->
+ case str:len(L) of
+ N -> L;
+ C when C > N -> L;
+ _ -> i2l(<<$0, L/binary>>, N)
+ end.
get_items(NodeId, _From,
#rsm_in{max = M, direction = Direction, id = I,
index = IncIndex}) ->
- Max = (?PUBSUB):escape(i2l(M)),
+ Max = (?PUBSUB):escape(jlib:i2l(M)),
{Way, Order} = case Direction of
aft -> {<<"<">>, <<"desc">>};
before when I == <<>> -> {<<"is not">>, <<"asc">>};
NodeId,
<<"' and modification > pi.modification "
"having count1 = ">>,
- (?PUBSUB):escape(i2l(IncIndex)),
+ (?PUBSUB):escape(jlib:i2l(IncIndex)),
<<" );">>])
of
{selected, [_], [[O]]} ->
undefined -> [<<"modification">>, <<"null">>];
<<>> -> [<<"modification">>, <<"null">>];
I ->
- [A, B] = str:tokens((?PUBSUB):escape(i2l(I)),
+ [A, B] = str:tokens((?PUBSUB):escape(jlib:i2l(I)),
<<"@">>),
[A, <<"'", B/binary, "'">>]
end,
NodeId, <<"' and ">>, AttrName, <<" ">>,
Way, <<" ">>, Id, <<" order by ">>,
AttrName, <<" ">>, Order, <<" limit ">>,
- i2l(Max), <<" ;">>])
+ jlib:i2l(Max), <<" ;">>])
of
{selected,
[<<"itemid">>, <<"publisher">>, <<"creation">>,
[_, _, _, L, _] = lists:last(RItems),
RsmOut = #rsm_out{count = Count, index = Index,
first = <<"modification@", F/binary>>,
- last = <<"modification@", (i2l(L))/binary>>},
+ last = <<"modification@", (jlib:i2l(L))/binary>>},
{result, {[raw_to_item(NodeId, RItem) || RItem <- RItems], RsmOut}};
0 -> {result, {[], #rsm_out{count = Count}}}
end;
"where nodeid='">>,
NodeId,
<<"' order by modification desc limit ">>,
- i2l(Count), <<";">>])
+ jlib:i2l(Count), <<";">>])
of
{selected,
[<<"itemid">>, <<"publisher">>, <<"creation">>,
Payload = Item#pubsub_item.payload,
XML = (?PUBSUB):escape(str:join([xml:element_to_binary(X) || X<-Payload], <<>>)),
S = fun ({T1, T2, T3}) ->
- str:join([i2l(T1, 6), i2l(T2, 6), i2l(T3, 6)], <<":">>)
+ str:join([jlib:i2l(T1, 6), jlib:i2l(T2, 6), jlib:i2l(T3, 6)], <<":">>)
end,
case catch
ejabberd_odbc:sql_query_t([<<"update pubsub_item set publisher='">>,
JID = decode_jid(SJID),
ToTime = fun (Str) ->
[T1, T2, T3] = str:tokens(Str, <<":">>),
- {l2i(T1), l2i(T2), l2i(T3)}
+ {jlib:l2i(T1), jlib:l2i(T2), jlib:l2i(T3)}
end,
Payload = case xml_stream:parse_element(XML) of
{error, _Reason} -> [];
creation = {ToTime(Creation), JID},
modification = {ToTime(Modification), JID},
payload = Payload}.
-
-l2i(I) when is_integer(I) -> I;
-l2i(L) when is_binary(L) -> jlib:binary_to_integer(L).
-
-i2l(I) when is_integer(I) ->
- iolist_to_binary(integer_to_list(I));
-i2l(L) when is_binary(L) -> L.
-
-i2l(I, N) when is_integer(I) -> i2l(i2l(I), N);
-i2l(L, N) when is_binary(L) ->
- case str:len(L) of
- N -> L;
- C when C > N -> L;
- _ -> i2l(<<$0, L/binary>>, N)
- end.