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_latitude.c File Reference

Purpose

The latitude linter ensures that the given data represents the latitude component of a WGS84 coordinate expressed as a 10-digit number.

Functional Description

◆ gs1_lint_latitude()

GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_latitude ( 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 represents the latitude component of a WGS84 coordinate expressed as a 10-digit number.

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_LATITUDE_INVALID_LENGTH if the latitude does not have length 10.
GS1_LINTER_INVALID_LATITUDE if the latitude is outside the range 0000000000 - 1800000000.
51{
52
53 size_t pos;
54 unsigned long value;
55
56 assert(data);
57
58 /*
59 * Data must be 10 characters.
60 *
61 */
62 if (GS1_LINTER_UNLIKELY(data_len != 10))
65 0,
66 data_len
67 );
68
69 /*
70 * Data must consist of all digits and latitude must be within
71 * 0000000000 to 1800000000.
72 *
73 */
74 for (pos = 0, value = 0; pos < data_len; pos++) {
75 if (GS1_LINTER_UNLIKELY(data[pos] < '0' || data[pos] > '9'))
78 pos,
79 1
80 );
81 value = value * 10 + (unsigned long)(data[pos] - '0');
82 }
83
84 if (GS1_LINTER_UNLIKELY(value > 1800000000))
87 0,
88 10
89 );
90
92
93}
#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_LATITUDE_INVALID_LENGTH
The latitude value must be 10 digits.
Definition gs1syntaxdictionary.h:183
@ GS1_LINTER_INVALID_LATITUDE
The latitude is outside of the range "0000000000" to "1800000000".
Definition gs1syntaxdictionary.h:180
@ GS1_LINTER_NON_DIGIT_CHARACTER
A non-digit character was found where a digit is expected.
Definition gs1syntaxdictionary.h:78