]> www.ginac.de Git - cln.git/blob - src/base/string/input/cl_st_get1.cc
697a72fc1944dc611180896167b662d0a0f7a7f5
[cln.git] / src / base / string / input / cl_st_get1.cc
1 // cl_fget().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_string.h"
8
9
10 // Implementation.
11
12 #ifdef CL_IO_IOSTREAM
13
14 #include "cl_io.h"
15 #include "cl_spushstring.h"
16
17 #if ((defined(__sparc__) || defined(__rs6000__) || defined(__mips__)) && !defined(__GNUC__))
18 // Sun C++ doesn't have istream::unget().
19   #define unget()  putback(c)
20 #endif
21
22 const cl_string cl_fget (cl_istream stream, char delim)
23 {
24         var cl_spushstring buffer;
25         // Handling of eofp is tricky: EOF is reached when (!stream.good()) || (stream.get()==EOF).
26         while (stream.good()) {
27                 var int c = stream.get();
28                 if (c==EOF)
29                         break;  // ios::eofbit already set
30                 if (c==delim) {
31                         stream.unget();
32                         break;
33                 }
34                 buffer.push(c);
35         }
36         return buffer.contents();
37 }
38
39 #endif