protected override UnitError DecodeLine(string line, ref int position, Func <char, bool> isIgnoreSymbol) { UnitError error = null; var savePosition = position; var valueSymbolPosition = 0; var ignoreCase = DecodeLineIgnoreCaseSymbols; if (_count != 0) { for (; position < line.Length; position++) { var symbolLine = line[position]; if (symbolLine.EqualsIgnoreCase(_symbols[valueSymbolPosition], ignoreCase)) { ++valueSymbolPosition; } else { var isError = !(valueSymbolPosition == 0 && isIgnoreSymbol(symbolLine)); if (isError) { break; } } if (valueSymbolPosition == _count) { position++; break; } } } if (valueSymbolPosition != _count) { error = CreateError(line, position, this, valueSymbolPosition); position = savePosition; } return(error); }
public bool DecodeEndLine(string line, int position, out UnitError error) { error = null; if (!string.IsNullOrEmpty(line)) { for (var i = position; i < line.Length; i++) { var symbol = line[i]; if (!_ignoreSymbols.IsIgnoreSymbol(symbol)) { error = CreateError(line, i, null, -1); break; } } } return(error == null); }
protected override UnitError DecodeLine(string line, ref int position, Func <char, bool> isIgnoreSymbol) { UnitError oldError = null; var savePosition = position; _selectedIndex = -1; var units = Units; for (var i = 0; i < units.Count; i++) { var unit = units[i]; unit.InitializeDecodeLine(); UnitError error; if (unit.DecodeLine(line, ref position, out error)) { _selectedIndex = i; break; } position = savePosition; if (oldError == null) { oldError = error; } else { if (oldError.PositionInLine == error.PositionInLine) { oldError = CreateError(oldError.Line, oldError.PositionInLine, null, -1); } else if (oldError.PositionInLine < error.PositionInLine) { oldError = error; } } } return(_selectedIndex != -1 ? null : oldError); }
protected override UnitError DecodeLine(string line, ref int position, Func <char, bool> isIgnoreSymbol) { UnitError error; UnitError oldError = null; while (true) { var isExit = true; foreach (var unit in _units) { if ((position == line.Length) || ((position + 1) == line.Length)) { break; } if (unit.DecodeLine(line, ref position, out error)) { if (unit.IsDead) { oldError = CreateError(line, position - GetLength(unit), unit.Unit, 0); } else { if (_isNoNextUnit) { oldError = null; } unit.Ageing(); if ((position + 1) != line.Length) { isExit = false; } } break; } if (_isNoNextUnit && unit.IsAlive) { if (error.Unit == null || !error.Unit.IgnoreSymbols.IsIgnoreSymbol(error.Line[error.PositionInLine])) { if (oldError == null || oldError.PositionInLine < error.PositionInLine) { oldError = error; } else { if (oldError.Unit != null && oldError.PositionInLine == error.PositionInLine) { oldError = new UnitError(error.Line, error.PositionInLine); } } } } } if (isExit) { error = null; break; } } if (oldError != null) { error = oldError; } return(error); }
public bool DecodeLine(string line, ref int position, out UnitError error) { error = line == null?CreateError(null, position, this, 0) : DecodeLine(line, ref position, _ignoreSymbols.IsIgnoreSymbol); return(error == null); }