Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from remco1271/master
Add support for Field Hexadecimal Indicator(^FH)
- Loading branch information
Showing
5 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldHexadecimalZplCommandAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using BinaryKits.Zpl.Label.Elements; | ||
using BinaryKits.Zpl.Viewer.Helpers; | ||
|
||
namespace BinaryKits.Zpl.Viewer.CommandAnalyzers | ||
{ | ||
public class FieldHexadecimalZplCommandAnalyzer : ZplCommandAnalyzerBase | ||
{ | ||
public FieldHexadecimalZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base("^FH", virtualPrinter) | ||
{ } | ||
public override ZplElementBase Analyze(string zplCommand) | ||
{ | ||
var zplDataParts = this.SplitCommand(zplCommand); | ||
|
||
char Indicator = '_'; | ||
|
||
if (zplDataParts.Length > 0) | ||
{ | ||
Indicator = zplDataParts[0][0]; | ||
} | ||
StringHelper.ReplaceChar = Indicator; | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace BinaryKits.Zpl.Viewer.Helpers | ||
{ | ||
public static class StringHelper | ||
{ | ||
/// <summary> | ||
/// The hexadecimal indicator from the ^FH | ||
/// </summary> | ||
public static char ReplaceChar { get; set; } = '_'; | ||
|
||
/// <summary> | ||
/// Search for the Hexadecimal indicator and replaces it with the HEX char | ||
/// </summary> | ||
/// <param name="text">String to search in</param> | ||
/// <returns>Output string</returns> | ||
public static string ReplaceSpecialChars(this string text) | ||
{ | ||
if (!text.Contains(ReplaceChar)) | ||
return text; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < text.Length; i++) | ||
{ | ||
if (text[i] == ReplaceChar) | ||
{ | ||
string temp = text.Substring(i + 1, 2); | ||
sb.Append((char)Int16.Parse(temp, NumberStyles.AllowHexSpecifier)); | ||
i = i + 2; | ||
} | ||
else | ||
{ | ||
sb.Append(text[i]); | ||
} | ||
|
||
} | ||
return sb.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters