source: tests/collections/string-istream.cfa@ b5e725a

stuck-waitfor-destruct
Last change on this file since b5e725a was d32679d5, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

String input operator with chunked memory management.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <iostream.hfa>
2#include <containers/string.hfa>
3#include <containers/string_res.hfa>
4
5
6void istream_cstr(void) {
7 char s1[999], s2[999], s3[999], si[999];
8 sin | wdi(999,s1) | wdi(999,s2) | wdi(999,s3);
9 sout | s1;
10 sout | s2;
11 sout | s3;
12 for(;;) {
13 sin | wdi(999,si);
14 if (si[0] == '=') break;
15 sout | si;
16 }
17}
18
19string accumulator;
20
21void reset_otherStringAction(void) {
22 accumulator = "";
23}
24void step_otherStringAction(void) {
25 string localAction = "--";
26 accumulator += localAction(0,1);
27 sout | accumulator;
28}
29
30void istream_string_res(void) {
31 string_res s1, s2, s3, si;
32 sin | s1 | s2 | s3;
33 sout | s1; step_otherStringAction();
34 sout | s2; step_otherStringAction();
35 sout | s3; step_otherStringAction();
36 for(;;) {
37 sin | si;
38 if (size(si) > 0 && si[0] == '=') break;
39 sout | si; step_otherStringAction();
40 }
41}
42
43void istream_string(void) {
44 string s1, s2, s3, si;
45 sin | s1 | s2 | s3;
46 sout | s1; step_otherStringAction();
47 sout | s2; step_otherStringAction();
48 sout | s3; step_otherStringAction();
49 for(;;) {
50 sin | si;
51 if (size(si) > 0 && si[0] == '=') break;
52 sout | si; step_otherStringAction();
53 }
54}
55
56
57int main() {
58 istream_cstr(); sout | "=";
59 istream_string_res(); sout | "="; reset_otherStringAction();
60 istream_string();
61}
Note: See TracBrowser for help on using the repository browser.