From f56afb1ea2dbd59262947ed27bb1913394aeb5c6 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Sat, 15 Aug 2009 02:09:16 +0000 Subject: replace regexp with re. Thanks Kim Shrier, Gordon Stratton. Closes COUCHDB-245 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@804428 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_config_writer.erl | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/couchdb/couch_config_writer.erl') diff --git a/src/couchdb/couch_config_writer.erl b/src/couchdb/couch_config_writer.erl index a829b40a..cb855ea8 100644 --- a/src/couchdb/couch_config_writer.erl +++ b/src/couchdb/couch_config_writer.erl @@ -34,7 +34,7 @@ save_to_file({{Section, Option}, Value}, File) -> % 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 @@ append_var_to_section({{Section, Option}, Value}, Line, OldCurrentSection, DoneO %% @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 @@ parse_module(Line, OldSection) -> %% 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. -- cgit v1.2.3