GS1 Syntax Dictionary: Linter reference
A reference to the AI component linter routines referred to by the GS1 Syntax Dictionary.
lint_iso3166list.c File Reference

Purpose

The iso3166list linter ensures that the data is a concatenated sequence of ISO 3166 "num-3" country codes.

Remarks
The three-digit country codes are defined by ISO 3166-1: Codes for the representation of names of countries and their subdivisions - Part 1: Country code as the "num-3" codes.

Functional Description

◆ gs1_lint_iso3166list()

GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166list ( const char *const  data,
size_t *const  err_pos,
size_t *const  err_len 
)

Used to validate that an AI component is a concatenated sequence of ISO 3166 "num-3" country codes.

Parameters
[in]dataPointer to the null-terminated data to be linted. Must not be NULL.
[out]err_posTo facilitate error highlighting, the start position of the bad data is written to this pointer, if not NULL.
[out]err_lenThe length of the bad data is written to this pointer, if not NULL.
Returns
GS1_LINTER_OK if okay.
GS1_LINTER_NOT_ISO3166 if the data contains a part of the sequence that is not a num-3 country code, or the data is empty.
54 {
55 
56  const char *p, *q;
57  char c3[4] = {0};
58  gs1_lint_err_t ret;
59 
60  assert(data);
61 
62  p = data;
63  q = p + strlen(data);
64 
65  /*
66  * Process each group of three characters to check if it is a valid
67  * ISO 3166 num-3 country code.
68  *
69  */
70  while (p <= q - 3) {
71 
72  strncpy(c3, p, 3);
73 
74  ret = gs1_lint_iso3166(c3, err_pos, err_len);
75  assert(ret == GS1_LINTER_OK || ret == GS1_LINTER_NOT_ISO3166);
76 
77  if (ret != GS1_LINTER_OK) {
78  if (err_pos) *err_pos = (size_t)(p - data);
79  if (err_len) *err_len = 3;
80  return ret;
81  }
82 
83  p += 3;
84 
85  }
86 
87  /*
88  * Any remaining characters or an empty list are invalid.
89  *
90  */
91  if (p != q || q - data == 0) {
92  if (err_pos) *err_pos = (size_t)(p - data);
93  if (err_len) *err_len = (size_t)(q - p);
95  }
96 
97  return GS1_LINTER_OK;
98 
99 }
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166(const char *data, size_t *err_pos, size_t *err_len)
Definition: lint_iso3166.c:76
gs1_lint_err_t
Linter return codes other than GS1_LINTER_OK indicate an error condition.
Definition: gs1syntaxdictionary.h:65
@ GS1_LINTER_NOT_ISO3166
A valid ISO 3166 three-digit country code is required.
Definition: gs1syntaxdictionary.h:86
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition: gs1syntaxdictionary.h:66