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

Purpose

The pcenc linter ensures that the data has correct percent-encoding.

Remarks
Percent-encoding is defined by RFC 3986: Uniform Resource Identifier (URI): Generic Syntax section "2.1. Percent-Encoding".

Functional Description

◆ gs1_lint_pcenc()

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

Used to ensure that an AI component conforms with correct percent encoding.

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_INVALID_PERCENT_SEQUENCE if the data contains an invalid percent sequence.
53 {
54 
55  const char *p, *q;
56  char pct[3] = {0};
57 
58  assert(data);
59 
60  p = data;
61  q = data + strlen(data);
62 
63  /*
64  * Find each instance of "%" in the data and ensure that there are at
65  * least two following characters and that these two characters
66  * represent a hex value.
67  *
68  */
69  while (p != q && (p = strchr(p, '%')) != NULL) {
70 
71  if (q - p < 3) {
72  if (err_pos) *err_pos = (size_t)(p - data);
73  if (err_len) *err_len = (size_t)(q - p);
75  }
76 
77  memcpy(pct, p + 1, 2);
78  if (strspn(pct, "0123456789ABCDEFabcdef") != 2) {
79  if (err_pos) *err_pos = (size_t)(p - data);
80  if (err_len) *err_len = 3;
82  }
83 
84  p += 3;
85 
86  }
87 
88  return GS1_LINTER_OK;
89 
90 }
@ GS1_LINTER_INVALID_PERCENT_SEQUENCE
The input contains an invalid percent hex-encoding "%hh" sequence.
Definition: gs1syntaxdictionary.h:110
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition: gs1syntaxdictionary.h:66