Skip to content

Commit

Permalink
Merge pull request #128 from CanSeeThePain/OptionalEAN13CountryException
Browse files Browse the repository at this point in the history
Optional ean13 country exception.
  • Loading branch information
barnhill authored May 9, 2021
2 parents 6ac6856 + 6f1358d commit 4239194
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 5 additions & 1 deletion BarcodeStandard/BarcodeLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ public static Version Version
{
get { return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; }
}
/// <summary>
/// Disables EAN13 invalid country code exception.
/// </summary>
public bool DisableEAN13CountryException { get; set; } = false;
#endregion

/// <summary>
Expand Down Expand Up @@ -440,7 +444,7 @@ public string GenerateBarcode(string raw_data = "")
break;
case TYPE.UCC13:
case TYPE.EAN13: //Encode_EAN13();
ibarcode = new EAN13(Raw_Data);
ibarcode = new EAN13(Raw_Data, DisableEAN13CountryException);
break;
case TYPE.Interleaved2of5_Mod10:
case TYPE.Interleaved2of5: //Encode_Interleaved2of5();
Expand Down
24 changes: 17 additions & 7 deletions BarcodeStandard/Symbologies/EAN13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ class EAN13 : BarcodeCommon, IBarcode
private readonly Hashtable _countryCodes = new Hashtable(); //is initialized by init_CountryCodes()
private string _countryAssigningManufacturerCode = "N/A";

public EAN13(string input)
public EAN13(string input, bool disableCountryException = false)
{
Raw_Data = input;
DisableCountryException = disableCountryException;

CheckDigit();
CheckDigit();
}
/// <summary>
/// Encode the raw data using the EAN-13 algorithm. (Can include the checksum already. If it doesnt exist in the data then it will calculate it for you. Accepted data lengths are 12 + 1 checksum or just the 12 data digits)
/// </summary>
private string Encode_EAN13()

/// <summary>
/// Disables EAN13 invalid country code exception.
/// </summary>
public bool DisableCountryException { get; set; } = false;

/// <summary>
/// Encode the raw data using the EAN-13 algorithm. (Can include the checksum already. If it doesnt exist in the data then it will calculate it for you. Accepted data lengths are 12 + 1 checksum or just the 12 data digits)
/// </summary>
private string Encode_EAN13()
{
//check length of input
if (Raw_Data.Length < 12 || Raw_Data.Length > 13)
Expand Down Expand Up @@ -82,7 +89,10 @@ private string Encode_EAN13()
cc = _countryCodes[twodigitCode].ToString();
if (cc == null)
{
Error("EEAN13-3: Country assigning manufacturer code not found.");
if (!DisableCountryException)
{
Error("EEAN13-3: Country assigning manufacturer code not found.");
}
}
else
{
Expand Down

0 comments on commit 4239194

Please sign in to comment.