/// <summary> /// Parses the specified string to a sequence of cells /// that may contain a number or symbols or arithmetic operation. /// </summary> public InputCell[] Parse(string input) { var result = new LinkedList <InputCell>(); var numberBuffer = new NumberBuilder(); foreach (char ch in input) { if (ch.IsEmpty()) { continue; } if (ch.IsDigit() || ch.IsDot()) { numberBuffer.Append(ch); continue; } result.AddIfNotNull(CreateCell(numberBuffer)); if (ch.IsMinus() && IsMinusForNumber(result)) { numberBuffer.Append(ch); continue; } result.AddLast(InputCell.Symbol(ch)); } result.AddIfNotNull(CreateCell(numberBuffer)); return(result.ToArray()); }
public static InputCell CreateCell(NumberBuilder builder) { if (builder.IsEmpty()) { return(null); } double number = builder.Build(); builder.Clear(); return(InputCell.Number(number)); }