Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Ref to Tuple change

  • Loading branch information...
michal-franc committed May 26, 2014
1 parent ffe6520 commit bd05a0d885d4e2cd1622f03200d1dd8ad6677002
Showing with 7 additions and 5 deletions.
  1. +7 −5 TddStringCalculator/TddStringCalculator/StringCalculator.cs
@@ -13,8 +13,8 @@ public int SumFromString(string input)
{
if (string.IsNullOrWhiteSpace(input)) return 0;

var delimeters = ExtractDelimeters(ref input);
return this.ParseSumValues(delimeters, input);
var extractedData = ExtractDelimeters(input);
return this.ParseSumValues(extractedData.Item1, extractedData.Item2);
}

private int ParseSumValues(IEnumerable<string> delimeters, string input)
@@ -38,18 +38,20 @@ private int ParseSumValues(IEnumerable<string> delimeters, string input)
}
}

private IEnumerable<string> ExtractDelimeters(ref string input)
private Tuple<IEnumerable<string>, string> ExtractDelimeters(string input)
{
var delimeterIndex = input.IndexOf("//");

var delimeters = new List<string>();

var extractedInput = input;

if (delimeterIndex >= 0)
{
var matches = DelimeterRegex.Matches(input);

var delim = matches.OfType<Match>().Select(m => m.Groups["delimeter"].Value).Single();
input = matches.OfType<Match>().Select(m => m.Groups["value"].Value).Single();
extractedInput = matches.OfType<Match>().Select(m => m.Groups["value"].Value).Single();
delimeters.Add(delim);
}
else
@@ -58,7 +60,7 @@ private IEnumerable<string> ExtractDelimeters(ref string input)
delimeters.Add("\n");
}

return delimeters;
return new Tuple<IEnumerable<string>, string>(delimeters, extractedInput);
}
}
}

0 comments on commit bd05a0d

Please sign in to comment.
You can’t perform that action at this time.