Permalink
Browse files

Removed redundant hidden eunit directory and fixed incorrect module n…

…ame in one of the unit tests
  • Loading branch information...
1 parent 8003d06 commit 4103a15e2e2004e98922aa15fedc9932a8e53f09 @ifandelse committed Jul 7, 2011
View
Binary file not shown.
View
@@ -1,148 +0,0 @@
--module(erlastic).
-
--export([parse_string/3, parse_string/4]).
-
-parse_string(Line, Delimiter, Qualifier) ->
- parse_string(Line, Delimiter, Qualifier, [trim_left, trim_right]).
-
-parse_string(Line, Delimiter, Qualifier, Options)->
- QualifierLen = string:len(Qualifier),
- DelimiterLen = string:len(Delimiter),
- Delims = lists:append([ line_start | sterling:find_all_positions(Line, Delimiter) ], [line_end]),
- Quals = sterling:find_all_positions(Line, Qualifier),
- ActualDelims = purge_false_delims(Delims, Quals),
- Fields = eval_escapes(
- remove_qualifiers(
- parse_fields(
- build_field_map(ActualDelims)
- ,Line
- ,DelimiterLen)
- ,Qualifier
- ,QualifierLen)
- ,Qualifier),
- apply_options(Fields, Options).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Use Delimiter Positions to build start, end coordinates for each field %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-build_field_map(Delims) ->
- build_field_map(Delims, []).
-
-build_field_map([line_end | []], Accum) ->
- lists:reverse(Accum);
-build_field_map([FieldStart | [FieldStop | _ ] = Rest], Accum) ->
- build_field_map(Rest, [ {FieldStart, FieldStop} | Accum ]).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Remove positions of delimiters that are legitimately inside a qualified field %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-purge_false_delims(Delims, []) ->
- Delims;
-purge_false_delims(Delims, [_ | []]) ->
- purge_false_delims(Delims, []);
-purge_false_delims(Delims, [QFirst | [ QSecond | [] ]]) ->
- NewDelims = lists:filter(fun(Elem) ->
- if
- Elem == line_start -> true;
- Elem == line_end -> true;
- true -> Elem < QFirst orelse Elem > QSecond
- end
- end,
- Delims),
- purge_false_delims(NewDelims, []);
-purge_false_delims(Delims, [QFirst | [ QSecond | Quals ] ]) ->
- NewDelims = lists:filter(fun(Elem) ->
- if
- Elem == line_start -> true;
- Elem == line_end -> true;
- true -> Elem < QFirst orelse Elem > QSecond
- end
- end,
- Delims),
- purge_false_delims(NewDelims, Quals).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Use the Field Map to extract the actual data for each field from the string %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-parse_fields(FieldMap, Line, DelimiterLen) ->
- parse_fields(FieldMap, Line, DelimiterLen, string:len(Line), []).
-
-parse_fields(Accum) ->
- lists:reverse(Accum).
-
-parse_fields([], _, _, _, Accum) ->
- lists:reverse(Accum);
-parse_fields([{line_start, line_end} | _], _, _, _, Accum) ->
- parse_fields([ [] | Accum ]);
-parse_fields([{line_start, 1} | Rest ], Line, DelimiterLen, Len, Accum) ->
- parse_fields(Rest, Line, DelimiterLen, Len, [ [] | Accum ]);
-parse_fields([{line_start, FieldStop} | Rest ], Line, DelimiterLen, Len, Accum) ->
- parse_fields(Rest, Line, DelimiterLen, Len, [ string:sub_string(Line, 1, FieldStop - 1) | Accum ]);
-parse_fields([{FieldStart, line_end} | _ ], _, _, Len, Accum) when FieldStart =:= Len ->
- parse_fields([ [] | Accum ]);
-parse_fields([{FieldStart, line_end} | _ ], Line, DelimiterLen, _, Accum) ->
- parse_fields([ string:sub_string(Line, FieldStart + DelimiterLen) | Accum ]);
-parse_fields([{Position, Position} | Rest ], Line, DelimiterLen, Len, Accum) ->
- parse_fields(Rest, Line, DelimiterLen, Len, [ [] | Accum ]);
-parse_fields([{FieldStart, FieldStop} | Rest ], Line, DelimiterLen, Len, Accum) ->
- parse_fields(Rest, Line, DelimiterLen, Len, [ string:sub_string(Line, FieldStart + DelimiterLen, FieldStop - 1) | Accum ]).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Remove leading and trailing qualifiers from the string if they exist %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-remove_qualifiers(Fields, Qualifier, QLen) ->
- remove_qualifiers(Fields, [], Qualifier, QLen).
-
-remove_qualifiers([], Accum, _, _) ->
- lists:reverse(Accum);
-remove_qualifiers([First | Rest ], Accum, Qualifier, QLen)->
- Trimmed = string:strip(First, both),
- Start = string:substr(Trimmed, 1, QLen),
- if
- Start == Qualifier ->
- remove_qualifiers(Rest, [ string:sub_string(Trimmed, QLen + 1, string:len(Trimmed) - QLen) | Accum ], Qualifier, QLen);
- true ->
- remove_qualifiers(Rest, [ Trimmed | Accum ], Qualifier, QLen)
- end.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Evaluate (i.e - collapse) the escaped qualifier sequences %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-eval_escapes(Fields, Qualifier)->
- eval_escapes(Fields, [], Qualifier).
-
-eval_escapes([], Accum, _) ->
- lists:reverse(Accum);
-eval_escapes([ Field | Rest ], Accum, Qualifier) ->
- TargetSeq = string:concat(Qualifier, Qualifier),
- TrimmedField = string:strip(Field, both),
- if
- TrimmedField == TargetSeq ->
- eval_escapes(Rest, [ sterling:gsubstitute_chars(TrimmedField, TargetSeq, "") | Accum ], Qualifier);
- true ->
- eval_escapes(Rest, [ sterling:gsubstitute_chars(Field, TargetSeq, Qualifier) | Accum ], Qualifier)
- end.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Apply Parsing Options Before Returning Field List to Caller %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-apply_options(Fields, [])->
- Fields;
-apply_options(Fields, [trim_left | Rest ]) ->
- apply_options(trim(Fields, left), Rest);
-apply_options(Fields, [trim_right | Rest ]) ->
- apply_options(trim(Fields, right), Rest);
-apply_options(Fields, [ _ | Rest ]) ->
- apply_options(Fields, Rest).
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% CLEANUP FUNCTIONS TO TRIM WHITESPACE IN FIELDS %%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-trim(Fields, Direction) ->
- trim(Fields, [], Direction).
-
-trim([], Accum, _) ->
- lists:reverse(Accum);
-trim([ Field | Rest ], Accum, Direction) ->
- NewAccum = [string:strip(Field, Direction) | Accum ],
- trim(Rest, NewAccum, Direction).
Binary file not shown.
@@ -1,81 +0,0 @@
--module(erlastic_tests).
--include_lib("eunit/include/eunit.hrl").
-
-parse_empty_unqualified_test() ->
- [[],[],[],[],[]] = erlastic:parse_string(",,,,", ",","").
-
-parse_empty_unqualified_dual_compound_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string("~$~$~$~$~$", "~$","").
-
-parse_empty_unqualified_dual_compound_same_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string(",,,,,,,,,,", ",,","").
-
-parse_empty_unqualified_triple_compound_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string("~$~~$~~$~~$~~$~", "~$~","").
-
-parse_empty_unqualified_triple_compound_same_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string(",,,,,,,,,,,,,,,", ",,,","").
-
-parse_unqualified_string_test() ->
- ["10","11","12","13","14","15"] = erlastic:parse_string("10,11,12,13,14,15", ",", "").
-
-parse_unqualified_string_with_compound_delimiter_test() ->
- ["Bugs","Bunny","Road","Runner",[],"10"] = erlastic:parse_string("Bugs~$Bunny~$Road~$Runner~$~$10", "~$", "").
-
-parse_empty_qualified_compound_same_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string("\"\",,\"\",,\"\",,\"\",,\"\",,\"\"", ",,","\"").
-
-parse_empty_qualified_test() ->
- [[],[],[],[],[]] = erlastic:parse_string("\"\",\"\",\"\",\"\",\"\"", ",", "\"").
-
-parse_qualified_string_test() ->
- ["10","11","12","13","14","15"] = erlastic:parse_string("\"10\",\"11\",\"12\",\"13\",\"14\",\"15\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_in_field_test() ->
- ["Field 1","Field 2","Field with \"escaped qualifiers\""] = erlastic:parse_string("\"Field 1\",\"Field 2\",\"Field with \"\"escaped qualifiers\"\"\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_and_nested_delims_test() ->
- ["Field 1","Field 2","Field with \",,escaped qualifiers,,\""] = erlastic:parse_string("\"Field 1\",\"Field 2\",\"Field with \"\",,escaped qualifiers,,\"\"\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_and_nested_delimsB_test() ->
- ["Field 1","Field 2","\",,escaped qualifiers,,\""] = erlastic:parse_string("\"Field 1\",\"Field 2\",\"\"\",,escaped qualifiers,,\"\"\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_and_nested_delimsC_test() ->
- ["Field 1","Field 2","Some \",,escaped qualifiers,,\" here"] = erlastic:parse_string("\"Field 1\",\"Field 2\",\"Some \"\",,escaped qualifiers,,\"\" here\"", ",", "\"").
-
-parse_qualified_string_surrounded_by_empty_unqualifieds_test() ->
- [[],"Field 2","Some \",,escaped qualifiers,,\" here",[]] = erlastic:parse_string(",\"Field 2\",\"Some \"\",,escaped qualifiers,,\"\" here\",", ",", "\"").
-
-parse_qualified_string_surrounded_by_empty_qualifieds_test() ->
- [[],"Field 2","Some \",,escaped qualifiers,,\" here",[]] = erlastic:parse_string("\"\",\"Field 2\",\"Some \"\",,escaped qualifiers,,\"\" here\",\"\"", ",", "\"").
-
-parse_qualified_string_with_nested_delims_at_start_of_field_test() ->
- ["Field 1","Field 2",",,escaped qualifiers,, hi"] = erlastic:parse_string("\"Field 1\",\"Field 2\",\",,escaped qualifiers,, hi\"", ",", "\"").
-
-parse_qualified_string_with_nested_delims_at_end_of_field_test() ->
- ["Field 1","Field 2","hi ,,escaped qualifiers,,"] = erlastic:parse_string("\"Field 1\",\"Field 2\",\"hi ,,escaped qualifiers,,\"", ",", "\"").
-
-parse_qualified_string_with_nested_delims_as_entire_field_test() ->
- ["Field 1","Field 2",",,escaped qualifiers,,"] = erlastic:parse_string("\"Field 1\",\"Field 2\",\",,escaped qualifiers,,\"", ",", "\"").
-
-parse_qualified_string_with_compound_delimiter_test() ->
- ["Bugs","Bunny","Road","Runner",[],"10"] = erlastic:parse_string("\"Bugs\"~$\"Bunny\"~$\"Road\"~$\"Runner\"~$~$10", "~$", "\"").
-
-parse_qualified_string_with_compound_triple_delimiter_test() ->
- ["Bugs","Bunny","Road","Runner",[],"10"] = erlastic:parse_string("\"Bugs\"=:=\"Bunny\"=:=\"Road\"=:=\"Runner\"=:==:=10", "=:=", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_in_field_and_spaced_test() ->
- ["Field 1","Field 2","Field with \"escaped qualifiers\""] = erlastic:parse_string("\"Field 1\", \" Field 2\", \" Field with \"\"escaped qualifiers\"\"\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_and_nested_delims_and_spaced_test() ->
- ["Field 1","Field 2","Field with \",,escaped qualifiers,,\""] = erlastic:parse_string("\"Field 1\", \" Field 2\", \" Field with \"\",,escaped qualifiers,,\"\"\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_and_nested_delimsB_and_spaced_test() ->
- ["Field 1","Field 2","\",,escaped qualifiers,,\""] = erlastic:parse_string("\" Field 1\", \" Field 2\", \" \"\",,escaped qualifiers,,\"\"\"", ",", "\"").
-
-parse_qualified_string_with_escaped_qualifiers_and_nested_delimsC_and_spaced_test() ->
- ["Field 1","Field 2","Some \",,escaped qualifiers,,\" here"] = erlastic:parse_string("\" Field 1 \", \" Field 2 \", \" Some \"\",,escaped qualifiers,,\"\" here\"", ",", "\"").
-
-parse_qualified_string_surrounded_by_empty_unqualifieds_and_spaced_test() ->
- [[],"Field 2","Some \",,escaped qualifiers,,\" here",[]] = erlastic:parse_string(",\" Field 2\", \" Some \"\",,escaped qualifiers,,\"\" here\",", ",", "\"").
-
View
Binary file not shown.
View
@@ -40,16 +40,6 @@ purge_false_delims(Delims, []) ->
Delims;
purge_false_delims(Delims, [_ | []]) ->
purge_false_delims(Delims, []);
-%% purge_false_delims(Delims, [QFirst | [ QSecond | [] ]]) ->
-%% NewDelims = lists:filter(fun(Elem) ->
-%% if
-%% Elem == line_start -> true;
-%% Elem == line_end -> true;
-%% true -> Elem < QFirst orelse Elem > QSecond
-%% end
-%% end,
-%% Delims),
-%% purge_false_delims(NewDelims, []);
purge_false_delims(Delims, [QFirst | [ QSecond | Quals ] ]) ->
NewDelims = lists:filter(fun(Elem) ->
if
Binary file not shown.
@@ -14,7 +14,7 @@ parse_empty_unqualified_dual_compound_delimiter_test() ->
[[],[],[],[],[],[]] = parserl:parse_string("~$~$~$~$~$", "~$","").
parse_empty_unqualified_dual_compound_same_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string(",,,,,,,,,,", ",,","").
+ [[],[],[],[],[],[]] = parserl:parse_string(",,,,,,,,,,", ",,","").
parse_empty_unqualified_triple_compound_delimiter_test() ->
[[],[],[],[],[],[]] = parserl:parse_string("~$~~$~~$~~$~~$~", "~$~","").
View
Binary file not shown.
@@ -14,7 +14,7 @@ parse_empty_unqualified_dual_compound_delimiter_test() ->
[[],[],[],[],[],[]] = parserl:parse_string("~$~$~$~$~$", "~$","").
parse_empty_unqualified_dual_compound_same_delimiter_test() ->
- [[],[],[],[],[],[]] = erlastic:parse_string(",,,,,,,,,,", ",,","").
+ [[],[],[],[],[],[]] = parserl:parse_string(",,,,,,,,,,", ",,","").
parse_empty_unqualified_triple_compound_delimiter_test() ->
[[],[],[],[],[],[]] = parserl:parse_string("~$~~$~~$~~$~~$~", "~$~","").

0 comments on commit 4103a15

Please sign in to comment.