4
%% Copyright Ericsson AB 2008-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 2008-2011. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
33
33
{NewOpt,Convert,Unicode,Limit,Strip,Group} =
34
34
process_split_params(Options,iodata,false,-1,false,false),
36
case is_binary(Subject) of
42
unicode:characters_to_binary(Subject,unicode);
44
iolist_to_binary(Subject)
35
FlatSubject = to_binary(Subject, Unicode),
47
36
case compile_split(RE,NewOpt) of
50
39
{PreCompiled, NumSub, RunOpt} ->
52
41
case re:run(FlatSubject,PreCompiled,RunOpt ++ [global]) of
56
45
convert_any_split_result([[FlatSubject]],
57
Convert, Unicode,true);
46
Convert, Unicode, true);
59
48
convert_any_split_result([FlatSubject],
60
Convert, Unicode,false)
49
Convert, Unicode, false)
62
51
{match, Matches} ->
63
52
Res = do_split(FlatSubject, 0, Matches, NumSub,
80
69
erlang:error(badarg,[Subject,RE,Options])
83
backstrip_empty(List,false) ->
72
backstrip_empty(List, false) ->
84
73
do_backstrip_empty(List);
85
74
backstrip_empty(List, true) ->
86
75
do_backstrip_empty_g(List).
208
197
compile_split(_,_) ->
214
201
replace(Subject,RE,Replacement) ->
215
202
replace(Subject,RE,Replacement,[]).
216
204
replace(Subject,RE,Replacement,Options) ->
218
206
{NewOpt,Convert,Unicode} =
219
207
process_repl_params(Options,iodata,false),
221
case is_binary(Subject) of
227
unicode:characters_to_binary(Subject,unicode);
229
iolist_to_binary(Subject)
208
FlatSubject = to_binary(Subject, Unicode),
209
FlatReplacement = to_binary(Replacement, Unicode),
210
IoList = do_replace(FlatSubject,Subject,RE,FlatReplacement,NewOpt),
217
iolist_to_binary(IoList);
219
unicode:characters_to_binary(IoList,unicode)
224
binary_to_list(iolist_to_binary(IoList));
226
unicode:characters_to_list(IoList,unicode)
232
case do_replace(FlatSubject,Subject,RE,Replacement,NewOpt) of
240
iolist_to_binary(IoList);
244
binary_to_list(iolist_to_binary(IoList));
246
unicode:characters_to_list(IoList,unicode)
252
231
erlang:error(badarg,[Subject,RE,Replacement,Options]);
256
235
erlang:error(badarg,[Subject,RE,Replacement,Options])
260
239
do_replace(FlatSubject,Subject,RE,Replacement,Options) ->
261
240
case re:run(FlatSubject,RE,Options) of
324
303
{[H|NT],NC,NU,NL,NS,NG}.
326
305
apply_mlist(Subject,Replacement,Mlist) ->
327
do_mlist(Subject,Subject,0,precomp_repl(iolist_to_binary(Replacement)),
306
do_mlist(Subject,Subject,0,precomp_repl(Replacement), Mlist).
331
309
precomp_repl(<<>>) ->
333
311
precomp_repl(<<$\\,X,Rest/binary>>) when X < $1 ; X > $9 ->
335
313
case precomp_repl(Rest) of
336
314
[BHead | T0] when is_binary(BHead) ->
337
315
[<<X,BHead/binary>> | T0];
542
520
process_uparams([],Type) ->
546
524
ucompile(RE,Options) ->
548
re:compile(unicode:characters_to_binary(RE,unicode))
526
re:compile(unicode:characters_to_binary(RE,unicode),Options)
550
528
error:AnyError ->
551
529
{'EXIT',{new_stacktrace,[{Mod,_,L}|Rest]}} =
565
543
[Subject,RE,Options])),
566
544
erlang:raise(error,AnyError,[{Mod,run,L}|Rest])
568
547
urun2(Subject0,RE0,Options0) ->
569
548
{Options,RetType} = case (catch process_uparams(Options0,index)) of
619
597
grun2(Subject,RE,{Options,NeedClean}) ->
620
598
Unicode = check_for_unicode(RE,Options),
622
case is_binary(Subject) of
628
unicode:characters_to_binary(Subject,unicode);
630
iolist_to_binary(Subject)
599
FlatSubject = to_binary(Subject, Unicode),
633
600
do_grun(FlatSubject,Subject,Unicode,RE,{Options,NeedClean}).
635
602
do_grun(FlatSubject,Subject,Unicode,RE,{Options0,NeedClean}) ->
720
to_binary(Bin, _IsUnicode) when is_binary(Bin) ->
722
to_binary(Data, true) ->
723
unicode:characters_to_binary(Data,unicode);
724
to_binary(Data, false) ->
725
iolist_to_binary(Data).