couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r804428 - in /couchdb/trunk/src/couchdb: couch_config.erl couch_config_writer.erl couch_httpd_db.erl couch_log.erl couch_server.erl couch_view.erl
Date Sat, 15 Aug 2009 02:09:16 GMT
Author: kocolosk
Date: Sat Aug 15 02:09:16 2009
New Revision: 804428

URL: http://svn.apache.org/viewvc?rev=804428&view=rev
Log:
replace regexp with re. Thanks Kim Shrier, Gordon Stratton. Closes COUCHDB-245

Modified:
    couchdb/trunk/src/couchdb/couch_config.erl
    couchdb/trunk/src/couchdb/couch_config_writer.erl
    couchdb/trunk/src/couchdb/couch_httpd_db.erl
    couchdb/trunk/src/couchdb/couch_log.erl
    couchdb/trunk/src/couchdb/couch_server.erl
    couchdb/trunk/src/couchdb/couch_view.erl

Modified: couchdb/trunk/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_config.erl?rev=804428&r1=804427&r2=804428&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_config.erl (original)
+++ couchdb/trunk/src/couchdb/couch_config.erl Sat Aug 15 02:09:16 2009
@@ -184,13 +184,13 @@
             throw({startup_error, Msg})
     end,
 
-    {ok, Lines} = regexp:split(binary_to_list(IniBin), "\r\n|\n|\r|\032"),
+    Lines = re:split(IniBin, "\r\n|\n|\r|\032", [{return, list}]),
     {_, ParsedIniValues} =
     lists:foldl(fun(Line, {AccSectionName, AccValues}) ->
             case string:strip(Line) of
             "[" ++ Rest ->
-                case regexp:split(Rest, "\\]") of
-                {ok, [NewSectionName, ""]} ->
+                case re:split(Rest, "\\]", [{return, list}]) of
+                [NewSectionName, ""] ->
                     {NewSectionName, AccValues};
                 _Else -> % end bracket not at end, ignore this line
                     {AccSectionName, AccValues}
@@ -198,20 +198,20 @@
             ";" ++ _Comment ->
                 {AccSectionName, AccValues};
             Line2 ->
-                case regexp:split(Line2, "\s?=\s?") of
-                {ok, [_SingleElement]} -> % no "=" found, ignore this line
+                case re:split(Line2, "\s?=\s?", [{return, list}]) of
+                [_SingleElement] -> % no "=" found, ignore this line
                     {AccSectionName, AccValues};
-                {ok, [""|_LineValues]} -> % line begins with "=", ignore
+                [""|_LineValues] -> % line begins with "=", ignore
                     {AccSectionName, AccValues};
-                {ok, [ValueName|LineValues]} -> % yeehaw, got a line!
+                [ValueName|LineValues] -> % yeehaw, got a line!
                     RemainingLine = couch_util:implode(LineValues, "="),
                     % removes comments
-                    case regexp:split(RemainingLine, " ;|\t;") of
-                    {ok, [[]]} ->
+                    case re:split(RemainingLine, " ;|\t;", [{return, list}]) of
+                    [[]] ->
                         % empty line means delete this key
                         ets:delete(?MODULE, {AccSectionName, ValueName}),
                         {AccSectionName, AccValues};                        
-                    {ok, [LineValue | _Rest]} ->
+                    [LineValue | _Rest] ->
                         {AccSectionName,
                             [{{AccSectionName, ValueName}, LineValue} | AccValues]}
                     end

Modified: couchdb/trunk/src/couchdb/couch_config_writer.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_config_writer.erl?rev=804428&r1=804427&r2=804428&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_config_writer.erl (original)
+++ couchdb/trunk/src/couchdb/couch_config_writer.erl Sat Aug 15 02:09:16 2009
@@ -34,7 +34,7 @@
     % open file and create a list of lines
     {ok, Stream} = file:read_file(File),
     OldFileContents = binary_to_list(Stream),
-    {ok, Lines} = regexp:split(OldFileContents, "\r\n|\n|\r|\032"),
+    Lines = re:split(OldFileContents, "\r\n|\n|\r|\032", [{return, list}]),
 
     % prepare input variables
     SectionName = "[" ++ Section ++ "]",
@@ -136,13 +136,10 @@
 %% @doc Tries to match a line against a pattern specifying a ini module or
 %%      section ("[Section]"). Returns OldSection if no match is found.
 parse_module(Line, OldSection) ->
-    case regexp:match(Line, "^\\[([a-zA-Z0-9\_-]*)\\]$") of
+    case re:run(Line, "^\\[([a-zA-Z0-9\_-]*)\\]$", [{capture, global}]) of
         nomatch ->
             OldSection;
-        {error, Error} ->
-            io:format("ini file regex error module: '~s'~n", [Error]),
-            OldSection;
-        {match, Start, Length} ->
+        {match, [_, {Start, Length}]} ->
             string:substr(Line, Start, Length)
     end.
 
@@ -152,12 +149,9 @@
 %%      Option is not found. Returns a new line composed of the Option and
 %%      Value otherwise.
 parse_variable(Line, Option, Value) ->
-    case regexp:match(Line, "^" ++ Option ++ "\s?=") of
+    case re:run(Line, "^" ++ Option ++ "\s?=", [{capture, none}]) of
         nomatch ->
             nomatch;
-        {error, Error}->
-            io:format("ini file regex error variable: '~s'~n", [Error]),
-            nomatch;
-        {match, _Start, _Length} ->
+        match ->
             Option ++ " = " ++ Value
     end.

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=804428&r1=804427&r2=804428&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Sat Aug 15 02:09:16 2009
@@ -496,8 +496,8 @@
 % as slashes in document IDs must otherwise be URL encoded.
 db_req(#httpd{method='GET',mochi_req=MochiReq, path_parts=[DbName,<<"_design/",_/binary>>|_]}=Req,
_Db) ->
     PathFront = "/" ++ couch_httpd:quote(binary_to_list(DbName)) ++ "/",
-    RawSplit = regexp:split(MochiReq:get(raw_path),"_design%2F"),
-    {ok, [PathFront|PathTail]} = RawSplit,
+    [PathFront|PathTail] = re:split(MochiReq:get(raw_path), "_design%2F",
+        [{return, list}]),
     couch_httpd:send_redirect(Req, PathFront ++ "_design/" ++
         mochiweb_util:join(PathTail, "_design%2F"));
 
@@ -1008,12 +1008,12 @@
 
 parse_copy_destination_header(Req) ->
     Destination = couch_httpd:header_value(Req, "Destination"),
-    case regexp:match(Destination, "\\?") of
+    case re:run(Destination, "\\?", [{capture, none}]) of
     nomatch ->
         {list_to_binary(Destination), {0, []}};
-    {match, _, _} ->
-        {ok, [DocId, RevQueryOptions]} = regexp:split(Destination, "\\?"),
-        {ok, [_RevQueryKey, Rev]} = regexp:split(RevQueryOptions, "="),
+    match ->
+        [DocId, RevQs] = re:split(Destination, "\\?", [{return, list}]),
+        [_RevQueryKey, Rev] = re:split(RevQs, "=", [{return, list}]),
         {Pos, RevId} = couch_doc:parse_rev(Rev),
         {list_to_binary(DocId), {Pos, [RevId]}}
     end.

Modified: couchdb/trunk/src/couchdb/couch_log.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_log.erl?rev=804428&r1=804427&r2=804428&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_log.erl (original)
+++ couchdb/trunk/src/couchdb/couch_log.erl Sat Aug 15 02:09:16 2009
@@ -119,7 +119,8 @@
 log(Fd, Pid, Level, Format, Args) ->
     Msg = io_lib:format(Format, Args),
     ok = io:format("[~s] [~p] ~s~n", [Level, Pid, Msg]), % dump to console too
-    {ok, Msg2, _} = regexp:gsub(lists:flatten(Msg),"\\r\\n|\\r|\\n", "\r\n"),
+    Msg2 = re:replace(lists:flatten(Msg),"\\r\\n|\\r|\\n", "\r\n",
+        [global, {return, list}]),
     ok = io:format(Fd, "[~s] [~s] [~p] ~s\r~n\r~n", [httpd_util:rfc1123_date(), Level, Pid,
Msg2]).
 
 read(Bytes, Offset) ->

Modified: couchdb/trunk/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server.erl?rev=804428&r1=804427&r2=804428&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server.erl Sat Aug 15 02:09:16 2009
@@ -93,10 +93,10 @@
     gen_server:call(couch_server, {delete, DbName, Options}).
 
 check_dbname(#server{dbname_regexp=RegExp}, DbName) ->
-    case regexp:match(DbName, RegExp) of
+    case re:run(DbName, RegExp, [{capture, none}]) of
     nomatch ->
         {error, illegal_database_name};
-    _Match ->
+    match ->
         ok
     end.
 
@@ -150,7 +150,7 @@
             % spawn here so couch_config doesn't try to call itself
             spawn(fun() -> hash_admin_passwords() end)
         end),
-    {ok, RegExp} = regexp:parse("^[a-z][a-z0-9\\_\\$()\\+\\-\\/]*$"),
+    {ok, RegExp} = re:compile("^[a-z][a-z0-9\\_\\$()\\+\\-\\/]*$"),
     ets:new(couch_dbs_by_name, [set, private, named_table]),
     ets:new(couch_dbs_by_pid, [set, private, named_table]),
     ets:new(couch_dbs_by_lru, [ordered_set, private, named_table]),

Modified: couchdb/trunk/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_view.erl?rev=804428&r1=804427&r2=804428&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_view.erl Sat Aug 15 02:09:16 2009
@@ -90,7 +90,7 @@
 
     % filter out the ones in use
     DeleteFiles = lists:filter(fun(FilePath) ->
-            regexp:first_match(FilePath, RegExp)==nomatch
+            re:run(FilePath, RegExp, [{capture, none}]) == nomatch
         end, FileList),
     % delete unused files
     ?LOG_DEBUG("deleting unused view index files: ~p",[DeleteFiles]),



Mime
View raw message