Legofit
infers population history from nucleotide site patterns.
tokenizer.h
Go to the documentation of this file.
1
9#ifndef HAVE_TOKENIZER_H
10#define HAVE_TOKENIZER_H
11#include <stdio.h>
12#include "typedefs.h"
13
14/*
15 * Defined here rather than hidden in tokenizer.c so that tokenizers
16 * can be allocated as automatic variables, i.e. on the stack, rather
17 * than via a call to malloc. This usage looks like:
18 *
19 * Tokenizer tkz;
20 *
21 * Tokenizer_split(&tkz, buff, sep);
22 *
23 * On a 32 bit machine, the max values of ints and longs are the same:
24 * 2.14e9. On a 64 bit machine, ints are the same, but longs are
25 * 9.22e18. I'm using ints here, because I don't think I'll need to
26 * tokenize more than 2.14e9 items.
27 */
28struct Tokenizer {
29 int n; /* number of tokens */
30 int maxTokens; /* maximum number of tokens */
31 char **tokptr; /* array of pointers to tokens */
32};
33
34Tokenizer *Tokenizer_new(int maxtok);
35void Tokenizer_clear(Tokenizer *self);
37int Tokenizer_split(Tokenizer * t, char *buff, const char *sep);
38char *Tokenizer_token(Tokenizer * t, int index);
40int Tokenizer_strip(Tokenizer * t, const char *extraneous);
41int Tokenizer_find(Tokenizer * t, const char *s);
42void Tokenizer_print(const Tokenizer * tkz, FILE * ofp);
43void Tokenizer_printSummary(const Tokenizer * tkz, FILE * ofp);
44#endif
Definition: tokenizer.h:28
void Tokenizer_printSummary(const Tokenizer *tkz, FILE *ofp)
Print a summary of the information in a Tokenizer.
Definition: tokenizer.c:186
int Tokenizer_ntokens(Tokenizer *t)
Return number of tokens.
Definition: tokenizer.c:162
void Tokenizer_print(const Tokenizer *tkz, FILE *ofp)
Print Tokenizer object.
Definition: tokenizer.c:195
int Tokenizer_find(Tokenizer *t, const char *s)
Search for string s among tokens.
Definition: tokenizer.c:173
Tokenizer * Tokenizer_new(int maxtok)
Tokenizer constructor.
Definition: tokenizer.c:48
int Tokenizer_strip(Tokenizer *t, const char *extraneous)
Strip extraneous chars (those list in "extraneous") from both ends of each token.
Definition: tokenizer.c:124
void Tokenizer_free(Tokenizer *t)
Tokenizer destructor.
Definition: tokenizer.c:65
char * Tokenizer_token(Tokenizer *t, int index)
Return pointer to token with given index.
Definition: tokenizer.c:107
int Tokenizer_split(Tokenizer *t, char *buff, const char *sep)
Turn string "buff" into an array of tokens, assuming that tokens in the input string may be separated...
Definition: tokenizer.c:77