Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 1.33 KB

README.md

File metadata and controls

37 lines (26 loc) · 1.33 KB

MRZ Parser for C/C++

Single-file header library to parse a Machine Readable Zone (Type 1, 2 and 3, MRV A and B, France ID and Swiss driver license).

How to use

Before you include the header file in one C or C++ file, you need to define MRZ_PARSER_IMPLEMENTATION to create the implementation:

#define MRZ_PARSER_IMPLEMENTATION
#include "mrzparser.h"

How to parse a MRZ

Then invoke parse_mrz() with a MRZ (the string may contain white space and/or line breaks):

MRZ mrz;
if (!parse_mrz(&mrz, "I<UTOERIKSSON<<ANNA<MARIA<<<<…")) {
	fprintf(stderr, "error: %s\n", mrz.error);
}

Now the structure mrz holds the parsed values from the MRZ:

printf("document number: %s\n", mrz.document_number);

If parse_mrz() was unsuccessful (returned 0), mrz may still contain some data depending on the nature of the error. It is guaranteed that all members of the mrz struct are always null-terminated even in case of an error.