diff --git a/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs b/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs index 6083209..7470fe4 100644 --- a/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs +++ b/src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs @@ -122,6 +122,11 @@ public AnalyzeInfo Analyze(string zplData) return analyzeInfo; } + // When adding new commands: 1 per line, always upper case, comment why if possible + private string[] ignoredCommands = { + "CI", // may be implemented in the future, but for now always set to CI128 + }; + private string[] SplitZplCommands(string zplData) { if (string.IsNullOrWhiteSpace(zplData)) @@ -134,6 +139,7 @@ private string[] SplitZplCommands(string zplData) char tilde = '~'; List results = new(200); StringBuilder buffer = new(2000); + HashSet ignoredCommandsHS = new HashSet(ignoredCommands); for (int i = 0; i < cleanZpl.Length; i++) { char c = cleanZpl[i]; @@ -141,25 +147,33 @@ private string[] SplitZplCommands(string zplData) { string command = buffer.ToString(); buffer.Clear(); + + // all commands have at least 3 chars, even ^A because of required font parameter if (command.Length > 2) { PatchCommand(ref command, ref caret, ref tilde); - results.Add(command); - if (command.Substring(1, 2) == "CT") + + var commandLetters = command.Substring(1, 2).ToUpper(); + + if (ignoredCommandsHS.Contains(commandLetters)) { + continue; + } + else if (commandLetters == "CT") { tilde = command[3]; - results.RemoveAt(results.Count - 1); } - else if (command.Substring(1, 2) == "CC") + else if (commandLetters == "CC") { caret = command[3]; - results.RemoveAt(results.Count - 1); + } else { + results.Add(command); } } // likely invalid command else if (command.Trim().Length > 0) { results.Add(command.Trim()); } + // no else case, multiple ^ or ~ in a row should not be valid commands to be processed } buffer.Append(c); }