diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-08-15 02:09:16 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-08-15 02:09:16 +0000 |
commit | f56afb1ea2dbd59262947ed27bb1913394aeb5c6 (patch) | |
tree | 240b1d142ddcf20a7398c06a7075f0ab169acc3b /src/couchdb/couch_config_writer.erl | |
parent | bff8b7d9751fad8319124fbfa238446170885b21 (diff) |
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
Diffstat (limited to 'src/couchdb/couch_config_writer.erl')
-rw-r--r-- | src/couchdb/couch_config_writer.erl | 16 |
1 files changed, 5 insertions, 11 deletions
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. |