46 static void binary_read_test();
53 for (tokens=0; !ts.
eof(); tokens++)
54 cout << ts.
get().string() << endl;
55 cout <<
"Total: " << tokens << endl << endl;;
59 int main(
int argc,
char **argv)
70 s =
"This is a test.";
76 s =
"This (is) a test.";
82 s =
"This (is) a test.";
90 s =
"This (is) a test.";
98 s =
"This \"is a\" te\\\"st.";
106 s =
"This \"is a\" te\\\"st.";
134 sprintf(buff,
"a buffer BINARY ");
137 memmove(buff+16,a,
sizeof(
int)*2);
138 sprintf(buff+16+(
sizeof(
int)*2),
" and tokens");
140 if ((fd=fopen(filename,
"w")) ==
NULL)
142 cerr <<
"Token_regression: failed to open " << filename << endl;
146 numbytes = fwrite(buff,1,16+(
sizeof(
int)*2)+11,fd);
153 static void binary_read_test()
169 cout <<
"Reading tokens and binary from string\n";
173 cout << ts.
get() << endl;
174 cout << ts.
get() << endl;
175 if (ts.
get() !=
"BINARY")
177 cout <<
"failed to read binary data, missing BINARY token." << endl;
180 if(ts.
fread(b,
sizeof(
int),2) != 2)
182 cerr <<
"Error reading 2 integers from tokenstream" << endl;
185 cout << b[0] << endl;
186 cout << b[1] << endl;
187 cout << ts.
get() << endl;
188 cout << ts.
get() << endl;
191 cout <<
"Reading tokens and binary from file\n";
193 ts.
open(
"tmp/tokbin.dat");
195 cout << ts.
get() << endl;
196 cout << ts.
get() << endl;
197 if (ts.
get() !=
"BINARY")
199 cout <<
"failed to read binary data, missing BINARY token." << endl;
202 if (ts.
fread(b,
sizeof(
int),2) != 2)
204 cerr <<
"Error reading 2 int from tokenstream" << endl;
207 cout << b[0] << endl;
208 cout << b[1] << endl;
209 cout << ts.
get() << endl;
210 cout << ts.
get() << endl;
EST_TokenStream & get(EST_Token &t)
get next token in stream
int fread(void *buff, int size, int nitems) EST_WARN_UNUSED_RESULT
Reading binary data, (don't use peek() immediately beforehand)
void set_SingleCharSymbols(const EST_String &sc)
set which characters are to be treated as single character symbols
void close(void)
Close stream.
const EST_String EST_Token_Default_PunctuationSymbols
void set_PrePunctuationSymbols(const EST_String &ps)
set which characters are to be treated as (post) punctuation
int open(const EST_String &filename)
open a EST_TokenStream for a file.
int open_string(const EST_String &newbuffer)
open a EST_TokenStream for string rather than a file
void set_PunctuationSymbols(const EST_String &ps)
set which characters are to be treated as (post) punctuation
const EST_String EST_Token_Default_PrePunctuationSymbols
void set_quotes(char q, char e)
set characters to be used as quotes and escape, and set quote mode
int main(int argc, char **argv)
EST_String make_tokbins(const EST_String &filename)
EST_String quote_string(const EST_String &s, const EST_String "e, const EST_String &escape, int force)