Skip to content

Commit 2a6fcb6

Browse files
Update README examples
1 parent 7a8fe40 commit 2a6fcb6

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ And an example with the C API:
211211

212212
int main(int argc, char **argv) {
213213
// Setup (only called once at the beginning of your program)
214-
if (!libpostal_setup() || !libpostal_setup_parser()) {
214+
libpostal_t *instance = libpostal_setup();
215+
address_parser_t *parser = libpostal_setup_parser();
216+
if (instance == NULL || parser == NULL) {
215217
exit(EXIT_FAILURE);
216218
}
217219

218220
libpostal_address_parser_options_t options = libpostal_get_address_parser_default_options();
219-
libpostal_address_parser_response_t *parsed = libpostal_parse_address("781 Franklin Ave Crown Heights Brooklyn NYC NY 11216 USA", options);
221+
libpostal_address_parser_response_t *parsed = libpostal_parse_address(parser, instance, "781 Franklin Ave Crown Heights Brooklyn NYC NY 11216 USA", options);
220222

221223
for (size_t i = 0; i < parsed->num_components; i++) {
222224
printf("%s: %s\n", parsed->labels[i], parsed->components[i]);
@@ -226,8 +228,8 @@ int main(int argc, char **argv) {
226228
libpostal_address_parser_response_destroy(parsed);
227229

228230
// Teardown (only called once at the end of your program)
229-
libpostal_teardown();
230-
libpostal_teardown_parser();
231+
libpostal_teardown(&instance);
232+
libpostal_teardown_parser(&parser);
231233
}
232234
```
233235
@@ -308,13 +310,15 @@ The C API equivalent is a few more lines, but still fairly simple:
308310

309311
int main(int argc, char **argv) {
310312
// Setup (only called once at the beginning of your program)
311-
if (!libpostal_setup() || !libpostal_setup_language_classifier()) {
313+
libpostal_t *instance = libpostal_setup();
314+
language_classifier_t *classifier = libpostal_setup_language_classifier();
315+
if (instance == NULL || classifier == NULL) {
312316
exit(EXIT_FAILURE);
313317
}
314318

315319
size_t num_expansions;
316320
libpostal_normalize_options_t options = libpostal_get_default_options();
317-
char **expansions = libpostal_expand_address("Quatre-vingt-douze Ave des Champs-Élysées", options, &num_expansions);
321+
char **expansions = libpostal_expand_address(classifier, instance, "Quatre-vingt-douze Ave des Champs-Élysées", options, &num_expansions);
318322

319323
for (size_t i = 0; i < num_expansions; i++) {
320324
printf("%s\n", expansions[i]);
@@ -324,8 +328,8 @@ int main(int argc, char **argv) {
324328
libpostal_expansion_array_destroy(expansions, num_expansions);
325329

326330
// Teardown (only called once at the end of your program)
327-
libpostal_teardown();
328-
libpostal_teardown_language_classifier();
331+
libpostal_teardown(&instance);
332+
libpostal_teardown_language_classifier(&classifier);
329333
}
330334
```
331335
@@ -625,7 +629,7 @@ libpostal is written in modern, legible, C99 and uses the following conventions:
625629
- Generic containers (via [klib](https://github.com/attractivechaos/klib)) whenever possible
626630
- Data structrues take advantage of sparsity as much as possible
627631
- Efficient double-array trie implementation for most string dictionaries
628-
- Cross-platform as much as possible, particularly for *nix
632+
- Cross-platform as much as possible, particularly for \*nix
629633
630634
Preprocessing (Python)
631635
----------------------

0 commit comments

Comments
 (0)