2005-03-29 17:20:08 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: KWSys - Kitware System Library
|
|
|
|
Module: $RCSfile$
|
|
|
|
|
|
|
|
Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
|
|
|
|
// This header is extra code for <@KWSYS_NAMESPACE@/stl/string>.
|
|
|
|
#if !defined(@KWSYS_NAMESPACE@_stl_string_including_hxx)
|
|
|
|
# error "The header <@KWSYS_NAMESPACE@/stl/string.hxx> may be included only by <@KWSYS_NAMESPACE@/stl/string>."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Provide the istream operator for the stl string if it is not
|
|
|
|
// provided by the system or another copy of kwsys. Allow user code
|
|
|
|
// to block this definition by defining the macro
|
|
|
|
// @KWSYS_NAMESPACE@_STL_STRING_NO_ISTREAM
|
2005-04-07 00:14:29 +04:00
|
|
|
// to avoid conflicts with other libraries. User code can test for
|
|
|
|
// this definition by checking the macro
|
|
|
|
// @KWSYS_NAMESPACE@_STL_STRING_ISTREAM_DEFINED
|
2005-04-22 19:57:59 +04:00
|
|
|
#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_ISTREAM) && !defined(KWSYS_STL_STRING_ISTREAM_DEFINED)
|
2005-03-29 17:20:08 +04:00
|
|
|
# define KWSYS_STL_STRING_ISTREAM_DEFINED
|
2005-04-07 00:14:29 +04:00
|
|
|
# define @KWSYS_NAMESPACE@_STL_STRING_ISTREAM_DEFINED
|
2005-03-29 17:20:08 +04:00
|
|
|
# include <ctype.h> // isspace
|
|
|
|
# include <@KWSYS_NAMESPACE@/ios/iostream>
|
2007-04-19 19:21:35 +04:00
|
|
|
# if defined(__WATCOMC__)
|
|
|
|
namespace @KWSYS_NAMESPACE@
|
|
|
|
{
|
|
|
|
struct ios_istream_hack: public kwsys_ios::istream
|
|
|
|
{ void eatwhite() { this->@KWSYS_NAMESPACE@_ios::istream::eatwhite(); } };
|
|
|
|
}
|
|
|
|
# endif
|
2005-03-29 17:20:08 +04:00
|
|
|
inline @KWSYS_NAMESPACE@_ios::istream&
|
|
|
|
operator>>(@KWSYS_NAMESPACE@_ios::istream& is,
|
|
|
|
@KWSYS_NAMESPACE@_stl::string& s)
|
|
|
|
{
|
|
|
|
// Keep track of the resulting state.
|
|
|
|
int state = @KWSYS_NAMESPACE@_ios::ios::goodbit;
|
|
|
|
|
|
|
|
// Save the width setting and set it back to zero.
|
|
|
|
size_t n = static_cast<size_t>(is.width(0));
|
|
|
|
|
|
|
|
// Clear any old contents of the output string.
|
|
|
|
s.erase();
|
|
|
|
|
|
|
|
// Skip leading whitespace.
|
2007-04-19 19:21:35 +04:00
|
|
|
#if defined(__WATCOMC__)
|
|
|
|
static_cast<@KWSYS_NAMESPACE@::ios_istream_hack&>(is).eatwhite();
|
|
|
|
#else
|
2005-03-29 17:20:08 +04:00
|
|
|
is.eatwhite();
|
2007-04-19 19:21:35 +04:00
|
|
|
#endif
|
|
|
|
@KWSYS_NAMESPACE@_ios::istream& okay = is;
|
2005-03-29 17:20:08 +04:00
|
|
|
|
|
|
|
if(okay)
|
|
|
|
{
|
|
|
|
// Select a maximum possible length.
|
|
|
|
if(n == 0 || n >= s.max_size())
|
|
|
|
{
|
|
|
|
n = s.max_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read until a space is found or the maximum length is reached.
|
|
|
|
bool success = false;
|
|
|
|
for(int c = is.peek(); (--n > 0 && c != EOF && !isspace(c)); c = is.peek())
|
|
|
|
{
|
|
|
|
s += static_cast<char>(c);
|
|
|
|
success = true;
|
|
|
|
is.ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set flags for resulting state.
|
|
|
|
if(is.peek() == EOF) { state |= @KWSYS_NAMESPACE@_ios::ios::eofbit; }
|
2007-04-19 20:44:04 +04:00
|
|
|
if(!success) { state |= @KWSYS_NAMESPACE@_ios::ios::failbit; }
|
2005-03-29 17:20:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the final result state.
|
|
|
|
is.clear(state);
|
|
|
|
return is;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Provide the ostream operator for the stl string if it is not
|
|
|
|
// provided by the system or another copy of kwsys. Allow user code
|
|
|
|
// to block this definition by defining the macro
|
|
|
|
// @KWSYS_NAMESPACE@_STL_STRING_NO_OSTREAM
|
2005-04-07 00:14:29 +04:00
|
|
|
// to avoid conflicts with other libraries. User code can test for
|
|
|
|
// this definition by checking the macro
|
|
|
|
// @KWSYS_NAMESPACE@_STL_STRING_OSTREAM_DEFINED
|
2005-04-22 19:57:59 +04:00
|
|
|
#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_OSTREAM) && !defined(KWSYS_STL_STRING_OSTREAM_DEFINED)
|
2005-03-29 17:20:08 +04:00
|
|
|
# define KWSYS_STL_STRING_OSTREAM_DEFINED
|
2005-04-07 00:14:29 +04:00
|
|
|
# define @KWSYS_NAMESPACE@_STL_STRING_OSTREAM_DEFINED
|
2005-03-29 17:20:08 +04:00
|
|
|
# include <@KWSYS_NAMESPACE@/ios/iostream>
|
|
|
|
inline @KWSYS_NAMESPACE@_ios::ostream&
|
|
|
|
operator<<(@KWSYS_NAMESPACE@_ios::ostream& os,
|
|
|
|
@KWSYS_NAMESPACE@_stl::string const& s)
|
|
|
|
{
|
|
|
|
return os << s.c_str();
|
|
|
|
}
|
|
|
|
#endif
|
2005-03-29 19:10:25 +04:00
|
|
|
|
|
|
|
// Provide the operator!= for the stl string and char* if it is not
|
|
|
|
// provided by the system or another copy of kwsys. Allow user code
|
|
|
|
// to block this definition by defining the macro
|
|
|
|
// @KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR
|
2005-04-07 00:14:29 +04:00
|
|
|
// to avoid conflicts with other libraries. User code can test for
|
|
|
|
// this definition by checking the macro
|
|
|
|
// @KWSYS_NAMESPACE@_STL_STRING_NEQ_CHAR_DEFINED
|
2005-04-22 19:57:59 +04:00
|
|
|
#if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR) && !defined(KWSYS_STL_STRING_NEQ_CHAR_DEFINED)
|
2005-03-29 19:10:25 +04:00
|
|
|
# define KWSYS_STL_STRING_NEQ_CHAR_DEFINED
|
2005-04-07 00:14:29 +04:00
|
|
|
# define @KWSYS_NAMESPACE@_STL_STRING_NEQ_CHAR_DEFINED
|
2005-03-29 19:10:25 +04:00
|
|
|
inline bool operator!=(@KWSYS_NAMESPACE@_stl::string const& s, const char* c)
|
|
|
|
{
|
|
|
|
return !(s == c);
|
|
|
|
}
|
|
|
|
inline bool operator!=(const char* c, @KWSYS_NAMESPACE@_stl::string const& s)
|
|
|
|
{
|
|
|
|
return !(s == c);
|
|
|
|
}
|
|
|
|
#endif
|