GS1 Barcode Syntax Tests reference
A reference to the AI component "linter" routines referred to by the GS1 Barcode Syntax Dictionary. Copyright (c) 2022-2024 GS1 AISBL.
lint_iso5218.c File Reference

Purpose

The iso5218 linter ensures that the given data represents a ISO/IEC 5218 biological sex code, either "0" (not known), "1" (male), "2" (female) or "9" (not applicable).

Remarks
The biological sex codes are defined by ISO/IEC 5218: Information technology - Codes for the representation of human sexes.

Functional Description

◆ gs1_lint_iso5218()

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

Used to validate that an AI component is the string "0", "1", "2" or "9".

Parameters
[in]dataPointer to the data to be linted. Must not be NULL.
[in]data_lenLength of the data to be linted.
[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_BIOLOGICAL_SEX_CODE if the data is not "0", "1", "2" or "9".
53{
54
55 assert(data);
56
57
58 /*
59 * The data must be either "0", "1", "2" or "9".
60 *
61 */
62 if (GS1_LINTER_UNLIKELY(data_len != 1))
65 0,
66 data_len
67 );
68
70 data[0] != '0' && data[0] != '1' && data[0] != '2' && data[0] != '9'
71 )
72 )
75 0,
76 1
77 );
78
80
81}
#define GS1_LINTER_UNLIKELY(x)
Implementation may provide hint to the compiler that the expression is likely to be false.
Definition gs1syntaxdictionary-utils.h:76
#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:103
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:88
@ GS1_LINTER_INVALID_BIOLOGICAL_SEX_CODE
A valid ISO/IEC 5218 biological sex code required.
Definition gs1syntaxdictionary.h:188