using System.Text.RegularExpressions;
namespace Barcoded
{
internal class Code39Validator : ILinearValidator
{
///
/// Returns a string compatible with the given Code39 symbology.
///
/// Text to convert from.
/// Code39 symbology to be used.
/// Code39 supported string.
public string Parse(string text, Symbology symbology)
{
switch (symbology)
{
case Symbology.Code39Full:
return LinearHelpers.GetOnlyAscii(text);
case Symbology.Code39FullC:
return LinearHelpers.GetOnlyAscii(text);
default:
return GetOnlyCode39(text);
}
}
///
/// Returns a string containing only ASCII characters.
/// Non ASCII are converted to space character
///
/// Text to remove non ASCII from.
/// ASCII only version of input text.
private static string GetOnlyCode39(string text)
{
string returnString = text.ToUpper();
Regex code39Regex = new Regex("[^-0-9A-Z.$/+% ]");
returnString = code39Regex.Replace(returnString, " ");
return returnString;
}
}
}