Replace calls from 'regexp' to the OTP R12 new module 're' (EJAB-921)

SVN Revision: 2582
This commit is contained in:
Badlop 2009-09-02 14:26:01 +00:00
parent 330a4c9452
commit 29b2da42f5
11 changed files with 67 additions and 60 deletions

View File

@ -281,14 +281,14 @@ build_additional_translators(List) ->
List).
print_translation(File, Line, Str, StrT) ->
{ok, StrQ, _} = regexp:gsub(Str, "\"", "\\\""),
{ok, StrTQ, _} = regexp:gsub(StrT, "\"", "\\\""),
StrQ = re:replace(Str, "\"", "\\\"", [global, {return, list}]),
StrTQ = re:replace(StrT, "\"", "\\\"", [global, {return, list}]),
io:format("#: ~s:~p~nmsgid \"~s\"~nmsgstr \"~s\"~n~n", [File, Line, StrQ, StrTQ]).
print_translation_obsolete(Str, StrT) ->
File = "unknown.erl",
Line = 1,
{ok, StrQ, _} = regexp:gsub(Str, "\"", "\\\""),
{ok, StrTQ, _} = regexp:gsub(StrT, "\"", "\\\""),
StrQ = re:replace(Str, "\"", "\\\"", [global, {return, list}]),
StrTQ = re:replace(StrT, "\"", "\\\"", [global, {return, list}]),
io:format("#: ~s:~p~n#~~ msgid \"~s\"~n#~~ msgstr \"~s\"~n~n", [File, Line, StrQ, StrTQ]).

View File

@ -301,18 +301,19 @@ match_acl(ACLName, JID, Host) ->
%% String = string() | undefined
%% RegExp = string()
is_regexp_match(undefined, RegExp) ->
is_regexp_match(undefined, _RegExp) ->
false;
is_regexp_match(String, RegExp) ->
case regexp:first_match(String, RegExp) of
try re:run(String, RegExp, [{capture, none}]) of
nomatch ->
false;
{match, _, _} ->
true;
{error, ErrDesc} ->
match ->
true
catch
_:ErrDesc ->
?ERROR_MSG(
"Wrong regexp ~p in ACL: ~p",
[RegExp, lists:flatten(regexp:format_error(ErrDesc))]),
"Wrong regexp ~p in ACL:~n~p",
[RegExp, ErrDesc]),
false
end.
@ -321,6 +322,6 @@ is_regexp_match(String, RegExp) ->
%% Glob = string()
is_glob_match(String, Glob) ->
is_regexp_match(String, regexp:sh_to_awk(Glob)).
is_regexp_match(String, xmerl_regexp:sh_to_awk(Glob)).

View File

@ -277,7 +277,7 @@ try_call_command(Args, Auth, AccessCommands) ->
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()} | {error, ErrorType}
call_command([CmdString | Args], Auth, AccessCommands) ->
{ok, CmdStringU, _} = regexp:gsub(CmdString, "-", "_"),
CmdStringU = re:replace(CmdString, "-", "_", [global,{return,list}]),
Command = list_to_atom(CmdStringU),
case ejabberd_commands:get_command_format(Command) of
{error, command_unknown} ->
@ -673,13 +673,13 @@ filter_commands(All, SubString) ->
end.
filter_commands_regexp(All, Glob) ->
RegExp = regexp:sh_to_awk(Glob),
RegExp = xmerl_regexp:sh_to_awk(Glob),
lists:filter(
fun(Command) ->
case regexp:first_match(Command, RegExp) of
{match, _, _} ->
case re:run(Command, RegExp, [{capture, none}]) of
match ->
true;
_ ->
nomatch ->
false
end
end,

View File

@ -735,11 +735,11 @@ match_labels([DL | DLabels], [PL | PLabels]) ->
orelse (C == $-) orelse (C == $*)
end, PL) of
true ->
Regexp = regexp:sh_to_awk(PL),
case regexp:match(DL, Regexp) of
{match, _, _} ->
Regexp = xmerl_regexp:sh_to_awk(PL),
case re:run(DL, Regexp, [{capture, none}]) of
match ->
match_labels(DLabels, PLabels);
_ ->
nomatch ->
false
end;
false ->

View File

@ -182,7 +182,7 @@ parse_attr(less, {Name, Value}, ListOfSubValues) ->
eldap:lessOrEqual(Name, NewValue);
parse_attr(equal, {Name, Value}, ListOfSubValues) ->
{ok, RegSList} = regexp:split(remove_extra_asterisks(Value), "[*]"),
RegSList = re:split(remove_extra_asterisks(Value), "[*]", [{return, list}]),
Pattern = case [do_sub(X, ListOfSubValues) || X <- RegSList] of
[Head | Tail] when Tail /= [] ->
{Head, lists:sublist(Tail, length(Tail)-1), lists:last(Tail)};
@ -228,14 +228,15 @@ do_sub(S, [{RegExp, New, Times} | T]) ->
do_sub(Result, T).
do_sub(S, {RegExp, New}, Iter) ->
case regexp:sub(S, RegExp, New) of
{ok, NewS, 0} ->
try re:replace(S, RegExp, New, [{return, list}]) of
NewS when NewS == S ->
NewS;
{ok, NewS, _} when Iter =< ?MAX_RECURSION ->
NewS when Iter =< ?MAX_RECURSION ->
do_sub(NewS, {RegExp, New}, Iter+1);
{ok, _, _} when Iter > ?MAX_RECURSION ->
throw({regexp, max_substitute_recursion});
_ ->
_ when Iter > ?MAX_RECURSION ->
throw({regexp, max_substitute_recursion})
catch
_:_ ->
throw({regexp, bad_regexp})
end;
@ -243,14 +244,15 @@ do_sub(S, {_, _, N}, _) when N<1 ->
S;
do_sub(S, {RegExp, New, Times}, Iter) ->
case regexp:sub(S, RegExp, New) of
{ok, NewS, 0} ->
try re:replace(S, RegExp, New, [{return, list}]) of
NewS when NewS == S ->
NewS;
{ok, NewS, _} when Iter < Times ->
NewS when Iter < Times ->
do_sub(NewS, {RegExp, New, Times}, Iter+1);
{ok, NewS, _} ->
NewS;
_ ->
NewS ->
NewS
catch
_:_ ->
throw({regexp, bad_regexp})
end.

View File

@ -89,8 +89,8 @@ get_user_part(String, Pattern) ->
{'EXIT', _} ->
{error, badmatch};
Result ->
case regexp:sub(Pattern, "%u", Result) of
{ok, String, _} -> {ok, Result};
case re:replace(Pattern, "%u", Result, [{return, list}]) of
String -> {ok, Result};
_ -> {error, badmatch}
end
end.

View File

@ -173,11 +173,11 @@ get_module_opt(Host, Module, Opt, Default) ->
get_module_opt_host(Host, Module, Default) ->
Val = get_module_opt(Host, Module, host, Default),
element(2, regexp:gsub(Val, "@HOST@", Host)).
re:replace(Val, "@HOST@", Host, [global,{return,list}]).
get_opt_host(Host, Opts, Default) ->
Val = get_opt(host, Opts, Default),
element(2, regexp:gsub(Val, "@HOST@", Host)).
re:replace(Val, "@HOST@", Host, [global,{return,list}]).
loaded_modules(Host) ->
ets:select(ejabberd_modules,

View File

@ -524,7 +524,7 @@ get_local_items({_, Host}, ["all users", [$@ | Diap]], _Server, _Lang) ->
Users ->
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
case catch begin
{ok, [S1, S2]} = regexp:split(Diap, "-"),
[S1, S2] = re:split(Diap, "-", [{return, list}]),
N1 = list_to_integer(S1),
N2 = list_to_integer(S2),
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),

View File

@ -415,11 +415,11 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
io_lib:format("<font class=\"msc\">~s~s~s</font><br/>",
[Nick, ?T(" has set the subject to: "), htmlize(T,NoFollow,FileFormat)]);
{body, T} ->
case {regexp:first_match(T, "^/me\s"), Nick} of
case {re:run(T, "^/me\s", [{capture, none}]), Nick} of
{_, ""} ->
io_lib:format("<font class=\"msm\">~s</font><br/>",
[htmlize(T,NoFollow,FileFormat)]);
{{match, _, _}, _} ->
{match, _} ->
io_lib:format("<font class=\"mne\">~s ~s</font><br/>",
[Nick, string:substr(htmlize(T,FileFormat), 5)]);
{nomatch, _} ->
@ -664,8 +664,7 @@ fw(F, S, O, FileFormat) ->
html ->
S1;
plaintext ->
{ok, Res, _} = regexp:gsub(S1, "<[^>]*>", ""),
Res
re:replace(S1, "<[^>]*>", "", [global,{return,list}])
end,
io:format(F, S2, []).
@ -794,15 +793,20 @@ htmlize(S1, NoFollow, _FileFormat) ->
S2_list).
htmlize2(S1, NoFollow) ->
S2 = element(2, regexp:gsub(S1, "\\&", "\\&amp;")),
S3 = element(2, regexp:gsub(S2, "<", "\\&lt;")),
S4 = element(2, regexp:gsub(S3, ">", "\\&gt;")),
S5 = element(2, regexp:gsub(S4, "((http|https|ftp)://|(mailto|xmpp):)[^] )\'\"}]+",
link_regexp(NoFollow))),
%% Remove 'right-to-left override' unicode character 0x202e
S6 = element(2, regexp:gsub(S5, " ", "\\&nbsp;\\&nbsp;")),
S7 = element(2, regexp:gsub(S6, "\\t", "\\&nbsp;\\&nbsp;\\&nbsp;\\&nbsp;")),
element(2, regexp:gsub(S7, [226,128,174], "[RLO]")).
ReplacementRules =
[{"\\&", "\\&amp;"},
{"<", "\\&lt;"},
{">", "\\&gt;"},
{"((http|https|ftp)://|(mailto|xmpp):)[^] )\'\"}]+", link_regexp(NoFollow)},
{" ", "\\&nbsp;\\&nbsp;"},
{"\\t", "\\&nbsp;\\&nbsp;\\&nbsp;\\&nbsp;"},
{[226,128,174], "[RLO]"}], %% Remove 'right-to-left override' unicode character 0x202e
lists:foldl(
fun({RegExp, Replace}, Acc) ->
re:replace(Acc, RegExp, Replace)
end,
S1,
ReplacementRules).
%% Regexp link
%% Add the nofollow rel attribute when required

View File

@ -561,8 +561,8 @@ is_user_in_group({_U, S} = US, Group, Host) ->
%% @spec (Host::string(), {User::string(), Server::string()}, Group::string()) -> {atomic, ok}
add_user_to_group(Host, US, Group) ->
{LUser, LServer} = US,
case regexp:match(LUser, "^@.+@$") of
{match,_,_} ->
case re:run(LUser, "^@.+@$", [{capture, none}]) of
match ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
AllUsersOpt =
case LUser == "@all@" of
@ -593,8 +593,8 @@ push_displayed_to_user(LUser, LServer, Group, Host, Subscription) ->
remove_user_from_group(Host, US, Group) ->
GroupHost = {Group, Host},
{LUser, LServer} = US,
case regexp:match(LUser, "^@.+@$") of
{match,_,_} ->
case re:run(LUser, "^@.+@$", [{capture, none}]) of
match ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
NewGroupOpts =
case LUser of
@ -856,7 +856,7 @@ shared_roster_group(Host, Group, Query, Lang) ->
[]
end ++ [[us_to_list(Member), $\n] || Member <- Members],
FDisplayedGroups = [[DG, $\n] || DG <- DisplayedGroups],
DescNL = length(element(2, regexp:split(Description, "\n"))),
DescNL = length(re:split(Description, "\n", [{return, list}])),
FGroup =
?XAE("table", [?XMLATTR('class', <<"withtextareas">>)],
[?XE("tbody",

View File

@ -1232,13 +1232,13 @@ acl_spec_select(ID, Opt) ->
term_to_string(T) ->
StringParagraph = lists:flatten(io_lib:format("~1000000p", [T])),
%% Remove from the string all the carriage returns characters
{ok, StringLine, _} = regexp:gsub(StringParagraph, "\\n ", ""),
StringLine = re:replace(StringParagraph, "\\n ", "", [global,{return,list}]),
StringLine.
%% @spec (T::any(), Cols::integer()) -> {NumLines::integer(), Paragraph::string()}
term_to_paragraph(T, Cols) ->
Paragraph = erl_prettypr:format(erl_syntax:abstract(T), [{paper, Cols}]),
{ok, FieldList} = regexp:split(Paragraph, "\n"),
FieldList = re:split(Paragraph, "\n", [{return, list}]),
NumLines = length(FieldList),
{NumLines, Paragraph}.
@ -1563,7 +1563,7 @@ list_users_parse_query(Query, Host) ->
list_users_in_diapason(Host, Diap, Lang, URLFunc) ->
Users = ejabberd_auth:get_vh_registered_users(Host),
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
{ok, [S1, S2]} = regexp:split(Diap, "-"),
[S1, S2] = re:split(Diap, "-", [{return, list}]),
N1 = list_to_integer(S1),
N2 = list_to_integer(S2),
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),