|
|
|
| 1 |
|
// string standard header |
| 2 |
|
#pragma once |
| 3 |
|
#ifndef _STRING_ |
| 4 |
|
#define _STRING_ |
| 5 |
|
#ifndef RC_INVOKED |
| 6 |
|
#include <istream> |
| 7 |
|
|
| 8 |
|
#ifdef _MSC_VER |
| 9 |
|
#pragma pack(push,_CRT_PACKING) |
| 10 |
|
#pragma warning(push,3) |
| 11 |
|
#pragma warning(disable: 4189) |
| 12 |
|
#endif /* _MSC_VER */ |
| 13 |
|
|
| 14 |
|
_STD_BEGIN |
| 15 |
|
|
| 16 |
|
// basic_string TEMPLATE OPERATORS |
| 17 |
|
template<class _Elem, |
| 18 |
|
class _Traits, |
| 19 |
|
class _Alloc> inline |
| 20 |
|
basic_string<_Elem, _Traits, _Alloc> __CLRCALL_OR_CDECL operator+( |
| 21 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 22 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 23 |
|
{ // return string + string |
| 24 |
|
return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right); |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
template<class _Elem, |
| 28 |
|
class _Traits, |
| 29 |
|
class _Alloc> inline |
| 30 |
|
basic_string<_Elem, _Traits, _Alloc> __CLRCALL_OR_CDECL operator+( |
| 31 |
|
const _Elem *_Left, |
| 32 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 33 |
|
{ // return NTCS + string |
| 34 |
|
return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
template<class _Elem, |
| 38 |
|
class _Traits, |
| 39 |
|
class _Alloc> inline |
| 40 |
|
basic_string<_Elem, _Traits, _Alloc> __CLRCALL_OR_CDECL operator+( |
| 41 |
|
const _Elem _Left, |
| 42 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 43 |
|
{ // return character + string |
| 44 |
|
return (basic_string<_Elem, _Traits, _Alloc>(1, _Left) += _Right); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
template<class _Elem, |
| 48 |
|
class _Traits, |
| 49 |
|
class _Alloc> inline |
| 50 |
|
basic_string<_Elem, _Traits, _Alloc> __CLRCALL_OR_CDECL operator+( |
| 51 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 52 |
|
const _Elem *_Right) |
| 53 |
|
{ // return string + NTCS |
| 54 |
|
return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
template<class _Elem, |
| 58 |
|
class _Traits, |
| 59 |
|
class _Alloc> inline |
| 60 |
|
basic_string<_Elem, _Traits, _Alloc> __CLRCALL_OR_CDECL operator+( |
| 61 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 62 |
|
const _Elem _Right) |
| 63 |
|
{ // return string + character |
| 64 |
|
return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
template<class _Elem, |
| 68 |
|
class _Traits, |
| 69 |
|
class _Alloc> inline |
| 70 |
|
bool __CLRCALL_OR_CDECL operator==( |
| 71 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 72 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 73 |
|
{ // test for string equality |
| 74 |
|
return (_Left.compare(_Right) == 0); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
template<class _Elem, |
| 78 |
|
class _Traits, |
| 79 |
|
class _Alloc> inline |
| 80 |
|
bool __CLRCALL_OR_CDECL operator==( |
| 81 |
|
const _Elem * _Left, |
| 82 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 83 |
|
{ // test for NTCS vs. string equality |
| 84 |
|
return (_Right.compare(_Left) == 0); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
template<class _Elem, |
| 88 |
|
class _Traits, |
| 89 |
|
class _Alloc> inline |
| 90 |
|
bool __CLRCALL_OR_CDECL operator==( |
| 91 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 92 |
|
const _Elem *_Right) |
| 93 |
|
{ // test for string vs. NTCS equality |
| 94 |
|
return (_Left.compare(_Right) == 0); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
template<class _Elem, |
| 98 |
|
class _Traits, |
| 99 |
|
class _Alloc> inline |
| 100 |
|
bool __CLRCALL_OR_CDECL operator!=( |
| 101 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 102 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 103 |
|
{ // test for string inequality |
| 104 |
|
return (!(_Left == _Right)); |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
template<class _Elem, |
| 108 |
|
class _Traits, |
| 109 |
|
class _Alloc> inline |
| 110 |
|
bool __CLRCALL_OR_CDECL operator!=( |
| 111 |
|
const _Elem *_Left, |
| 112 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 113 |
|
{ // test for NTCS vs. string inequality |
| 114 |
|
return (!(_Left == _Right)); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
template<class _Elem, |
| 118 |
|
class _Traits, |
| 119 |
|
class _Alloc> inline |
| 120 |
|
bool __CLRCALL_OR_CDECL operator!=( |
| 121 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 122 |
|
const _Elem *_Right) |
| 123 |
|
{ // test for string vs. NTCS inequality |
| 124 |
|
return (!(_Left == _Right)); |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
template<class _Elem, |
| 128 |
|
class _Traits, |
| 129 |
|
class _Alloc> inline |
| 130 |
|
bool __CLRCALL_OR_CDECL operator<( |
| 131 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 132 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 133 |
|
{ // test if string < string |
| 134 |
|
return (_Left.compare(_Right) < 0); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
template<class _Elem, |
| 138 |
|
class _Traits, |
| 139 |
|
class _Alloc> inline |
| 140 |
|
bool __CLRCALL_OR_CDECL operator<( |
| 141 |
|
const _Elem * _Left, |
| 142 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 143 |
|
{ // test if NTCS < string |
| 144 |
|
return (_Right.compare(_Left) > 0); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
template<class _Elem, |
| 148 |
|
class _Traits, |
| 149 |
|
class _Alloc> inline |
| 150 |
|
bool __CLRCALL_OR_CDECL operator<( |
| 151 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 152 |
|
const _Elem *_Right) |
| 153 |
|
{ // test if string < NTCS |
| 154 |
|
return (_Left.compare(_Right) < 0); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
template<class _Elem, |
| 158 |
|
class _Traits, |
| 159 |
|
class _Alloc> inline |
| 160 |
|
bool __CLRCALL_OR_CDECL operator>( |
| 161 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 162 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 163 |
|
{ // test if string > string |
| 164 |
|
return (_Right < _Left); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
template<class _Elem, |
| 168 |
|
class _Traits, |
| 169 |
|
class _Alloc> inline |
| 170 |
|
bool __CLRCALL_OR_CDECL operator>( |
| 171 |
|
const _Elem * _Left, |
| 172 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 173 |
|
{ // test if NTCS > string |
| 174 |
|
return (_Right < _Left); |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
template<class _Elem, |
| 178 |
|
class _Traits, |
| 179 |
|
class _Alloc> inline |
| 180 |
|
bool __CLRCALL_OR_CDECL operator>( |
| 181 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 182 |
|
const _Elem *_Right) |
| 183 |
|
{ // test if string > NTCS |
| 184 |
|
return (_Right < _Left); |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
template<class _Elem, |
| 188 |
|
class _Traits, |
| 189 |
|
class _Alloc> inline |
| 190 |
|
bool __CLRCALL_OR_CDECL operator<=( |
| 191 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 192 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 193 |
|
{ // test if string <= string |
| 194 |
|
return (!(_Right < _Left)); |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
template<class _Elem, |
| 198 |
|
class _Traits, |
| 199 |
|
class _Alloc> inline |
| 200 |
|
bool __CLRCALL_OR_CDECL operator<=( |
| 201 |
|
const _Elem * _Left, |
| 202 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 203 |
|
{ // test if NTCS <= string |
| 204 |
|
return (!(_Right < _Left)); |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
template<class _Elem, |
| 208 |
|
class _Traits, |
| 209 |
|
class _Alloc> inline |
| 210 |
|
bool __CLRCALL_OR_CDECL operator<=( |
| 211 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 212 |
|
const _Elem *_Right) |
| 213 |
|
{ // test if string <= NTCS |
| 214 |
|
return (!(_Right < _Left)); |
| 215 |
|
} |
| 216 |
|
|
| 217 |
|
template<class _Elem, |
| 218 |
|
class _Traits, |
| 219 |
|
class _Alloc> inline |
| 220 |
|
bool __CLRCALL_OR_CDECL operator>=( |
| 221 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 222 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 223 |
|
{ // test if string >= string |
| 224 |
|
return (!(_Left < _Right)); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
template<class _Elem, |
| 228 |
|
class _Traits, |
| 229 |
|
class _Alloc> inline |
| 230 |
|
bool __CLRCALL_OR_CDECL operator>=( |
| 231 |
|
const _Elem * _Left, |
| 232 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Right) |
| 233 |
|
{ // test if NTCS >= string |
| 234 |
|
return (!(_Left < _Right)); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
template<class _Elem, |
| 238 |
|
class _Traits, |
| 239 |
|
class _Alloc> inline |
| 240 |
|
bool __CLRCALL_OR_CDECL operator>=( |
| 241 |
|
const basic_string<_Elem, _Traits, _Alloc>& _Left, |
| 242 |
|
const _Elem *_Right) |
| 243 |
|
{ // test if string >= NTCS |
| 244 |
|
return (!(_Left < _Right)); |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
| 248 |
|
template _CRTIMP2_PURE basic_string<char, |
| 249 |
|
char_traits<char>, allocator<char> > __CLRCALL_OR_CDECL operator+( |
| 250 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 251 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 252 |
|
template _CRTIMP2_PURE basic_string<char, |
| 253 |
|
char_traits<char>, allocator<char> > __CLRCALL_OR_CDECL operator+( |
| 254 |
|
const char *, |
| 255 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 256 |
|
template _CRTIMP2_PURE basic_string<char, |
| 257 |
|
char_traits<char>, allocator<char> > __CLRCALL_OR_CDECL operator+( |
| 258 |
|
const char, |
| 259 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 260 |
|
template _CRTIMP2_PURE basic_string<char, |
| 261 |
|
char_traits<char>, allocator<char> > __CLRCALL_OR_CDECL operator+( |
| 262 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 263 |
|
const char *); |
| 264 |
|
template _CRTIMP2_PURE basic_string<char, |
| 265 |
|
char_traits<char>, allocator<char> > __CLRCALL_OR_CDECL operator+( |
| 266 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 267 |
|
const char); |
| 268 |
|
|
| 269 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator==( |
| 270 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 271 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 272 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator==( |
| 273 |
|
const char *, |
| 274 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 275 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator==( |
| 276 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 277 |
|
const char *); |
| 278 |
|
|
| 279 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator!=( |
| 280 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 281 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 282 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator!=( |
| 283 |
|
const char *, |
| 284 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 285 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator!=( |
| 286 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 287 |
|
const char *); |
| 288 |
|
|
| 289 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator<( |
| 290 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 291 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 292 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator<( |
| 293 |
|
const char *, |
| 294 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 295 |
|
template _CRTIMP2_PURE bool __CLRCALL_OR_CDECL operator<( |
| 296 |
|
const basic_string<char, char_traits<char>, allocator<char> >&, |
| 297 |
|
const char *); |
| 541 |
|
typedef basic_ostream<_Elem, _Traits> _Myos; |
| 542 |
|
typedef basic_string<_Elem, _Traits, _Alloc> _Mystr; |
| 543 |
|
typedef typename _Mystr::size_type _Mysizt; |
| 544 |
|
|
| 545 |
|
ios_base::iostate _State = ios_base::goodbit; |
| 546 |
|
_Mysizt _Size = _Str.size(); |
| 547 |
|
_Mysizt _Pad = _Ostr.width() <= 0 || (_Mysizt)_Ostr.width() <= _Size |
| 548 |
|
? 0 : (_Mysizt)_Ostr.width() - _Size; |
| 549 |
|
const typename _Myos::sentry _Ok(_Ostr); |
| 550 |
|
|
| 551 |
|
if (!_Ok) |
| 552 |
|
_State |= ios_base::badbit; |
| 553 |
|
else |
| 554 |
|
{ // state okay, insert characters |
| 555 |
|
_TRY_IO_BEGIN |
| 556 |
|
if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left) |
| 557 |
|
for (; 0 < _Pad; --_Pad) // pad on left |
| 558 |
|
if (_Traits::eq_int_type(_Traits::eof(), |
| 559 |
|
_Ostr.rdbuf()->sputc(_Ostr.fill()))) |
| 560 |
|
{ // insertion failed, quit |
| 561 |
|
_State |= ios_base::badbit; |
| 562 |
|
break; |
| 563 |
|
} |
| 564 |
|
|
| 565 |
|
if (_State == ios_base::goodbit) |
| 566 |
|
for (_Mysizt _Count = 0; _Count < _Size; ++_Count) |
| 567 |
|
if (_Traits::eq_int_type(_Traits::eof(), |
| 568 |
|
_Ostr.rdbuf()->sputc(_Str[_Count]))) |
| 569 |
|
{ // insertion failed, quit |
| 570 |
|
_State |= ios_base::badbit; |
| 571 |
|
break; |
| 572 |
|
} |
| 573 |
|
|
| 574 |
|
if (_State == ios_base::goodbit) |
| 575 |
|
for (; 0 < _Pad; --_Pad) // pad on right |
| 576 |
|
if (_Traits::eq_int_type(_Traits::eof(), |
| 577 |
|
_Ostr.rdbuf()->sputc(_Ostr.fill()))) |
| 578 |
|
{ // insertion failed, quit |
| 579 |
|
_State |= ios_base::badbit; |
| 580 |
|
break; |
| 581 |
|
} |
| 582 |
|
_Ostr.width(0); |
| 583 |
|
_CATCH_IO_(_Ostr) |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
_Ostr.setstate(_State); |
| 587 |
|
return (_Ostr); |
| 588 |
|
} |
| 589 |
|
|
| 590 |
|
#ifdef _DLL_CPPLIB |
| 591 |
|
template _CRTIMP2_PURE basic_istream<char, |
| 592 |
|
char_traits<char> >& __CLRCALL_OR_CDECL operator>>( |
| 593 |
|
basic_istream<char, char_traits<char> >&, |
| 594 |
|
basic_string<char, char_traits<char>, allocator<char> >&); |
| 595 |
|
template _CRTIMP2_PURE basic_istream<char, |
| 596 |
|
char_traits<char> >& __CLRCALL_OR_CDECL getline( |
| 597 |
|
basic_istream<char, char_traits<char> >&, |
| 598 |
|
basic_string<char, char_traits<char>, allocator<char> >&); |
| 599 |
|
template _CRTIMP2_PURE basic_istream<char, |
| 600 |
|
char_traits<char> >& __CLRCALL_OR_CDECL getline( |
| 601 |
|
basic_istream<char, char_traits<char> >&, |
| 602 |
|
basic_string<char, char_traits<char>, allocator<char> >&, |
| 603 |
|
const char); |
| 604 |
|
template _CRTIMP2_PURE basic_ostream<char, |
| 605 |
|
char_traits<char> >& __CLRCALL_OR_CDECL operator<<( |
| 606 |
|
basic_ostream<char, char_traits<char> >&, |
| 607 |
|
const basic_string<char, char_traits<char>, allocator<char> >&); |
| 608 |
|
|
| 609 |
|
template _CRTIMP2_PURE basic_istream<wchar_t, |
| 610 |
|
char_traits<wchar_t> >& __CLRCALL_OR_CDECL operator>>( |
| 611 |
|
basic_istream<wchar_t, char_traits<wchar_t> >&, |
| 612 |
|
basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&); |
| 613 |
|
template _CRTIMP2_PURE basic_istream<wchar_t, |
| 614 |
|
char_traits<wchar_t> >& __CLRCALL_OR_CDECL getline( |
| 615 |
|
basic_istream<wchar_t, char_traits<wchar_t> >&, |
| 616 |
|
basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&); |
| 617 |
|
template _CRTIMP2_PURE basic_istream<wchar_t, |
| 618 |
|
char_traits<wchar_t> >& __CLRCALL_OR_CDECL getline( |
| 619 |
|
basic_istream<wchar_t, char_traits<wchar_t> >&, |
| 620 |
|
basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&, |
| 621 |
|
const wchar_t); |
| 622 |
|
template _CRTIMP2_PURE basic_ostream<wchar_t, |
| 623 |
|
char_traits<wchar_t> >& __CLRCALL_OR_CDECL operator<<( |
| 624 |
|
basic_ostream<wchar_t, char_traits<wchar_t> >&, |
| 625 |
|
const basic_string<wchar_t, char_traits<wchar_t>, |
| 626 |
|
allocator<wchar_t> >&); |
| 627 |
|
|
| 628 |
|
|
| 629 |
|
|
| 630 |
|
#endif /* _DLL_CPPLIB */ |
| 631 |
|
_STD_END |
| 632 |
|
|
| 633 |
|
#ifdef _MSC_VER |
| 634 |
|
#pragma warning(default: 4189) |
| 635 |
|
#pragma warning(pop) |
| 636 |
|
#pragma pack(pop) |
| 637 |
|
#endif /* _MSC_VER */ |
| 638 |
|
|
| 639 |
|
#endif /* RC_INVOKED */ |
| 640 |
|
#endif /* _STRING */ |
| 641 |
|
|
| 642 |
|
/* |
| 643 |
|
* Copyright (c) 1992-2006 by P.J. Plauger. ALL RIGHTS RESERVED. |
| 644 |
|
* Consult your license regarding permissions and restrictions. |
| 645 |
|
V5.02:0009 */ |
| 646 |
|
|
|
|
|