int ParseInput()
{
bars = 0;
StringReader sr;
string line;
Match matchLine;
string sCurrentNumberDecimalSeparator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
char cCurrentNumberDecimalSeparator = sCurrentNumberDecimalSeparator.ToCharArray()[0];
char cNumberDecimalSeparator = numberDecimalSeparator.ToCharArray()[numberDecimalSeparator.ToCharArray().Length - 1];
bool isChangeDecSep = cNumberDecimalSeparator != cCurrentNumberDecimalSeparator;
Regex rx = new Regex(DataRowMatchPattern, RegexOptions.Compiled);
// Counts the data bars
bars = 0;
sr = new StringReader(input);
while ((line = sr.ReadLine()) != null)
if (rx.IsMatch(line))
bars++;
sr.Close();
if (bars == 0)
{
parsingErrorMessage = Language.T("Could not count the data bars!");
return -1;
}
int bar = 0;
aBar = new Bar[bars];
sr = new StringReader(input);
while ((line = sr.ReadLine()) != null)
{
matchLine = rx.Match(line);
if (matchLine.Success)
{
int year = int.Parse(matchLine.Groups["year"].Value);
int month = int.Parse(matchLine.Groups["month"].Value);
int day = int.Parse(matchLine.Groups["day"].Value);
int hour = int.Parse(matchLine.Groups["hour"].Value);
int min = int.Parse(matchLine.Groups["min"].Value);
int sec = (IsSeconds ? int.Parse(matchLine.Groups["sec"].Value) : 0);
if (year < 100)
year += 2000;
if (year > DateTime.Now.Year)
year -= 100;
if (isChangeDecSep)
{
aBar[bar].Time = new DateTime(year, month, day, hour, min, sec);
aBar[bar].Open = double.Parse(matchLine.Groups["open"].Value.Replace(cNumberDecimalSeparator, cCurrentNumberDecimalSeparator));
aBar[bar].High = double.Parse(matchLine.Groups["high"].Value.Replace(cNumberDecimalSeparator, cCurrentNumberDecimalSeparator));
aBar[bar].Low = double.Parse(matchLine.Groups["low"].Value.Replace(cNumberDecimalSeparator, cCurrentNumberDecimalSeparator));
aBar[bar].Close = double.Parse(matchLine.Groups["close"].Value.Replace(cNumberDecimalSeparator, cCurrentNumberDecimalSeparator));
aBar[bar].Volume = (IsVolumeColumn ? int.Parse(matchLine.Groups["volume"].Value) : 0);
}
else
{
aBar[bar].Time = new DateTime(year, month, day, hour, min, sec);
aBar[bar].Open = double.Parse(matchLine.Groups["open"].Value);
aBar[bar].High = double.Parse(matchLine.Groups["high"].Value);
aBar[bar].Low = double.Parse(matchLine.Groups["low"].Value);
aBar[bar].Close = double.Parse(matchLine.Groups["close"].Value);
aBar[bar].Volume = (IsVolumeColumn ? int.Parse(matchLine.Groups["volume"].Value) : 0);
}
bar++;
}
}
sr.Close();
return 0;
}