Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / kwsys_stl_string.hxx.in
blob8334328a38a9705d2427ea2336fd9957721be36d
1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: kwsys_stl_string.hxx.in,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
15 // This header is extra code for <@KWSYS_NAMESPACE@/stl/string>.
16 #if !defined(@KWSYS_NAMESPACE@_stl_string_including_hxx)
17 # error "The header <@KWSYS_NAMESPACE@/stl/string.hxx> may be included only by <@KWSYS_NAMESPACE@/stl/string>."
18 #endif
20 // Provide the istream operator for the stl string if it is not
21 // provided by the system or another copy of kwsys. Allow user code
22 // to block this definition by defining the macro
23 // @KWSYS_NAMESPACE@_STL_STRING_NO_ISTREAM
24 // to avoid conflicts with other libraries. User code can test for
25 // this definition by checking the macro
26 // @KWSYS_NAMESPACE@_STL_STRING_ISTREAM_DEFINED
27 #if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_ISTREAM && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_ISTREAM) && !defined(KWSYS_STL_STRING_ISTREAM_DEFINED)
28 # define KWSYS_STL_STRING_ISTREAM_DEFINED
29 # define @KWSYS_NAMESPACE@_STL_STRING_ISTREAM_DEFINED
30 # include <ctype.h> // isspace
31 # include <@KWSYS_NAMESPACE@/ios/iostream>
32 # if defined(__WATCOMC__)
33 namespace @KWSYS_NAMESPACE@
35 struct ios_istream_hack: public kwsys_ios::istream
36 { void eatwhite() { this->@KWSYS_NAMESPACE@_ios::istream::eatwhite(); } };
38 # endif
39 inline @KWSYS_NAMESPACE@_ios::istream&
40 operator>>(@KWSYS_NAMESPACE@_ios::istream& is,
41 @KWSYS_NAMESPACE@_stl::string& s)
43 // Keep track of the resulting state.
44 int state = @KWSYS_NAMESPACE@_ios::ios::goodbit;
46 // Save the width setting and set it back to zero.
47 size_t n = static_cast<size_t>(is.width(0));
49 // Clear any old contents of the output string.
50 s.erase();
52 // Skip leading whitespace.
53 #if defined(__WATCOMC__)
54 static_cast<@KWSYS_NAMESPACE@::ios_istream_hack&>(is).eatwhite();
55 #else
56 is.eatwhite();
57 #endif
58 @KWSYS_NAMESPACE@_ios::istream& okay = is;
60 if(okay)
62 // Select a maximum possible length.
63 if(n == 0 || n >= s.max_size())
65 n = s.max_size();
68 // Read until a space is found or the maximum length is reached.
69 bool success = false;
70 for(int c = is.peek(); (--n > 0 && c != EOF && !isspace(c)); c = is.peek())
72 s += static_cast<char>(c);
73 success = true;
74 is.ignore();
77 // Set flags for resulting state.
78 if(is.peek() == EOF) { state |= @KWSYS_NAMESPACE@_ios::ios::eofbit; }
79 if(!success) { state |= @KWSYS_NAMESPACE@_ios::ios::failbit; }
82 // Set the final result state.
83 is.clear(state);
84 return is;
86 #endif
88 // Provide the ostream operator for the stl string if it is not
89 // provided by the system or another copy of kwsys. Allow user code
90 // to block this definition by defining the macro
91 // @KWSYS_NAMESPACE@_STL_STRING_NO_OSTREAM
92 // to avoid conflicts with other libraries. User code can test for
93 // this definition by checking the macro
94 // @KWSYS_NAMESPACE@_STL_STRING_OSTREAM_DEFINED
95 #if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_OSTREAM) && !defined(KWSYS_STL_STRING_OSTREAM_DEFINED)
96 # define KWSYS_STL_STRING_OSTREAM_DEFINED
97 # define @KWSYS_NAMESPACE@_STL_STRING_OSTREAM_DEFINED
98 # include <@KWSYS_NAMESPACE@/ios/iostream>
99 inline @KWSYS_NAMESPACE@_ios::ostream&
100 operator<<(@KWSYS_NAMESPACE@_ios::ostream& os,
101 @KWSYS_NAMESPACE@_stl::string const& s)
103 return os << s.c_str();
105 #endif
107 // Provide the operator!= for the stl string and char* if it is not
108 // provided by the system or another copy of kwsys. Allow user code
109 // to block this definition by defining the macro
110 // @KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR
111 // to avoid conflicts with other libraries. User code can test for
112 // this definition by checking the macro
113 // @KWSYS_NAMESPACE@_STL_STRING_NEQ_CHAR_DEFINED
114 #if !@KWSYS_NAMESPACE@_STL_STRING_HAVE_NEQ_CHAR && !defined(@KWSYS_NAMESPACE@_STL_STRING_NO_NEQ_CHAR) && !defined(KWSYS_STL_STRING_NEQ_CHAR_DEFINED)
115 # define KWSYS_STL_STRING_NEQ_CHAR_DEFINED
116 # define @KWSYS_NAMESPACE@_STL_STRING_NEQ_CHAR_DEFINED
117 inline bool operator!=(@KWSYS_NAMESPACE@_stl::string const& s, const char* c)
119 return !(s == c);
121 inline bool operator!=(const char* c, @KWSYS_NAMESPACE@_stl::string const& s)
123 return !(s == c);
125 #endif