public bool Decode(Barcode barcode) { var text = barcode.Scanned; var gs1Barcode = new Gs1128Barcode(barcode); // Max lenght for application identifier is four var applicationIdentifier = new StringBuilder(4); var data = new StringBuilder(); for (var i = 0; i < text.Length; ++i) { var character = text[i]; if (character == '(') { // Process application identifier do { character = text[++i]; if (character == ')') { break; } applicationIdentifier.Append(character); } while (true); } // Act upon application identifier and extract that it identifies var ai = applicationIdentifier.ToString(); var processor = Processors[ai]; processor(data, gs1Barcode, ref i); applicationIdentifier.Clear(); } return true; }
public static string Process(StringBuilder sb, Gs1128Barcode barcode, ref int i) { do { if (++i >= barcode.Scanned.Length) { // Reached end of string break; } var character = barcode.Scanned[i]; if (character == '(') { // Decrement iterator to move to state "reading application identifier" --i; break; } sb.Append(character); } while (true); return sb.ToString(); }