Used to ensure that an AI component conforms to a PPTT format, where PP and TT have equal width.
57{
58
59
60#define P(i) data[i]
61#define T(i) data[len / 2 + i]
62
63
64 size_t pos, len, i;
65 int pieceiszero, totaliszero, compare;
66
67 assert(data);
68
69 len = strlen(data);
70
71
72
73
74
75 if (len == 0 || len % 2 != 0)
78 0,
79 len
80 );
81
82
83
84
85
86 if ((pos = strspn(data, "0123456789")) != len)
89 pos,
90 1
91 );
92
93
94
95
96
97
98 pieceiszero = totaliszero = 1;
99 compare = 0;
100 for (i = 0; i < len / 2; i++) {
101 if (pieceiszero && P(i) != '0') pieceiszero = 0;
102 if (totaliszero && T(i) != '0') totaliszero = 0;
103 if (!compare && P(i) != T(i)) compare = P(i) < T(i) ? -1 : 1;
104 }
105
106
107
108
109
110 if (pieceiszero || totaliszero)
113 pieceiszero ? 0 : len / 2,
114 len / 2
115 );
116
117
118
119
120
121 if (compare == 1)
124 0,
125 len
126 );
127
129
130}
#define GS1_LINTER_RETURN_ERROR(error, position, length)
Return from a linter indicating that a problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:77
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:62
@ GS1_LINTER_PIECE_NUMBER_EXCEEDS_TOTAL
The piece number must not exceed the piece total.
Definition gs1syntaxdictionary.h:121
@ GS1_LINTER_ZERO_PIECE_NUMBER
The piece number must not have a value of zero.
Definition gs1syntaxdictionary.h:119
@ GS1_LINTER_INVALID_LENGTH_FOR_PIECE_OF_TOTAL
The piece with total must have an even length, having equal-length components.
Definition gs1syntaxdictionary.h:118
@ GS1_LINTER_ZERO_TOTAL_PIECES
The piece total must not have a value of zero.
Definition gs1syntaxdictionary.h:120
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition gs1syntaxdictionary.h:78