home *** CD-ROM | disk | FTP | other *** search
-
- #include <iostream.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <limits.h>
-
- #include "NString.h"
-
- //_________________________________________________________________________________
-
- ostream& operator<<(ostream& theStream, const NString& theString)
- {
- return (theStream << theString.sb->str);
- }
-
- //_________________________________________________________________________________
-
- istream& operator>>(istream& theStream, NString& theString)
- {
- if (! theStream) // if the stream is not in good state, abort
- return theStream;
-
- char c;
-
- theString = "";
-
- while (theStream.get(c)) // eat whitespace and NUL chars
- if ((! isspace(c)) && (c != '\0'))
- {
- theStream.putback(c);
- break;
- }
-
- while ((theStream.peek() != EOF) && theStream.get(c))
- if (isspace(c) || (c == '\0'))
- {
- theStream.putback(c); // a NUL or a whitespace character: put it back and abort
- break;
- }
- else
- theString += c; // a plain, good character: add it to the string
-
- return theStream;
- }
-
- //_________________________________________________________________________________
-
- istream& get (istream& theStream, NString& theString,
- const unsigned long int maxLength, const char terminator)
- {
- if (! theStream) // if the stream is not in good state, abort
- return theStream;
-
- char c;
- const unsigned long int maxlen = (maxLength ? maxLength : ULONG_MAX);
-
- theString = "";
-
- while (theStream.get(c)) // eat NUL chars
- if (c != '\0')
- {
- theStream.putback(c);
- break;
- }
-
- while ((theStream.peek() != EOF) && (theString.sb->len < maxlen) && theStream.get(c))
- if ((c == '\0') || (c == terminator))
- {
- theStream.putback(c); // a NUL character: put it back and abort
- break;
- }
- else
- theString += c; // a plain, good character: add it to the string
-
- return theStream;
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const unsigned long int n)
- {
- char text[50];
-
- sprintf(text, "%lu", n);
- return (*this += text);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const signed long int n)
- {
- char text[50];
-
- sprintf(text, "%ld", n);
- return (*this += text);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const unsigned short int n)
- {
- char text[50];
-
- sprintf(text, "%hu", n);
- return (*this += text);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const signed short int n)
- {
- char text[50];
-
- sprintf(text, "%hd", n);
- return (*this += text);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const double n)
- {
- char text[50];
-
- sprintf(text, "%.12lf", n);
- return (*this += text);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const float n)
- {
- char text[50];
-
- sprintf(text, "%.6f", n);
- return (*this += text);
- }
-
- //_________________________________________________________________________________
-
- NString& NString::operator<< (const void *p)
- {
- char text[50];
-
- sprintf(text, "%p", p);
- return (*this += text);
- }
-