suplibxx  1.3.9
example_getrecord.cc
1 // --8<--8<--8<--8<--
2 //
3 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
4 //
5 // This file is part of suplibxx
6 //
7 // suplibxx is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // suplibxx is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the
19 // Free Software Foundation, Inc.
20 // 51 Franklin Street, Fifth Floor
21 // Boston, MA 02110-1301, USA
22 //
23 // -->8-->8-->8-->8--
24 
25 #include <iostream>
26 #include <string>
27 #include <strstream>
28 using namespace std;
29 
30 #include "io.h"
31 
32 int main( int argc, char** argv ) {
33 
34  string expected;
35  string returned;
36 
37  {
38  // Example 1
39  strstream strstr;
40  strstr << " now, is, the, time ";
41  expected = " now, is, the, time ";
42  suplib::getrecord( strstr, returned, suplib::READ_PHYS );
43  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
44  }
45 
46  {
47  // Example 2
48  strstream strstr;
49  strstr << " now, is, the, time \n";
50  expected = " now, is, the, time";
51  suplib::getrecord( strstr, returned, suplib::READ_PHYS | suplib::STRIP );
52  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
53  }
54 
55  {
56  // Example 3
57  strstream strstr;
58  strstr << " now, is, the, time \\ \n"
59  << " now, is, the, time \\ \n"
60  << " now, is, the, time ";
61  expected = " now, is, the, time ";
62  expected += " now, is, the, time ";
63  expected += " now, is, the, time ";
64  suplib::getrecord( strstr, returned, suplib::READ_LOGICAL );
65  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
66  }
67 
68  {
69  // Example 4
70  strstream strstr;
71  strstr << " now, is, the, time \\ \n"
72  << " now, is, the, time \\ \n"
73  << " now, is, the, time ";
74  expected = " now, is, the, time \\\n";
75  expected += " now, is, the, time \\\n";
76  expected += " now, is, the, time ";
78  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
79  }
80 
81  {
82  // Example 5
83  strstream strstr;
84  strstr << " now, is, the, time \n";
85  expected = " now, is, the, time";
87  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
88  }
89 
90  {
91  // Example 6
92  strstream strstr;
93  strstr << " now, is, the, time \\ \n"
94  << " now, is, the, time \\ \n"
95  << " now, is, the, time ";
96  expected = " now, is, the, time ";
97  expected += " now, is, the, time ";
98  expected += " now, is, the, time";
100  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
101  }
102 
103  {
104  // Example 7
105  strstream strstr;
106  strstr << " now, is, the, time \\ \n"
107  << " now, is, the, time \\ \n"
108  << " now, is, the, time ";
109  expected = " now, is, the, time \\\n";
110  expected += " now, is, the, time \\\n";
111  expected += " now, is, the, time";
113  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
114  }
115 
116  {
117  // Example 8
118  strstream strstr;
119  strstr << " now, is, the, time - \n"
120  << " now, is, the, time - \n"
121  << " now, is, the, time ";
122  expected = " now, is, the, time ";
123  expected += " now, is, the, time ";
124  expected += " now, is, the, time ";
125  suplib::getrecord( strstr, returned, suplib::READ_LOGICAL, '\n', '-' );
126  cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
127  }
128 
129  return 0;
130 }
istream & getrecord(istream &is, string &str, int opt=READ_PHYS, char delim='\n', char continuation='\\')
Reads physical and logical lines.
Definition: getrecord.cc:60