Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

744 lines
25 KiB

  1. // string standard header
  2. #pragma once
  3. #ifndef _STRING_
  4. #define _STRING_
  5. #include <istream>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. #pragma warning(disable: 4189)
  9. _STD_BEGIN
  10. // basic_string TEMPLATE OPERATORS
  11. template<class _Elem,
  12. class _Traits,
  13. class _Alloc> inline
  14. basic_string<_Elem, _Traits, _Alloc> __cdecl operator+(
  15. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  16. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  17. { // return string + string
  18. return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right);
  19. }
  20. template<class _Elem,
  21. class _Traits,
  22. class _Alloc> inline
  23. basic_string<_Elem, _Traits, _Alloc> __cdecl operator+(
  24. const _Elem *_Left,
  25. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  26. { // return NTCS + string
  27. return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right);
  28. }
  29. template<class _Elem,
  30. class _Traits,
  31. class _Alloc> inline
  32. basic_string<_Elem, _Traits, _Alloc> __cdecl operator+(
  33. const _Elem _Left,
  34. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  35. { // return character + string
  36. return (basic_string<_Elem, _Traits, _Alloc>(1, _Left) += _Right);
  37. }
  38. template<class _Elem,
  39. class _Traits,
  40. class _Alloc> inline
  41. basic_string<_Elem, _Traits, _Alloc> __cdecl operator+(
  42. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  43. const _Elem *_Right)
  44. { // return string + NTCS
  45. return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right);
  46. }
  47. template<class _Elem,
  48. class _Traits,
  49. class _Alloc> inline
  50. basic_string<_Elem, _Traits, _Alloc> __cdecl operator+(
  51. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  52. const _Elem _Right)
  53. { // return string + character
  54. return (basic_string<_Elem, _Traits, _Alloc>(_Left) += _Right);
  55. }
  56. template<class _Elem,
  57. class _Traits,
  58. class _Alloc> inline
  59. bool __cdecl operator==(
  60. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  61. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  62. { // test for string equality
  63. return (_Left.compare(_Right) == 0);
  64. }
  65. template<class _Elem,
  66. class _Traits,
  67. class _Alloc> inline
  68. bool __cdecl operator==(
  69. const _Elem * _Left,
  70. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  71. { // test for NTCS vs. string equality
  72. return (_Right.compare(_Left) == 0);
  73. }
  74. template<class _Elem,
  75. class _Traits,
  76. class _Alloc> inline
  77. bool __cdecl operator==(
  78. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  79. const _Elem *_Right)
  80. { // test for string vs. NTCS equality
  81. return (_Left.compare(_Right) == 0);
  82. }
  83. template<class _Elem,
  84. class _Traits,
  85. class _Alloc> inline
  86. bool __cdecl operator!=(
  87. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  88. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  89. { // test for string inequality
  90. return (!(_Left == _Right));
  91. }
  92. template<class _Elem,
  93. class _Traits,
  94. class _Alloc> inline
  95. bool __cdecl operator!=(
  96. const _Elem *_Left,
  97. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  98. { // test for NTCS vs. string inequality
  99. return (!(_Left == _Right));
  100. }
  101. template<class _Elem,
  102. class _Traits,
  103. class _Alloc> inline
  104. bool __cdecl operator!=(
  105. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  106. const _Elem *_Right)
  107. { // test for string vs. NTCS inequality
  108. return (!(_Left == _Right));
  109. }
  110. template<class _Elem,
  111. class _Traits,
  112. class _Alloc> inline
  113. bool __cdecl operator<(
  114. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  115. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  116. { // test if string < string
  117. return (_Left.compare(_Right) < 0);
  118. }
  119. template<class _Elem,
  120. class _Traits,
  121. class _Alloc> inline
  122. bool __cdecl operator<(
  123. const _Elem * _Left,
  124. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  125. { // test if NTCS < string
  126. return (_Right.compare(_Left) > 0);
  127. }
  128. template<class _Elem,
  129. class _Traits,
  130. class _Alloc> inline
  131. bool __cdecl operator<(
  132. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  133. const _Elem *_Right)
  134. { // test if string < NTCS
  135. return (_Left.compare(_Right) < 0);
  136. }
  137. template<class _Elem,
  138. class _Traits,
  139. class _Alloc> inline
  140. bool __cdecl operator>(
  141. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  142. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  143. { // test if string > string
  144. return (_Right < _Left);
  145. }
  146. template<class _Elem,
  147. class _Traits,
  148. class _Alloc> inline
  149. bool __cdecl operator>(
  150. const _Elem * _Left,
  151. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  152. { // test if NTCS > string
  153. return (_Right < _Left);
  154. }
  155. template<class _Elem,
  156. class _Traits,
  157. class _Alloc> inline
  158. bool __cdecl operator>(
  159. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  160. const _Elem *_Right)
  161. { // test if string > NTCS
  162. return (_Right < _Left);
  163. }
  164. template<class _Elem,
  165. class _Traits,
  166. class _Alloc> inline
  167. bool __cdecl operator<=(
  168. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  169. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  170. { // test if string <= string
  171. return (!(_Right < _Left));
  172. }
  173. template<class _Elem,
  174. class _Traits,
  175. class _Alloc> inline
  176. bool __cdecl operator<=(
  177. const _Elem * _Left,
  178. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  179. { // test if NTCS <= string
  180. return (!(_Right < _Left));
  181. }
  182. template<class _Elem,
  183. class _Traits,
  184. class _Alloc> inline
  185. bool __cdecl operator<=(
  186. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  187. const _Elem *_Right)
  188. { // test if string <= NTCS
  189. return (!(_Right < _Left));
  190. }
  191. template<class _Elem,
  192. class _Traits,
  193. class _Alloc> inline
  194. bool __cdecl operator>=(
  195. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  196. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  197. { // test if string >= string
  198. return (!(_Left < _Right));
  199. }
  200. template<class _Elem,
  201. class _Traits,
  202. class _Alloc> inline
  203. bool __cdecl operator>=(
  204. const _Elem * _Left,
  205. const basic_string<_Elem, _Traits, _Alloc>& _Right)
  206. { // test if NTCS >= string
  207. return (!(_Left < _Right));
  208. }
  209. template<class _Elem,
  210. class _Traits,
  211. class _Alloc> inline
  212. bool __cdecl operator>=(
  213. const basic_string<_Elem, _Traits, _Alloc>& _Left,
  214. const _Elem *_Right)
  215. { // test if string >= NTCS
  216. return (!(_Left < _Right));
  217. }
  218. #ifdef _DLL_CPPLIB
  219. #ifndef CRTDLL2
  220. template class _CRTIMP2 basic_string<char,
  221. char_traits<char>, allocator<char> > __cdecl operator+(
  222. const basic_string<char, char_traits<char>, allocator<char> >&,
  223. const basic_string<char, char_traits<char>, allocator<char> >&);
  224. template class _CRTIMP2 basic_string<char,
  225. char_traits<char>, allocator<char> > __cdecl operator+(
  226. const char *,
  227. const basic_string<char, char_traits<char>, allocator<char> >&);
  228. template class _CRTIMP2 basic_string<char,
  229. char_traits<char>, allocator<char> > __cdecl operator+(
  230. const char,
  231. const basic_string<char, char_traits<char>, allocator<char> >&);
  232. template class _CRTIMP2 basic_string<char,
  233. char_traits<char>, allocator<char> > __cdecl operator+(
  234. const basic_string<char, char_traits<char>, allocator<char> >&,
  235. const char *);
  236. template class _CRTIMP2 basic_string<char,
  237. char_traits<char>, allocator<char> > __cdecl operator+(
  238. const basic_string<char, char_traits<char>, allocator<char> >&,
  239. const char);
  240. template _CRTIMP2 bool __cdecl operator==(
  241. const basic_string<char, char_traits<char>, allocator<char> >&,
  242. const basic_string<char, char_traits<char>, allocator<char> >&);
  243. template _CRTIMP2 bool __cdecl operator==(
  244. const char *,
  245. const basic_string<char, char_traits<char>, allocator<char> >&);
  246. template _CRTIMP2 bool __cdecl operator==(
  247. const basic_string<char, char_traits<char>, allocator<char> >&,
  248. const char *);
  249. template _CRTIMP2 bool __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 bool __cdecl operator!=(
  253. const char *,
  254. const basic_string<char, char_traits<char>, allocator<char> >&);
  255. template _CRTIMP2 bool __cdecl operator!=(
  256. const basic_string<char, char_traits<char>, allocator<char> >&,
  257. const char *);
  258. template _CRTIMP2 bool __cdecl operator<(
  259. const basic_string<char, char_traits<char>, allocator<char> >&,
  260. const basic_string<char, char_traits<char>, allocator<char> >&);
  261. template _CRTIMP2 bool __cdecl operator<(
  262. const char *,
  263. const basic_string<char, char_traits<char>, allocator<char> >&);
  264. template _CRTIMP2 bool __cdecl operator<(
  265. const basic_string<char, char_traits<char>, allocator<char> >&,
  266. const char *);
  267. template _CRTIMP2 bool __cdecl operator>(
  268. const basic_string<char, char_traits<char>, allocator<char> >&,
  269. const basic_string<char, char_traits<char>, allocator<char> >&);
  270. template _CRTIMP2 bool __cdecl operator>(
  271. const char *,
  272. const basic_string<char, char_traits<char>, allocator<char> >&);
  273. template _CRTIMP2 bool __cdecl operator>(
  274. const basic_string<char, char_traits<char>, allocator<char> >&,
  275. const char *);
  276. template _CRTIMP2 bool __cdecl operator<=(
  277. const basic_string<char, char_traits<char>, allocator<char> >&,
  278. const basic_string<char, char_traits<char>, allocator<char> >&);
  279. template _CRTIMP2 bool __cdecl operator<=(
  280. const char *,
  281. const basic_string<char, char_traits<char>, allocator<char> >&);
  282. template _CRTIMP2 bool __cdecl operator<=(
  283. const basic_string<char, char_traits<char>, allocator<char> >&,
  284. const char *);
  285. template _CRTIMP2 bool __cdecl operator>=(
  286. const basic_string<char, char_traits<char>, allocator<char> >&,
  287. const basic_string<char, char_traits<char>, allocator<char> >&);
  288. template _CRTIMP2 bool __cdecl operator>=(
  289. const char *,
  290. const basic_string<char, char_traits<char>, allocator<char> >&);
  291. template _CRTIMP2 bool __cdecl operator>=(
  292. const basic_string<char, char_traits<char>, allocator<char> >&,
  293. const char *);
  294. template class _CRTIMP2 basic_string<wchar_t,
  295. char_traits<wchar_t>, allocator<wchar_t> > __cdecl operator+(
  296. const basic_string<wchar_t, char_traits<wchar_t>,
  297. allocator<wchar_t> >&,
  298. const basic_string<wchar_t, char_traits<wchar_t>,
  299. allocator<wchar_t> >&);
  300. template class _CRTIMP2 basic_string<wchar_t,
  301. char_traits<wchar_t>, allocator<wchar_t> > __cdecl operator+(
  302. const wchar_t *,
  303. const basic_string<wchar_t, char_traits<wchar_t>,
  304. allocator<wchar_t> >&);
  305. template class _CRTIMP2 basic_string<wchar_t,
  306. char_traits<wchar_t>, allocator<wchar_t> > __cdecl operator+(
  307. const wchar_t,
  308. const basic_string<wchar_t, char_traits<wchar_t>,
  309. allocator<wchar_t> >&);
  310. template class _CRTIMP2 basic_string<wchar_t,
  311. char_traits<wchar_t>, allocator<wchar_t> > __cdecl operator+(
  312. const basic_string<wchar_t, char_traits<wchar_t>,
  313. allocator<wchar_t> >&,
  314. const wchar_t *);
  315. template class _CRTIMP2 basic_string<wchar_t,
  316. char_traits<wchar_t>, allocator<wchar_t> > __cdecl operator+(
  317. const basic_string<wchar_t, char_traits<wchar_t>,
  318. allocator<wchar_t> >&,
  319. const wchar_t);
  320. template _CRTIMP2 bool __cdecl operator==(
  321. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  322. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  323. template _CRTIMP2 bool __cdecl operator==(
  324. const wchar_t *,
  325. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  326. template _CRTIMP2 bool __cdecl operator==(
  327. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  328. const wchar_t *);
  329. template _CRTIMP2 bool __cdecl operator!=(
  330. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  331. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  332. template _CRTIMP2 bool __cdecl operator!=(
  333. const wchar_t *,
  334. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  335. template _CRTIMP2 bool __cdecl operator!=(
  336. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  337. const wchar_t *);
  338. template _CRTIMP2 bool __cdecl operator<(
  339. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  340. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  341. template _CRTIMP2 bool __cdecl operator<(
  342. const wchar_t *,
  343. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  344. template _CRTIMP2 bool __cdecl operator<(
  345. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  346. const wchar_t *);
  347. template _CRTIMP2 bool __cdecl operator>(
  348. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  349. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  350. template _CRTIMP2 bool __cdecl operator>(
  351. const wchar_t *,
  352. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  353. template _CRTIMP2 bool __cdecl operator>(
  354. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  355. const wchar_t *);
  356. template _CRTIMP2 bool __cdecl operator<=(
  357. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  358. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  359. template _CRTIMP2 bool __cdecl operator<=(
  360. const wchar_t *,
  361. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  362. template _CRTIMP2 bool __cdecl operator<=(
  363. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  364. const wchar_t *);
  365. template _CRTIMP2 bool __cdecl operator>=(
  366. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  367. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  368. template _CRTIMP2 bool __cdecl operator>=(
  369. const wchar_t *,
  370. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  371. template _CRTIMP2 bool __cdecl operator>=(
  372. const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  373. const wchar_t *);
  374. #ifdef _CRTBLD_NATIVE_WCHAR_T
  375. template class _CRTIMP2 basic_string<unsigned short,
  376. char_traits<unsigned short>, allocator<unsigned short> > __cdecl operator+(
  377. const basic_string<unsigned short, char_traits<unsigned short>,
  378. allocator<unsigned short> >&,
  379. const basic_string<unsigned short, char_traits<unsigned short>,
  380. allocator<unsigned short> >&);
  381. template class _CRTIMP2 basic_string<unsigned short,
  382. char_traits<unsigned short>, allocator<unsigned short> > __cdecl operator+(
  383. const unsigned short *,
  384. const basic_string<unsigned short, char_traits<unsigned short>,
  385. allocator<unsigned short> >&);
  386. template class _CRTIMP2 basic_string<unsigned short,
  387. char_traits<unsigned short>, allocator<unsigned short> > __cdecl operator+(
  388. const unsigned short,
  389. const basic_string<unsigned short, char_traits<unsigned short>,
  390. allocator<unsigned short> >&);
  391. template class _CRTIMP2 basic_string<unsigned short,
  392. char_traits<unsigned short>, allocator<unsigned short> > __cdecl operator+(
  393. const basic_string<unsigned short, char_traits<unsigned short>,
  394. allocator<unsigned short> >&,
  395. const unsigned short *);
  396. template class _CRTIMP2 basic_string<unsigned short,
  397. char_traits<unsigned short>, allocator<unsigned short> > __cdecl operator+(
  398. const basic_string<unsigned short, char_traits<unsigned short>,
  399. allocator<unsigned short> >&,
  400. const unsigned short);
  401. template _CRTIMP2 bool __cdecl operator==(
  402. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  403. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  404. template _CRTIMP2 bool __cdecl operator==(
  405. const unsigned short *,
  406. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  407. template _CRTIMP2 bool __cdecl operator==(
  408. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  409. const unsigned short *);
  410. template _CRTIMP2 bool __cdecl operator!=(
  411. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  412. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  413. template _CRTIMP2 bool __cdecl operator!=(
  414. const unsigned short *,
  415. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  416. template _CRTIMP2 bool __cdecl operator!=(
  417. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  418. const unsigned short *);
  419. template _CRTIMP2 bool __cdecl operator<(
  420. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  421. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  422. template _CRTIMP2 bool __cdecl operator<(
  423. const unsigned short *,
  424. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  425. template _CRTIMP2 bool __cdecl operator<(
  426. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  427. const unsigned short *);
  428. template _CRTIMP2 bool __cdecl operator>(
  429. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  430. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  431. template _CRTIMP2 bool __cdecl operator>(
  432. const unsigned short *,
  433. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  434. template _CRTIMP2 bool __cdecl operator>(
  435. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  436. const unsigned short *);
  437. template _CRTIMP2 bool __cdecl operator<=(
  438. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  439. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  440. template _CRTIMP2 bool __cdecl operator<=(
  441. const unsigned short *,
  442. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  443. template _CRTIMP2 bool __cdecl operator<=(
  444. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  445. const unsigned short *);
  446. template _CRTIMP2 bool __cdecl operator>=(
  447. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  448. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  449. template _CRTIMP2 bool __cdecl operator>=(
  450. const unsigned short *,
  451. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  452. template _CRTIMP2 bool __cdecl operator>=(
  453. const basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  454. const unsigned short *);
  455. #endif
  456. #endif // CRTDLL2
  457. #endif // _DLL_CPPLIB
  458. // basic_string INSERTERS AND EXTRACTORS
  459. template<class _Elem,
  460. class _Traits,
  461. class _Alloc> inline
  462. basic_istream<_Elem, _Traits>& __cdecl operator>>(
  463. basic_istream<_Elem, _Traits>& _Istr,
  464. basic_string<_Elem, _Traits, _Alloc>& _Str)
  465. { // extract a string
  466. typedef ctype<_Elem> _Ctype;
  467. typedef basic_istream<_Elem, _Traits> _Myis;
  468. typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;
  469. typedef typename _Mystr::size_type _Mysizt;
  470. ios_base::iostate _State = ios_base::goodbit;
  471. bool _Changed = false;
  472. const typename _Myis::sentry _Ok(_Istr);
  473. if (_Ok)
  474. { // state okay, extract characters
  475. const _Ctype& _Fac = _USE(_Istr.getloc(), _Ctype);
  476. _Str.erase();
  477. _TRY_IO_BEGIN
  478. _Mysizt _Size = 0 < _Istr.width()
  479. && (_Mysizt)_Istr.width() < _Str.max_size()
  480. ? (_Mysizt)_Istr.width() : _Str.max_size();
  481. typename _Traits::int_type _Meta = _Istr.rdbuf()->sgetc();
  482. for (; 0 < _Size; --_Size, _Meta = _Istr.rdbuf()->snextc())
  483. if(_Traits::eq_int_type(_Traits::eof(), _Meta))
  484. { // end of file, quit
  485. _State |= ios_base::eofbit;
  486. break;
  487. }
  488. else if (_Fac.is(_Ctype::space, _Traits::to_char_type(_Meta)))
  489. break; // whitespace, quit
  490. else
  491. { // add character to string
  492. _Str.append(1, _Traits::to_char_type(_Meta));
  493. _Changed = true;
  494. }
  495. _CATCH_IO_(_Istr)
  496. }
  497. _Istr.width(0);
  498. if (!_Changed)
  499. _State |= ios_base::failbit;
  500. _Istr.setstate(_State);
  501. return (_Istr);
  502. }
  503. template<class _Elem,
  504. class _Traits,
  505. class _Alloc> inline
  506. basic_istream<_Elem, _Traits>& __cdecl getline(
  507. basic_istream<_Elem, _Traits>& _Istr,
  508. basic_string<_Elem, _Traits, _Alloc>& _Str)
  509. { // get characters into string, discard newline
  510. return (getline(_Istr, _Str, _Istr.widen('\n')));
  511. }
  512. template<class _Elem,
  513. class _Traits,
  514. class _Alloc> inline
  515. basic_istream<_Elem, _Traits>& __cdecl getline(
  516. basic_istream<_Elem, _Traits>& _Istr,
  517. basic_string<_Elem, _Traits, _Alloc>& _Str, const _Elem _Delim)
  518. { // get characters into string, discard delimiter
  519. typedef basic_istream<_Elem, _Traits> _Myis;
  520. ios_base::iostate _State = ios_base::goodbit;
  521. bool _Changed = false;
  522. const typename _Myis::sentry _Ok(_Istr, true);
  523. if (_Ok)
  524. { // state okay, extract characters
  525. _TRY_IO_BEGIN
  526. _Str.erase();
  527. const typename _Traits::int_type _Metadelim =
  528. _Traits::to_int_type(_Delim);
  529. typename _Traits::int_type _Meta = _Istr.rdbuf()->sgetc();
  530. for (; ; _Meta = _Istr.rdbuf()->snextc())
  531. if (_Traits::eq_int_type(_Traits::eof(), _Meta))
  532. { // end of file, quit
  533. _State |= ios_base::eofbit;
  534. break;
  535. }
  536. else if (_Traits::eq_int_type(_Meta, _Metadelim))
  537. { // got a delimiter, discard it and quit
  538. _Changed = true;
  539. _Istr.rdbuf()->sbumpc();
  540. break;
  541. }
  542. else if (_Str.max_size() <= _Str.size())
  543. { // string too large, quit
  544. _State |= ios_base::failbit;
  545. break;
  546. }
  547. else
  548. { // got a character, add it to string
  549. _Str += _Traits::to_char_type(_Meta);
  550. _Changed = true;
  551. }
  552. _CATCH_IO_(_Istr)
  553. }
  554. if (!_Changed)
  555. _State |= ios_base::failbit;
  556. _Istr.setstate(_State);
  557. return (_Istr);
  558. }
  559. template<class _Elem,
  560. class _Traits,
  561. class _Alloc> inline
  562. basic_ostream<_Elem, _Traits>& __cdecl operator<<(
  563. basic_ostream<_Elem, _Traits>& _Ostr,
  564. const basic_string<_Elem, _Traits, _Alloc>& _Str)
  565. { // insert a string
  566. typedef basic_ostream<_Elem, _Traits> _Myos;
  567. typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;
  568. typedef typename _Mystr::size_type _Mysizt;
  569. ios_base::iostate _State = ios_base::goodbit;
  570. _Mysizt _Size = _Str.size();
  571. _Mysizt _Pad = _Ostr.width() <= 0 || (_Mysizt)_Ostr.width() <= _Size
  572. ? 0 : (_Mysizt)_Ostr.width() - _Size;
  573. const typename _Myos::sentry _Ok(_Ostr);
  574. if (!_Ok)
  575. _State |= ios_base::badbit;
  576. else
  577. { // state okay, insert characters
  578. _TRY_IO_BEGIN
  579. if ((_Ostr.flags() & ios_base::adjustfield) != ios_base::left)
  580. for (; 0 < _Pad; --_Pad) // pad on left
  581. if (_Traits::eq_int_type(_Traits::eof(),
  582. _Ostr.rdbuf()->sputc(_Ostr.fill())))
  583. { // insertion failed, quit
  584. _State |= ios_base::badbit;
  585. break;
  586. }
  587. if (_State == ios_base::goodbit)
  588. for (_Mysizt _Count = 0; _Count < _Size; ++_Count)
  589. if (_Traits::eq_int_type(_Traits::eof(),
  590. _Ostr.rdbuf()->sputc(_Str[_Count])))
  591. { // insertion failed, quit
  592. _State |= ios_base::badbit;
  593. break;
  594. }
  595. if (_State == ios_base::goodbit)
  596. for (; 0 < _Pad; --_Pad) // pad on right
  597. if (_Traits::eq_int_type(_Traits::eof(),
  598. _Ostr.rdbuf()->sputc(_Ostr.fill())))
  599. { // insertion failed, quit
  600. _State |= ios_base::badbit;
  601. break;
  602. }
  603. _Ostr.width(0);
  604. _CATCH_IO_(_Ostr)
  605. }
  606. _Ostr.setstate(_State);
  607. return (_Ostr);
  608. }
  609. #ifdef _DLL_CPPLIB
  610. #ifndef CRTDLL2
  611. template class _CRTIMP2 basic_istream<char,
  612. char_traits<char> >& __cdecl operator>>(
  613. basic_istream<char, char_traits<char> >&,
  614. basic_string<char, char_traits<char>, allocator<char> >&);
  615. template class _CRTIMP2 basic_istream<char,
  616. char_traits<char> >& __cdecl getline(
  617. basic_istream<char, char_traits<char> >&,
  618. basic_string<char, char_traits<char>, allocator<char> >&);
  619. template class _CRTIMP2 basic_istream<char,
  620. char_traits<char> >& __cdecl getline(
  621. basic_istream<char, char_traits<char> >&,
  622. basic_string<char, char_traits<char>, allocator<char> >&,
  623. const char);
  624. template class _CRTIMP2 basic_ostream<char,
  625. char_traits<char> >& __cdecl operator<<(
  626. basic_ostream<char, char_traits<char> >&,
  627. const basic_string<char, char_traits<char>, allocator<char> >&);
  628. template class _CRTIMP2 basic_istream<wchar_t,
  629. char_traits<wchar_t> >& __cdecl operator>>(
  630. basic_istream<wchar_t, char_traits<wchar_t> >&,
  631. basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  632. template class _CRTIMP2 basic_istream<wchar_t,
  633. char_traits<wchar_t> >& __cdecl getline(
  634. basic_istream<wchar_t, char_traits<wchar_t> >&,
  635. basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&);
  636. template class _CRTIMP2 basic_istream<wchar_t,
  637. char_traits<wchar_t> >& __cdecl getline(
  638. basic_istream<wchar_t, char_traits<wchar_t> >&,
  639. basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >&,
  640. const wchar_t);
  641. template class _CRTIMP2 basic_ostream<wchar_t,
  642. char_traits<wchar_t> >& __cdecl operator<<(
  643. basic_ostream<wchar_t, char_traits<wchar_t> >&,
  644. const basic_string<wchar_t, char_traits<wchar_t>,
  645. allocator<wchar_t> >&);
  646. #ifdef _CRTBLD_NATIVE_WCHAR_T
  647. template class _CRTIMP2 basic_istream<unsigned short,
  648. char_traits<unsigned short> >& __cdecl operator>>(
  649. basic_istream<unsigned short, char_traits<unsigned short> >&,
  650. basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  651. template class _CRTIMP2 basic_istream<unsigned short,
  652. char_traits<unsigned short> >& __cdecl getline(
  653. basic_istream<unsigned short, char_traits<unsigned short> >&,
  654. basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&);
  655. template class _CRTIMP2 basic_istream<unsigned short,
  656. char_traits<unsigned short> >& __cdecl getline(
  657. basic_istream<unsigned short, char_traits<unsigned short> >&,
  658. basic_string<unsigned short, char_traits<unsigned short>, allocator<unsigned short> >&,
  659. const unsigned short);
  660. template class _CRTIMP2 basic_ostream<unsigned short,
  661. char_traits<unsigned short> >& __cdecl operator<<(
  662. basic_ostream<unsigned short, char_traits<unsigned short> >&,
  663. const basic_string<unsigned short, char_traits<unsigned short>,
  664. allocator<unsigned short> >&);
  665. #endif
  666. #endif // CRTDLL2
  667. #endif // _DLL_CPPLIB
  668. _STD_END
  669. #pragma warning(default: 4189)
  670. #pragma warning(pop)
  671. #pragma pack(pop)
  672. #endif /* _STRING */
  673. /*
  674. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  675. * Consult your license regarding permissions and restrictions.
  676. V3.10:0009 */