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

Purpose

The hhmm linter ensures that the given data is meaningful time as hours and minutes, in HHMM format.

Functional Description

◆ gs1_lint_hhmm()

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

Used to ensure that an AI component conforms to HHMM format.

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_HOUR_WITH_MINUTE_TOO_SHORT if the data is too short for HHMM format.
GS1_LINTER_HOUR_WITH_MINUTE_TOO_LONG if the data is too long for HHMM format.
GS1_LINTER_NON_DIGIT_CHARACTER if the data contains a non-digit character.
GS1_LINTER_ILLEGAL_HOUR if the data contains an invalid hour.
GS1_LINTER_ILLEGAL_MINUTE if the data contains an invalid minute.
54 {
55 
56  size_t len, pos;
57 
58  assert(data);
59 
60  len = strlen(data);
61 
62  /*
63  * Data must be four characters.
64  *
65  */
66  if (len != 4) {
67  if (err_pos) *err_pos = 0;
68  if (err_len) *err_len = len;
70  }
71 
72  /*
73  * Data must consist of all digits.
74  *
75  */
76  if ((pos = strspn(data, "0123456789")) != len) {
77  if (err_pos) *err_pos = pos;
78  if (err_len) *err_len = 1;
80  }
81 
82  /*
83  * Validate the hour.
84  *
85  */
86  if ((data[0] - '0') * 10 + (data[1] - '0') > 23) {
87  if (err_pos) *err_pos = 0;
88  if (err_len) *err_len = 2;
90  }
91 
92  /*
93  * Validate the minute.
94  *
95  */
96  if ((data[2] - '0') * 10 + (data[3] - '0') > 59) {
97  if (err_pos) *err_pos = 2;
98  if (err_len) *err_len = 2;
100  }
101 
102  return GS1_LINTER_OK;
103 
104 }
@ GS1_LINTER_HOUR_WITH_MINUTE_TOO_LONG
The hour with minute is too long for HHMM format.
Definition: gs1syntaxdictionary.h:99
@ GS1_LINTER_ILLEGAL_MINUTE
The time contains an illegal minute.
Definition: gs1syntaxdictionary.h:104
@ GS1_LINTER_ILLEGAL_HOUR
The time contains an illegal hour.
Definition: gs1syntaxdictionary.h:103
@ GS1_LINTER_HOUR_WITH_MINUTE_TOO_SHORT
The hour with minute is too short for HHMM format.
Definition: gs1syntaxdictionary.h:98
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition: gs1syntaxdictionary.h:66
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition: gs1syntaxdictionary.h:67