home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / STRING.H < prev    next >
C/C++ Source or Header  |  1997-01-16  |  81KB  |  2,125 lines

  1. /*  string.h
  2.  
  3.     Definitions for memory and string functions.
  4.  
  5. */
  6.  
  7. /*
  8.  *      C/C++ Run Time Library - Version 8.0
  9.  *
  10.  *      Copyright (c) 1987, 1997 by Borland International
  11.  *      All Rights Reserved.
  12.  *
  13.  */
  14. /* $Revision:   8.15  $ */
  15.  
  16. #if !defined(__USING_STD_NAMES__)
  17.  
  18. #ifndef __STRING_H
  19. #define __STRING_H
  20.  
  21. #if !defined(___DEFS_H)
  22. #include <_defs.h>
  23. #endif
  24.  
  25. #ifndef __STDDEF_H
  26. #include <stddef.h>
  27. #endif
  28.  
  29. #if !defined(NULL)
  30. #include <_null.h>
  31. #endif
  32.  
  33. #if !defined(__STDC__) && defined(__USELOCALES__)
  34. #if !defined(__LOCALE_H)
  35. #include <locale.h>
  36. #endif
  37. #endif  /* !__STDC__ && __USELOCALES__ */
  38.  
  39. #if !defined(RC_INVOKED)
  40.  
  41. #if defined(__STDC__)
  42. #pragma warn -nak
  43. #endif
  44.  
  45. #endif  /* !RC_INVOKED */
  46.  
  47.  
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51.  
  52.  
  53. #ifndef _SIZE_T
  54. #define _SIZE_T
  55. typedef unsigned size_t;
  56. #endif
  57.  
  58. #define wcscmpi(s1,s2)      _wcsicmp(s1,s2)
  59. #define _wcscmpi(s1,s2)     _wcsicmp(s1,s2)
  60. #define wcsncmpi(s1,s2,n)   _wcsnicmp(s1,s2,n)
  61. #define _wcsncmpi(s1,s2,n)  _wcsnicmp(s1,s2,n)
  62.  
  63. size_t          _RTLENTRY  _EXPFUNC wcslen(const wchar_t *__s);
  64. wchar_t *       _RTLENTRY  _EXPFUNC wcscpy(wchar_t *__dst, const wchar_t *__src);
  65. wchar_t *       _RTLENTRY  _EXPFUNC wcscat(wchar_t *__dest, const wchar_t *__src);
  66. wchar_t *       _RTLENTRY  _EXPFUNC wcschr(const wchar_t *__s, int __c);
  67. int             _RTLENTRY  _EXPFUNC wcscmp(const wchar_t *__s1, const wchar_t *__s2);
  68. int             _RTLENTRY  _EXPFUNC wcscoll(const wchar_t * __s1, const wchar_t * __s2);
  69. size_t          _RTLENTRY  _EXPFUNC wcscspn(const wchar_t *__s1, const wchar_t *__s2);
  70. wchar_t *       _RTLENTRY  _EXPFUNC _wcsdup(const wchar_t *__s);
  71. int             _RTLENTRY  _EXPFUNC wcsncmp(const wchar_t *__s1, const wchar_t *__s2, size_t __maxlen);
  72. wchar_t *       _RTLENTRY  _EXPFUNC wcsncpy(wchar_t *__dest, const wchar_t *__src, size_t __maxlen);
  73. wchar_t *       _RTLENTRY  _EXPFUNC _wcsnset(wchar_t *__s, wchar_t __ch, size_t __n);
  74. wchar_t *       _RTLENTRY  _EXPFUNC wcspbrk(const wchar_t *__s1, const wchar_t *__s2);
  75. wchar_t *       _RTLENTRY  _EXPFUNC wcsrchr(const wchar_t *__s, wchar_t __c);
  76. wchar_t *       _RTLENTRY  _EXPFUNC _wcsrev(wchar_t *__s);
  77. wchar_t *       _RTLENTRY  _EXPFUNC _wcsset(wchar_t*__s, wchar_t __ch);
  78. size_t          _RTLENTRY  _EXPFUNC wcsspn(const wchar_t *__s1, const wchar_t *__s2);
  79. wchar_t *       _RTLENTRY  _EXPFUNC wcsstr(const wchar_t *__s1, const wchar_t *__s2);
  80. wchar_t *       _RTLENTRY  _EXPFUNC wcstok(wchar_t *__s1, const wchar_t *__s2);
  81. wchar_t *       _RTLENTRY  _EXPFUNC wcsncat(wchar_t *__dest, const wchar_t *__src, size_t __maxlen);
  82. wchar_t *       _RTLENTRY  _EXPFUNC wcspcpy(wchar_t *__dest, const wchar_t *__src);
  83. wchar_t *       _RTLENTRY  _EXPFUNC _wcspcpy(wchar_t *__dest, const wchar_t *__src);
  84. int             _RTLENTRY  _EXPFUNC wcsicmp(const wchar_t *__s1, const wchar_t *__s2);
  85. int             _RTLENTRY  _EXPFUNC _wcsicmp(const wchar_t *__s1, const wchar_t *__s2);
  86. int             _RTLENTRY  _EXPFUNC _wcsnicmp(const wchar_t *__s1, const wchar_t *__s2, size_t __maxlen);
  87. void *          _RTLENTRY  _EXPFUNC _wmemset(void *__s, int __c, size_t __n);
  88. wchar_t *       _RTLENTRYF _EXPFUNC _wcslwr(wchar_t *__s);
  89. wchar_t *       _RTLENTRYF _EXPFUNC _wcsupr(wchar_t *__s);
  90. wchar_t *       _RTLENTRYF _EXPFUNC _lwcslwr(wchar_t *__s);
  91. wchar_t *       _RTLENTRYF _EXPFUNC _lwcsupr(wchar_t *__s);
  92. void *          _RTLENTRY  _EXPFUNC _wmemcpy(void *__dest, const void *__src, size_t __n);
  93.  
  94. int         _RTLENTRY  _EXPFUNC memcmp(const void _FAR *__s1,
  95.                                        const void _FAR *__s2, size_t __n);
  96. void _FAR * _RTLENTRY  _EXPFUNC memcpy(void _FAR *__dest, const void _FAR *__src,
  97.                                        size_t __n);
  98. void _FAR * _RTLENTRYF _EXPFUNC memmove(void _FAR *__dest, const void _FAR *__src,
  99.                                         size_t __n);
  100. void _FAR * _RTLENTRYF _EXPFUNC memset(void _FAR *__s, int __c, size_t __n);
  101. char _FAR * _RTLENTRYF _EXPFUNC strcat(char _FAR *__dest, const char _FAR *__src);
  102. int         _RTLENTRYF _EXPFUNC strcmp(const char _FAR *__s1, const char _FAR *__s2);
  103. char _FAR * _RTLENTRYF _EXPFUNC strcpy(char _FAR *__dest, const char _FAR *__src);
  104. size_t      _RTLENTRY  _EXPFUNC strcspn(const char _FAR *__s1, const char _FAR *__s2);
  105. char _FAR * _RTLENTRY  _EXPFUNC strerror(int __errnum);
  106. size_t      _RTLENTRYF _EXPFUNC strlen(const char _FAR *__s);
  107. char _FAR * _RTLENTRYF _EXPFUNC strncat(char _FAR *__dest, const char _FAR *__src,
  108.                                         size_t __maxlen);
  109. int         _RTLENTRYF _EXPFUNC strncmp(const char _FAR *__s1, const char _FAR *__s2,
  110.                                         size_t __maxlen);
  111. char _FAR * _RTLENTRYF _EXPFUNC strncpy(char _FAR *__dest, const char _FAR *__src,
  112.                                         size_t __maxlen);
  113. size_t      _RTLENTRY  _EXPFUNC strspn(const char _FAR *__s1, const char _FAR *__s2);
  114. char _FAR * _RTLENTRYF _EXPFUNC strtok(char _FAR *__s1, const char _FAR *__s2);
  115. char _FAR * _RTLENTRY  _EXPFUNC _strerror(const char _FAR *__s);
  116.  
  117.  
  118. #if !defined(__STDC__)
  119. /* compatibility with other compilers */
  120. #define strcmpi(s1,s2)      stricmp(s1,s2)
  121. #define strncmpi(s1,s2,n)   strnicmp(s1,s2,n)
  122.  
  123. char _FAR * _RTLENTRYF _EXPFUNC   _lstrlwr(char _FAR *__s);
  124. char _FAR * _RTLENTRYF _EXPFUNC   _lstrupr(char _FAR *__s);
  125. void _FAR * _RTLENTRY  _EXPFUNC   memccpy(void _FAR *__dest, const void _FAR *__src,
  126.                                           int __c, size_t __n);
  127. int         _RTLENTRY  _EXPFUNC   memicmp(const void _FAR *__s1, const void _FAR *__s2,
  128.                                           size_t __n);
  129. char _FAR * _RTLENTRYF _EXPFUNC32 stpcpy(char _FAR *__dest, const char _FAR *__src);
  130. char _FAR * _RTLENTRY  _EXPFUNC32 _stpcpy(char _FAR *__dest, const char _FAR *__src);
  131. char _FAR * _RTLENTRY  _EXPFUNC   strdup(const char _FAR *__s);
  132. int         _RTLENTRYF _EXPFUNC   stricmp(const char _FAR *__s1, const char _FAR *__s2);
  133. char _FAR * _RTLENTRYF _EXPFUNC   strlwr(char _FAR *__s);
  134. int         _RTLENTRYF _EXPFUNC   strnicmp(const char _FAR *__s1, const char _FAR *__s2,
  135.                                            size_t __maxlen);
  136. char _FAR * _RTLENTRY  _EXPFUNC   strnset(char _FAR *__s, int __ch, size_t __n);
  137. char _FAR * _RTLENTRY  _EXPFUNC   strrev(char _FAR *__s);
  138. char _FAR * _RTLENTRY  _EXPFUNC   strset(char _FAR *__s, int __ch);
  139. char _FAR * _RTLENTRYF _EXPFUNC   strupr(char _FAR *__s);
  140. #endif  /* !__STDC__ */
  141.  
  142.  
  143. #if defined(__cplusplus)
  144. extern "C++"
  145. {
  146.           void _FAR * _RTLENTRY  _EXPFUNC32 memchr(void _FAR *__s, int __c, size_t __n);
  147.     const void _FAR * _RTLENTRY  _EXPFUNC32 memchr(const void _FAR *__s, int __c, size_t __n);
  148. #if defined(__FLAT__)
  149.           void      * _RTLENTRY  _EXPFUNC32 _wmemchr(void *__s, int __c, size_t __n);
  150.     const void      * _RTLENTRY  _EXPFUNC32 _wmemchr(const void *__s, int __c, size_t __n);
  151. #endif
  152.           char _FAR * _RTLENTRYF _EXPFUNC   strchr(char _FAR * __s, int __c);
  153.     const char _FAR * _RTLENTRYF _EXPFUNC   strchr(const char _FAR * __s, int __c);
  154.           char _FAR * _RTLENTRYF _EXPFUNC   strrchr(char _FAR *__s, int __c);
  155.     const char _FAR * _RTLENTRYF _EXPFUNC   strrchr(const char _FAR *__s, int __c);
  156.           char _FAR * _RTLENTRYF _EXPFUNC   strpbrk(char _FAR *__s1, const char _FAR *__s2);
  157.     const char _FAR * _RTLENTRYF _EXPFUNC   strpbrk(const char _FAR *__s1, const char _FAR *__s2);
  158.           char _FAR * _RTLENTRY  _EXPFUNC   strstr(char _FAR *__s1, const char _FAR *__s2);
  159.     const char _FAR * _RTLENTRY  _EXPFUNC   strstr(const char _FAR *__s1, const char _FAR *__s2);
  160. }
  161. #else
  162.           void _FAR * _RTLENTRY  _EXPFUNC32 memchr(const void _FAR *__s, int __c, size_t __n);
  163. #if defined(__FLAT__)
  164.           void      * _RTLENTRY  _EXPFUNC32 _wmemchr(const void *__s, int __c, size_t __n);
  165. #endif
  166.           char _FAR * _RTLENTRYF _EXPFUNC   strchr(const char _FAR * __s, int __c);
  167.           char _FAR * _RTLENTRYF _EXPFUNC   strrchr(const char _FAR *__s, int __c);
  168.           char _FAR * _RTLENTRYF _EXPFUNC   strpbrk(const char _FAR *__s1, const char _FAR *__s2);
  169.           char _FAR * _RTLENTRY  _EXPFUNC   strstr(const char _FAR *__s1, const char _FAR *__s2);
  170. #endif
  171.  
  172.  
  173. /* Intrinsic functions */
  174. #if !defined(__MEM_H)
  175. void _FAR * _RTLENTRY  _EXPFUNC16 __memchr__(const void _FAR *__s, int __c, size_t __n);
  176. int         _RTLENTRY  _EXPFUNC16 __memcmp__(const void _FAR *__s1,
  177.                                              const void _FAR *__s2, size_t __n);
  178. void _FAR * _RTLENTRY  _EXPFUNC16 __memcpy__(void _FAR *__dest, const void _FAR *__src,
  179.                                              size_t __n);
  180. void _FAR * _RTLENTRYF _EXPFUNC16 __memset__(void _FAR *__s, int __c, size_t __n);
  181. #endif
  182.  
  183. char _FAR * _RTLENTRY             __stpcpy__(char _FAR *__dest, const char _FAR *__src);
  184. char _FAR * _RTLENTRYF _EXPFUNC16 __strcat__(char _FAR *__dest, const char _FAR *__src);
  185. char _FAR * _RTLENTRY  _EXPFUNC16 __strchr__(const char _FAR *__s, int __c);
  186. int         _RTLENTRYF _EXPFUNC16 __strcmp__(const char _FAR *__s1, const char _FAR *__s2);
  187. char _FAR * _RTLENTRYF _EXPFUNC16 __strcpy__(char _FAR *__dest, const char _FAR *__src);
  188. size_t      _RTLENTRYF _EXPFUNC16 __strlen__(const char _FAR *__s);
  189. char _FAR * _RTLENTRY  _EXPFUNC16 __strncat__(char _FAR *__dest, const char _FAR *__src,
  190.                                               size_t __maxlen);
  191. int         _RTLENTRY  _EXPFUNC16 __strncmp__(const char _FAR *__s1, const char _FAR *__s2,
  192.                                               size_t __maxlen);
  193. char _FAR * _RTLENTRYF _EXPFUNC16 __strncpy__(char _FAR *__dest, const char _FAR *__src,
  194.                                               size_t __maxlen);
  195. char _FAR * _RTLENTRY  _EXPFUNC16 __strnset__(char _FAR *__s, int __ch, size_t __n);
  196. char _FAR * _RTLENTRYF _EXPFUNC16 __strrchr__(const char _FAR *__s, int __c);
  197. char _FAR * _RTLENTRY  _EXPFUNC16 __strset__(char _FAR *__s, int __ch);
  198.  
  199. #if defined(__MSC) && !defined(__MFC_COMPAT__)
  200. #define _stricmp(s1,s2) stricmp(s1,s2)
  201. #define _strdup(s1)     strdup(s1)
  202. #define _strupr(s1)     strupr(s1)
  203. #define _strlwr(s1)     strlwr(s1)
  204. #define _strrev(s1)     strrev(s1)
  205. #endif  /* __MSC */
  206.  
  207. #if defined(__MFC_COMPAT__)
  208. inline char _FAR * _RTLENTRY  _strrev(char _FAR *__s) { return strrev(__s); }
  209.  
  210. inline char _FAR * _RTLENTRY  _strset(char _FAR *__s, int __ch)
  211.                               { return strset(__s, __ch); }
  212. inline char _FAR * _RTLENTRY  _strnset(char _FAR *__s, int __ch, size_t __n)
  213.                               { return strnset(__s, __ch, __n); }
  214. inline char _FAR * _RTLENTRYF _strupr(char _FAR *__s) { return strupr(__s); }
  215.  
  216. inline char _FAR * _RTLENTRYF _strlwr(char _FAR *__s) { return strlwr(__s); }
  217.  
  218. inline char _FAR * _RTLENTRY  _strdup(const char _FAR *__s)
  219.                               { return strdup(__s); }
  220. inline int         _RTLENTRYF _strcmpi(const char _FAR *__s1, const char _FAR *__s2)
  221.                               { return stricmp (__s1, __s2); }
  222. inline int         _RTLENTRYF _stricmp(const char _FAR *__s1, const char _FAR *__s2)
  223.                               { return stricmp (__s1, __s2); }
  224. inline int         _RTLENTRYF _strcmp(const char _FAR *__s1, const char _FAR *__s2)
  225.                               { return strcmp (__s1, __s2); }
  226. inline int         _RTLENTRYF _strnicmp(const char _FAR *__s1, const char _FAR *__s2, size_t __maxlen)
  227.                               { return strnicmp (__s1, __s2, __maxlen); }
  228. #endif
  229.  
  230. #if !defined(__FLAT__) || defined(__DPMI32__)
  231. void        _RTLENTRY  _EXPFUNC movedata(unsigned __srcseg,unsigned __srcoff,
  232.                                          unsigned __dstseg,unsigned __dstoff, size_t __n);
  233. #endif
  234.  
  235.  
  236. #if !defined(__FLAT__)
  237. int           _RTLENTRYF _EXPFUNC _lstrcoll(const char _FAR *__s1, const char _FAR *__s2);
  238. size_t        _RTLENTRYF _EXPFUNC _lstrxfrm(char _FAR *__s1, const char _FAR *__s2,
  239.                                             size_t __n );
  240. int           _RTLENTRYF          strcoll(const char _FAR *__s1, const char _FAR *__s2);
  241. size_t        _RTLENTRYF          strxfrm(char _FAR *__s1, const char _FAR *__s2,
  242.                                           size_t __n );
  243.  
  244. #if !defined(__STDC__)
  245. void  __far * _RTLENTRY _FARCALL  _fmemccpy(void __far *__dest, const void __far *__src,
  246.                                             int c, size_t __n);
  247. void  __far * _RTLENTRY _FARCALL  _fmemchr(const void __far *__s, int c, size_t __n);
  248. int           _RTLENTRY _FARCALL  _fmemcmp(const void __far *__s1, const void __far *__s2,
  249.                                            size_t __n);
  250. void  __far * _RTLENTRY _FARCALL  _fmemcpy(void __far *__dest, const void __far *__src,
  251.                                            size_t __n);
  252. int           _RTLENTRY _FARCALL  _fmemicmp(const void __far *__s1, const void __far *__s2,
  253.                                             size_t __n);
  254. void  __far * _RTLENTRY _FARCALL  _fmemmove(void __far *__dest, const void __far *__src,
  255.                                             size_t __n);
  256. void  __far * _RTLENTRY _FARCALL  _fmemset(void __far *__s, int c, size_t __n);
  257. void          _RTLENTRY _FARCALL  _fmovmem(const void __far *__src, void __far *__dest,
  258.                                            unsigned __length);
  259. void          _RTLENTRY _FARCALL  _fsetmem(void __far *__dest,unsigned __length,
  260.                                            char __value);
  261. char  __far * _RTLENTRY _FARCALL  _fstrcat(char __far *__dest, const char __far *__src);
  262. char  __far * _RTLENTRY _FARCALL  _fstrchr(const char __far *__s, int c);
  263. int           _RTLENTRY _FARCALL  _fstrcmp(const char __far *__s1, const char __far *__s2);
  264. char  __far * _RTLENTRY _FARCALL  _fstrcpy(char __far *__dest, const char __far *__src);
  265. size_t        _RTLENTRY _FARCALL  _fstrcspn(const char __far *__s1, const char __far *__s2);
  266. char  __far * _RTLENTRY _FARCALL  _fstrdup(const char __far *__s);
  267. int           _RTLENTRY _FARCALL  _fstricmp(const char __far *__s1, const char __far *__s2);
  268. size_t        _RTLENTRY _FARCALL  _fstrlen(const char __far *__s);
  269. char  __far * _RTLENTRY _FARCALL  _fstrlwr(char __far *__s);
  270. char  __far * _RTLENTRY _FARCALL  _fstrncat(char __far *__dest, const char __far *__src,
  271.                                             size_t maxlen);
  272. int           _RTLENTRY _FARCALL  _fstrncmp(const char __far *__s1, const char __far *__s2,
  273.                                             size_t maxlen);
  274. char  __far * _RTLENTRY _FARCALL  _fstrncpy(char __far *__dest, const char __far *__src,
  275.                                             size_t maxlen);
  276. int           _RTLENTRY _FARCALL  _fstrnicmp(const char __far *__s1, const char __far *__s2,
  277.                                              size_t maxlen);
  278. char  __far * _RTLENTRY _FARCALL  _fstrnset(char __far *__s, int ch, size_t __n);
  279. char  __far * _RTLENTRY _FARCALL  _fstrpbrk(const char __far *__s1, const char __far *__s2);
  280. char  __far * _RTLENTRY _FARCALL  _fstrrchr(const char __far *__s, int c);
  281. char  __far * _RTLENTRY _FARCALL  _fstrrev(char __far *__s);
  282. char  __far * _RTLENTRY _FARCALL  _fstrset(char __far *__s, int ch);
  283. size_t        _RTLENTRY _FARCALL  _fstrspn(const char __far *__s1, const char __far *__s2);
  284. char  __far * _RTLENTRY _FARCALL  _fstrstr(const char __far *__s1, const char __far *__s2);
  285. char  __far * _RTLENTRY _FARCALL  _fstrtok(char __far *__s1, const char __far *__s2);
  286. char  __far * _RTLENTRY _FARCALL  _fstrupr(char __far *__s);
  287. #endif  /* ! __STDC__ */
  288.  
  289.  
  290. #else    /* defined __FLAT__ */
  291.  
  292.  
  293. int    _RTLENTRY  _EXPFUNC _lstrcoll(const char * __s1, const char * __s2);
  294. int    _RTLENTRY  _EXPFUNC _lstricoll(const char * __s1, const char * __s2);
  295. int    _RTLENTRY  _EXPFUNC _lstrncoll(const char * __s1, const char * __s2, const int len);
  296. int    _RTLENTRY  _EXPFUNC _lstrnicoll(const char * __s1, const char * __s2, int len);
  297. size_t _RTLENTRY  _EXPFUNC _lstrxfrm(char * __s1, const char * __s2,size_t __n );
  298. int    _RTLENTRY  _EXPFUNC strcoll(const char * __s1, const char * __s2);
  299. int    _RTLENTRY  _EXPFUNC _stricoll(const char * __s1, const char * __s2);
  300. int    _RTLENTRY  _EXPFUNC _strncoll(const char * __s1, const char * __s2, size_t __n);
  301. int    _RTLENTRY  _EXPFUNC _strnicoll(const char * __s1, const char * __s2, int len);
  302. size_t _RTLENTRY  _EXPFUNC strxfrm(char * __s1, const char * __s2,size_t __n );
  303.  
  304. int    _RTLENTRY  _EXPFUNC _lwcscoll(const wchar_t * __s1, const wchar_t * __s2);
  305. int    _RTLENTRY  _EXPFUNC _lwcsicoll(const wchar_t * __s1, const wchar_t * __s2);
  306. int    _RTLENTRY  _EXPFUNC _lwcsncoll(const wchar_t * __s1, const wchar_t * __s2, const int len);
  307. int    _RTLENTRY  _EXPFUNC _lwcsnicoll(const wchar_t * __s1, const wchar_t * __s2, int len);
  308. size_t _RTLENTRY  _EXPFUNC _lwcsxfrm(wchar_t * __s1, const wchar_t * __s2,size_t __n );
  309. int    _RTLENTRY  _EXPFUNC wcscoll(const wchar_t * __s1, const wchar_t * __s2);
  310. int    _RTLENTRY  _EXPFUNC _wcsicoll(const wchar_t * __s1, const wchar_t * __s2);
  311. int    _RTLENTRY  _EXPFUNC _wcsncoll(const wchar_t * __s1, const wchar_t * __s2, size_t __n);
  312. int    _RTLENTRY  _EXPFUNC _wcsnicoll(const wchar_t * __s1, const wchar_t * __s2, int len);
  313. size_t _RTLENTRY  _EXPFUNC wcsxfrm(wchar_t * __s1, const wchar_t * __s2, size_t __n );
  314.  
  315.  
  316. #if !defined(__STDC__) /* NON_ANSI  */
  317. #define _fmemccpy  memccpy
  318. #define _fmemchr   memchr
  319. #define _fmemcmp   memcmp
  320. #define _fmemcpy   memcpy
  321. #define _fmemicmp  memicmp
  322. #define _fmemmove  memmove
  323. #define _fmemset   memset
  324. #define _fmovmem   movmem
  325. #define _fsetmem   setmem
  326. #define _fstrcat   strcat
  327. #define _fstrchr   strchr
  328. #define _fstrcmp   strcmp
  329. #define _fstrcpy   strcpy
  330. #define _fstrcspn  strcspn
  331. #define _fstrdup   strdup
  332. #define _fstricmp  stricmp
  333. #define _fstrlen   strlen
  334. #define _fstrlwr   strlwr
  335. #define _fstrncat  strncat
  336. #define _fstrncmp  strncmp
  337. #define _fstrncpy  strncpy
  338. #define _fstrnicmp strnicmp
  339. #define _fstrnset  strnset
  340. #define _fstrpbrk  strpbrk
  341. #define _fstrrchr  strrchr
  342. #define _fstrrev   strrev
  343. #define _fstrset   strset
  344. #define _fstrspn   strspn
  345. #define _fstrstr   strstr
  346. #define _fstrtok   strtok
  347. #define _fstrupr   strupr
  348. #endif /* __STDC__  */
  349.  
  350. #endif  /* __FLAT__ */
  351.  
  352. #if defined(__USELOCALES__)
  353. #define  strupr     _lstrupr
  354. #define  strlwr     _lstrlwr
  355. #define  strcoll    _lstrcoll
  356. #define  stricoll   _lstricoll
  357. #define  strncoll   _lstrncoll
  358. #define  strnicoll  _lstrnicoll
  359. #define  strxfrm    _lstrxfrm
  360. #endif  /* __USELOCALES__ */
  361.  
  362. #ifdef __cplusplus
  363. }
  364. #endif
  365.  
  366. #if !defined(RC_INVOKED)
  367.  
  368. #if defined(__STDC__)
  369. #pragma warn .nak
  370. #endif
  371.  
  372. #endif  /* !RC_INVOKED */
  373.  
  374.  
  375. #endif  /* __STRING_H */
  376.  
  377. #else   /* __USING_STD_NAMES__ */
  378.  
  379. #ifndef __STD_STRING
  380. #define __STD_STRING
  381.  
  382. /***************************************************************************
  383.  *
  384.  * string - Declarations for the Standard Library string classes
  385.  *
  386.  * $Id: string,v 1.116 1995/10/03 00:03:27 smithey Exp $
  387.  *
  388.  ***************************************************************************
  389.  *
  390.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  391.  * ALL RIGHTS RESERVED
  392.  *
  393.  * The software and information contained herein are proprietary to, and
  394.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  395.  * intends to preserve as trade secrets such software and information.
  396.  * This software is furnished pursuant to a written license agreement and
  397.  * may be used, copied, transmitted, and stored only in accordance with
  398.  * the terms of such license and with the inclusion of the above copyright
  399.  * notice.  This software and information or any other copies thereof may
  400.  * not be provided or otherwise made available to any other person.
  401.  *
  402.  * Notwithstanding any other lease or license that may pertain to, or
  403.  * accompany the delivery of, this computer software and information, the
  404.  * rights of the Government regarding its use, reproduction and disclosure
  405.  * are as set forth in Section 52.227-19 of the FARS Computer
  406.  * Software-Restricted Rights clause.
  407.  *
  408.  * Use, duplication, or disclosure by the Government is subject to
  409.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  410.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  411.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  412.  * P.O. Box 2328, Corvallis, Oregon 97339.
  413.  *
  414.  * This computer software and information is distributed with "restricted
  415.  * rights."  Use, duplication or disclosure is subject to restrictions as
  416.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  417.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  418.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  419.  * then the "Alternate III" clause applies.
  420.  *
  421.  **************************************************************************/
  422.  
  423. #include <stdcomp.h>
  424. #include <stddefs.h>
  425.  
  426. #ifndef RWSTD_NO_NEW_HEADER
  427. #include <cstddef>
  428. #include <cstring>
  429. #include <cctype>
  430. #else
  431. #include <stddef.h>
  432. #include <string.h>
  433. #include <ctype.h>
  434. #endif
  435.  
  436. #include <memory>     // For allocator.
  437. #include <algorith>
  438. #include <iterator>
  439.  
  440. #ifdef RWSTD_MULTI_THREAD
  441. #include <stdmutex.h>
  442. #endif
  443.  
  444. #ifndef RWSTD_NO_WSTR
  445. #ifndef RWSTD_NO_NEW_HEADER
  446. #include <cwctype>
  447. #include <cwchar>
  448. #else
  449. #ifndef RWSTD_NO_WCTYPE_H
  450. # include <wctype.h>
  451. #endif
  452. #include <wchar.h>
  453. #endif
  454. #endif
  455.  
  456. #ifdef RW_STD_IOSTREAM
  457. #include <iostream>
  458. #else
  459. #include <iostream.h>
  460. #endif
  461.  
  462. //
  463. // Temporarily turn off the warnings under the Borland compiler that
  464. // say 'Functions containing ... cannot be inlined'
  465. //
  466. #if defined(__BORLANDC__)
  467. #pragma warn -inl
  468. #endif
  469.  
  470.  
  471. //
  472. // Extra comment after = d keeps > and > from being put together
  473. // if the default parameter is a templated type and is also the
  474. // last in the template parameter list
  475. //
  476.  
  477. #ifndef RWSTD_NO_DEFAULT_TEMPLATES
  478. #define RWSTD_TDFLT(d) = d /* */
  479. #else
  480. #define RWSTD_TDFLT(d) /* */
  481. #endif
  482.  
  483. #ifdef RW_STD_ALLOCATOR
  484. #define RWSTD_ALLOC_TYPE(t) allocator
  485. #else
  486. #define RWSTD_ALLOC_TYPE(t) allocator<t>
  487. #endif
  488.  
  489. #ifndef RWSTD_NO_NAMESPACE
  490. namespace std {
  491. #endif
  492.  
  493. //
  494. // Global error message declarations
  495. //
  496.  
  497. extern char RWSTDExport rwse_InvalidSizeParam[];
  498. extern char RWSTDExport rwse_PosBeyondEndOfString[];
  499. extern char RWSTDExport rwse_ResultLenInvalid[];
  500. extern char RWSTDExport rwse_StringIndexOutOfRange[];
  501. extern char RWSTDExport rwse_UnexpectedNullPtr[];
  502.  
  503. //
  504. // Class & Structure Declarations
  505. //
  506.  
  507. template<class charT> struct ios_traits;
  508. template<class charT> struct string_char_traits;
  509.  
  510. template< class charT, class traits RWSTD_TDFLT(string_char_traits<charT>),
  511.   class Allocator RWSTD_TDFLT(RWSTD_ALLOC_TYPE(charT)) >
  512. class string_ref;
  513.  
  514. template< class charT,  class traits RWSTD_TDFLT(string_char_traits<charT>),
  515.  class Allocator RWSTD_TDFLT(RWSTD_ALLOC_TYPE(charT)) >
  516. class basic_string;
  517.  
  518. //
  519. // string_char_traits structure definition
  520. //
  521. // Header right out of the working paper.
  522. //
  523.  
  524. template <class charT>
  525. struct string_char_traits
  526. {
  527.   typedef charT char_type;
  528.  
  529. #ifdef RW_STD_IOSTREAM
  530.   typedef basic_istream<char_type, ios_traits<char_type> > istream_type;
  531.   typedef basic_ostream<char_type, ios_traits<char_type> > ostream_type;
  532. #endif
  533.  
  534.   static void assign (char_type& c1, const char_type& c2)   { c1 = c2;         }
  535.   static bool eq (const char_type& c1, const char_type& c2) { return c1 == c2; }
  536.   static bool ne (const char_type& c1, const char_type& c2) { return !(c1==c2);}
  537.   static bool lt (const char_type& c1, const char_type& c2) { return c1 < c2;  }
  538.   static char_type eos ()  { return char_type(); }
  539.  
  540. #ifdef RW_STD_IOSTREAM
  541.   static istream_type& char_in  (istream_type& is, char_type& a) { is.get(a); return is;}
  542.   static ostream_type& char_out (ostream_type& os, char_type  a) { return os<<a;}
  543. #endif
  544.  
  545.   static bool is_del (char_type a)  { return isspace(a); }   // Delimiter
  546.  
  547.   static int compare (const char_type* s1, const char_type* s2, size_t n)
  548.   {
  549.     int result = 0;
  550.     for (size_t i = 0; i < n && result == 0; ++i, ++s1, ++s2)
  551.       if (ne(*s1, *s2))
  552.         result = lt(*s1, *s2) ? -1 : 1;
  553.     return result;
  554.   }
  555.   static size_t length (const char_type * s)
  556.   {
  557.     size_t l = 0;
  558.     while (ne(*s++, eos()))  ++l;
  559.     return l;
  560.   }
  561.   static char_type* copy (char_type* s1, const char_type* s2, size_t n)
  562.   {
  563.     char_type* s = s1;
  564.     for (size_t i = 0; i < n; i++)  assign(*s1++, *s2++);
  565.     return s;
  566.   }
  567.   static char_type* move (char_type* s1, const char_type* s2, size_t n)
  568.   {
  569.     char_type * s = s1;
  570.     if (s1 < s2)
  571.       copy(s1, s2, n);
  572.     else if (s1 > s2)
  573.     {
  574.       s1 += n;
  575.       s2 += n;
  576.       for(size_t i = 0; i < n; ++i) assign(*--s1, *--s2);
  577.     }
  578.     return s;
  579.   }
  580. };
  581.  
  582. class RWSTDExport string_char_traits<char>
  583. {
  584.  public:
  585.   typedef char char_type;
  586.  
  587. #ifdef RW_STD_IOSTREAM
  588.   typedef basic_istream<char, ios_traits<char> > istream_type;
  589.   typedef basic_ostream<char, ios_traits<char> > ostream_type;
  590. #else
  591.   typedef istream istream_type;
  592.   typedef ostream ostream_type;
  593. #endif
  594.  
  595.   static void assign (char_type& c1, const char_type& c2)   { c1 = c2; }
  596.   static bool eq (const char_type& c1, const char_type& c2) { return c1 == c2;}
  597.   static bool ne (const char_type& c1, const char_type& c2) { return c1 != c2;}
  598.   static bool lt (const char_type& c1, const char_type& c2) { return c1 < c2;}
  599.   static char_type eos () { return 0; }
  600.  
  601.   static istream_type& char_in  (istream_type& is, char_type& a) { is.get(a); return is;}
  602.   static ostream_type& char_out (ostream_type& os, char_type  a) { os.put(a); return os; }
  603.  
  604.   static bool is_del (char_type a)  { return isspace(a); }
  605.  
  606.   static int compare (const char_type* s1, const char_type* s2, size_t n)
  607.   {
  608.     return memcmp(s1, s2, n);
  609.   }
  610.   static size_t length (const char_type* s)
  611.   {
  612.     return strlen(s);
  613.   }
  614.   static char_type * copy (char_type* s1, const char_type* s2, size_t n)
  615.   {
  616.     return (char_type *) memcpy(s1, s2, n);
  617.   }
  618.   static char_type * move (char_type* s1, const char_type* s2, size_t n)
  619.   {
  620. #ifndef RWSTD_NO_MEMMOVE
  621.     return (char_type *) memmove(s1, s2, n);
  622. #else
  623.     char_type * s = s1;
  624.     if (s1 < s2)
  625.       copy(s1, s2, n);
  626.     else if (s1 > s2)
  627.     {
  628.       s1 += n;
  629.       s2 += n;
  630.       for(size_t i = 0; i < n; ++i) assign(*--s1, *--s2);
  631.     }
  632.     return s;
  633. #endif
  634.   }
  635. };
  636.  
  637. #ifndef RWSTD_NO_WSTR
  638. struct RWSTDExport string_char_traits<wchar_t>
  639. {
  640.   typedef wchar_t char_type;
  641.  
  642. #ifdef RW_STD_IOSTREAM
  643.   typedef basic_istream<char_type, ios_traits<char_type> > istream_type;
  644.   typedef basic_ostream<char_type, ios_traits<char_type> > ostream_type;
  645. #else
  646.   typedef istream istream_type;
  647.   typedef ostream ostream_type;
  648. #endif
  649.  
  650.   static void assign (char_type& c1, const char_type& c2)   { c1 = c2; }
  651.   static bool eq (const char_type& c1, const char_type& c2) { return c1 == c2;}
  652.   static bool ne (const char_type& c1, const char_type& c2) { return c1 != c2;}
  653.   static bool lt (const char_type& c1, const char_type& c2) { return c1 < c2;}
  654.   static char_type eos ()  { return 0; }
  655.  
  656. #ifdef RW_STD_IOSTREAM
  657.   static istream_type& char_in  (istream_type& is, char_type& a) { is.get(a); return is;}
  658.   static ostream_type& char_out (ostream_type& os, char_type  a) { return os<<a;}
  659. #else
  660.   static istream_type& char_in (istream_type& is, char_type& a)
  661.   {
  662.     char c;
  663.     is.get(c);
  664.     char_type wc;
  665.     mbtowc(&wc,&c,1);
  666.     a = wc;
  667.     return is;
  668.   }
  669.   static ostream_type& char_out (ostream_type& os, char_type a)
  670.   {
  671.     char c[RWSTD_MB_CUR_MAX+1];
  672.     int i;
  673.     if (i = wctomb(c,a) > 0)
  674.     {
  675.       c[i] = '\0';
  676.       os << c;
  677.     }
  678.     return os;
  679.   }
  680. #endif
  681.  
  682.   static bool is_del (char a)  { return iswspace(a); }
  683.  
  684.   static int compare (const char_type* s1, const char_type* s2, size_t n)
  685.   {
  686.     return wcsncmp(s1, s2, n);
  687.   }
  688.   static size_t length(const char_type* s)  { return wcslen(s); }
  689.   static char_type* copy(char_type* s1, const char_type* s2, size_t n)
  690.   {
  691.     return (char_type *) wcsncpy(s1, s2, n);
  692.   }
  693.   static char_type* move(char_type* s1, const char_type* s2, size_t n)
  694.   {
  695.     return (char_type *) wcsncpy(s1, s2, n);
  696.   }
  697. };
  698. #endif /* not defined RWSTD_NO_WSTR */
  699.  
  700. template <class Allocator>
  701. class string_ref_rep
  702. {
  703.  public:
  704.   string_ref_rep() : refs_(0), capacity_(0), nchars_(0) {;}
  705.  
  706. #ifdef RWSTD_MULTI_THREAD
  707.   RWSTDMutex mutex_;
  708. #endif
  709.  
  710.   typedef typename Allocator::size_type    size_type;
  711.  
  712.  protected:
  713.  
  714.   unsigned long   refs_;      // (1 less than) number of references
  715.  
  716.   size_type       capacity_;  // Size of allocated memory
  717.   size_type       nchars_;    // Number of actual data values stored
  718. };
  719.  
  720. template <class charT, class traits, class Allocator>
  721. struct null_string_ref_rep
  722. {
  723.   //
  724.   // ref_hdr has to be immediately followed by eos_char !
  725.   //
  726.   string_ref_rep<Allocator>      ref_hdr;
  727.   charT                          eos_char;
  728.  
  729.   null_string_ref_rep () : eos_char(traits::eos())  {;}
  730. };
  731.  
  732. #ifdef RWSTD_NO_STATIC_DEF3
  733. extern unsigned long RWSTDExport nullref[];
  734. #endif
  735.  
  736. template <class charT, class traits, class Allocator>
  737. class string_ref : public string_ref_rep<Allocator>
  738. {
  739.   typedef string_ref_rep<Allocator> string_ref_rep_type;
  740.  
  741.   string_ref (long initRef = 0) { refs_ = (unsigned long)initRef - 1; }
  742.  
  743.   unsigned references () const { return refs_+1; }
  744.  
  745.   void setRefCount (unsigned r)
  746.   {
  747. #ifdef RWSTD_MULTI_THREAD
  748.       RWSTDGuard guard(this->mutex_);
  749. #endif
  750.       refs_ = r-1;
  751.   }
  752.  
  753.   void addReference ()
  754.   {
  755. #ifdef RWSTD_MULTI_THREAD
  756.       RWSTDGuard guard(this->mutex_);
  757. #endif
  758.       refs_++;
  759.   }
  760.   unsigned  removeReference ()
  761.   {
  762. #ifdef RWSTD_MULTI_THREAD
  763.       RWSTDGuard guard(this->mutex_);
  764. #endif
  765.       return unSafeRemoveReference();
  766.   }
  767. unsigned  unSafeRemoveReference ()
  768.   {
  769.       return refs_--;
  770.   }
  771.  
  772.   size_type length         () const           { return nchars_; }
  773.   size_type getCapac       () const           { return capacity_;}
  774.   charT*    data           () const           { return (charT*)(this+1); }
  775.  
  776.   charT&    operator[]     (size_type i)      { return ((charT*)(this+1))[i]; }
  777.   charT     operator[]     (size_type i) const{ return ((charT*)(this+1))[i]; }
  778.  
  779.   //
  780.   // Disconnect from this ref, maybe delete it.
  781.   //
  782.   void      unLink          (Allocator& alloc);
  783.   void      unSafeunLink    (Allocator& alloc);
  784.  
  785.   friend class basic_string<charT, traits, Allocator>;
  786. };
  787.  
  788.  
  789. template <class charT, class traits, class Allocator >
  790. class basic_string
  791. {
  792.   public:
  793.     //
  794.     // types
  795.     //
  796.     typedef traits                                            traits_type;
  797.     typedef typename traits::char_type                        value_type;
  798.  
  799. #ifndef RWSTD_NO_COMPLICATED_TYPEDEF
  800.     typedef typename Allocator::size_type                     size_type;
  801. #else
  802.     typedef size_t                                            size_type;
  803. #endif
  804.     typedef typename Allocator::difference_type               difference_type;
  805.  
  806. #ifdef RW_STD_ALLOCATOR
  807.     typedef typename Allocator::types<charT>::reference       reference;
  808.     typedef typename Allocator::types<charT>::const_reference const_reference;
  809.     typedef typename Allocator::types<charT>::pointer         pointer;
  810.     typedef typename Allocator::types<charT>::const_pointer   const_pointer;
  811.  
  812.     typedef typename Allocator::types<charT>::pointer         iterator;
  813.     typedef typename Allocator::types<charT>::const_pointer   const_iterator;
  814. #else
  815.     typedef typename Allocator::reference                     reference;
  816.     typedef typename Allocator::const_reference               const_reference;
  817.     typedef typename Allocator::pointer                       pointer;
  818.     typedef typename Allocator::const_pointer                 const_pointer;
  819.  
  820.     typedef typename Allocator::pointer                       iterator;
  821.     typedef typename Allocator::const_pointer                 const_iterator;
  822. #endif
  823.  
  824.     typedef reverse_iterator<const_iterator, value_type,
  825.                     const_reference, difference_type>   const_reverse_iterator;
  826.     typedef reverse_iterator<iterator, value_type,
  827.                     reference, difference_type>         reverse_iterator;
  828.  
  829.     static const size_type npos;
  830.  
  831.     explicit basic_string (const Allocator& = Allocator());
  832.     basic_string (const basic_string<charT, traits, Allocator>&);
  833.     basic_string (const basic_string<charT, traits, Allocator>&, size_type,
  834.                   size_type = npos, const Allocator& = Allocator());
  835.     basic_string (const charT*, size_type, const Allocator& = Allocator());
  836.     basic_string (const charT*, const Allocator& = Allocator());
  837.     basic_string (size_type, charT, const Allocator& = Allocator());
  838. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  839.     template <class InputIterator>
  840.       basic_string (InputIterator, InputIterator, const Allocator&=Allocator());
  841. #else
  842.     basic_string (const charT*, const charT*, const Allocator& = Allocator());
  843. #endif
  844.  
  845.    ~basic_string ();
  846.  
  847.     basic_string<charT, traits, Allocator>& operator= (const basic_string<charT, traits, Allocator>&);
  848.     basic_string<charT, traits, Allocator>& operator= (const charT*);
  849.     basic_string<charT, traits, Allocator>& operator= (charT);
  850.     //
  851.     // iterators
  852.     //
  853.     iterator       begin ()        { return data_;          }
  854.     const_iterator begin () const  { return data_;          }
  855.     iterator       end   ()        { return data_+length(); }
  856.     const_iterator end   () const  { return data_+length(); }
  857.  
  858.     reverse_iterator rbegin ()
  859.     {
  860.         reverse_iterator tmp(end()); return tmp;
  861.     }
  862.     const_reverse_iterator rbegin () const
  863.     {
  864.         const_reverse_iterator tmp(end()); return tmp;
  865.     }
  866.     reverse_iterator rend ()
  867.     {
  868.         reverse_iterator tmp(begin()); return tmp;
  869.     }
  870.     const_reverse_iterator rend () const
  871.     {
  872.         const_reverse_iterator tmp(begin()); return tmp;
  873.     }
  874.     //
  875.     // capacity
  876.     //
  877.     size_type length () const;
  878.     size_type size () const      { return length(); }
  879.     size_type max_size () const
  880.     {
  881.         return npos - sizeof(string_ref_rep<Allocator>);
  882.     }
  883.     void resize (size_type, charT);
  884.     void resize (size_type);
  885.     size_type capacity () const;
  886.     void reserve (size_type);
  887.     bool empty () const  { return length() == 0; }
  888.     //
  889.     // element access
  890.     //
  891.     charT           operator[] (size_type) const;
  892.     reference       operator[] (size_type);
  893.     const_reference at (size_type) const;
  894.     reference       at (size_type);
  895.     //
  896.     // modifiers
  897.     //
  898.     basic_string<charT, traits, Allocator>& operator+= (const basic_string<charT, traits, Allocator>&);
  899.     basic_string<charT, traits, Allocator>& operator+= (const charT*);
  900.     basic_string<charT, traits, Allocator>& operator+= (charT);
  901.  
  902.     basic_string<charT, traits, Allocator>& append (const basic_string<charT, traits, Allocator>&,
  903.                                                     size_type = 0,
  904.                                                     size_type = npos);
  905.     basic_string<charT, traits, Allocator>& append (const charT*, size_type);
  906.     basic_string<charT, traits, Allocator>& append (const charT*);
  907.     //
  908.     // The WP defaults the second argument here.
  909.     //
  910.     basic_string<charT, traits, Allocator>& append (size_type, charT);
  911.     //
  912.     // This is currently not in the WP.
  913.     //
  914.     basic_string<charT, traits, Allocator>& append (charT c)
  915.     {
  916.         return append(1,c);
  917.     }
  918. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  919.     template<class InputIterator>
  920.     basic_string<charT, traits, Allocator>& append (InputIterator,
  921.                                                     InputIterator);
  922. #else
  923.     basic_string<charT, traits, Allocator>& append (const charT*,
  924.                                                     const charT*);
  925. #endif
  926.  
  927.     basic_string<charT, traits, Allocator>& assign (const basic_string<charT, traits, Allocator>&,
  928.                                                     size_type = 0,
  929.                                                     size_type = npos);
  930.     basic_string<charT, traits, Allocator>& assign (const charT*, size_type);
  931.     basic_string<charT, traits, Allocator>& assign (const charT*);
  932.     //
  933.     // The WP defaults the second argument here.
  934.     //
  935.     basic_string<charT, traits, Allocator>& assign (size_type, charT);
  936.     //
  937.     // This is currently not in the WP.
  938.     //
  939.     basic_string<charT, traits, Allocator>& assign (charT c)
  940.     {
  941.       return assign(1,c);
  942.     }
  943. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  944.     template<class InputIterator>
  945.     basic_string<charT, traits, Allocator>& assign (InputIterator,
  946.                                                     InputIterator);
  947. #else
  948.     basic_string<charT, traits, Allocator>& assign (const charT*,
  949.                                                     const charT*);
  950. #endif
  951.  
  952.     basic_string<charT, traits, Allocator>& insert (size_type,
  953.                                                     const basic_string<charT, traits, Allocator>&,
  954.                                                     size_type = 0,
  955.                                                     size_type = npos);
  956.     basic_string<charT, traits, Allocator>& insert (size_type,
  957.                                                     const charT*,
  958.                                                     size_type);
  959.     basic_string<charT, traits, Allocator>& insert (size_type, const charT*);
  960.     //
  961.     // The WP defaults the third argument here.
  962.     //
  963.     basic_string<charT, traits, Allocator>& insert (size_type,size_type,charT);
  964.     //
  965.     // This is not currently defined by the WP.
  966.     //
  967.     basic_string<charT, traits, Allocator>& insert (size_type pos, charT c)
  968.     {
  969.         return insert(pos,1,c);
  970.     }
  971.     //
  972.     // The WP defaults the third argument here.
  973.     //
  974.     iterator insert (iterator, size_type, charT);
  975.     //
  976.     // The WP defaults the second argument here.
  977.     //
  978.     iterator insert (iterator pos, charT c)
  979.     {
  980.         return insert(pos,1,c);
  981.     }
  982. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  983.     template<class InputIterator>
  984.     void insert (iterator, InputIterator, InputIterator);
  985. #else
  986.     void insert (iterator, const charT*, const charT*);
  987. #endif
  988.  
  989.     basic_string<charT, traits, Allocator>& remove (size_type = 0,
  990.                                                     size_type = npos);
  991.     basic_string<charT, traits, Allocator>& remove (iterator);
  992.     basic_string<charT, traits, Allocator>& remove (iterator, iterator);
  993.  
  994.     void erase (iterator it) { remove(it); }
  995.     void erase (iterator first, iterator last) { remove(first,last); }
  996.  
  997. private:
  998.     //
  999.     // Used for effiency
  1000.     //
  1001.     basic_string<charT, traits, Allocator>::iterator replace (size_type,
  1002.                                                               size_type,
  1003.                                                               const charT*,
  1004.                                                               size_type,
  1005.                                                               size_type,
  1006.                                                               size_type);
  1007.     basic_string<charT, traits, Allocator>::iterator replace_aux (size_type,
  1008.                                                                   size_type,
  1009.                                                                   const basic_string<charT, traits, Allocator>&,
  1010.                                                                   size_type =0,
  1011.                                                                   size_type =npos);
  1012. public:
  1013.  
  1014.     basic_string<charT, traits, Allocator>& replace (size_type,
  1015.                                                      size_type,
  1016.                                                      const basic_string<charT, traits, Allocator>&,
  1017.                                                      size_type = 0,
  1018.                                                      size_type = npos);
  1019.     basic_string<charT, traits, Allocator>& replace (size_type,
  1020.                                                      size_type,
  1021.                                                      const charT*,
  1022.                                                      size_type);
  1023.     basic_string<charT, traits, Allocator>& replace (size_type,
  1024.                                                      size_type,
  1025.                                                      const charT*);
  1026.     basic_string<charT, traits, Allocator>& replace (size_type,
  1027.                                                      size_type,
  1028.                                                      size_type,
  1029.                                                      charT);
  1030.     basic_string<charT, traits, Allocator>& replace (iterator,
  1031.                                                      iterator,
  1032.                                                      const basic_string<charT, traits, Allocator>&);
  1033.     basic_string<charT, traits, Allocator>& replace (iterator,
  1034.                                                      iterator,
  1035.                                                      const charT*,
  1036.                                                      size_type);
  1037.     basic_string<charT, traits, Allocator>& replace (iterator,
  1038.                                                      iterator,
  1039.                                                      const charT*);
  1040.     basic_string<charT, traits, Allocator>& replace (iterator,
  1041.                                                      iterator,
  1042.                                                      size_type,
  1043.                                                      charT);
  1044.     basic_string<charT, traits, Allocator>& replace (iterator first,
  1045.                                                      iterator last,
  1046.                                                      charT c)
  1047.     {
  1048.         return replace(first,last,1,c);
  1049.     }
  1050. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  1051.     template<class InputIterator>
  1052.     basic_string<charT, traits, Allocator>& replace (iterator, iterator,
  1053.                                                      InputIterator,
  1054.                                                      InputIterator);
  1055. #else
  1056.     basic_string<charT, traits, Allocator>& replace (iterator, iterator,
  1057.                                                      const charT*,
  1058.                                                      const charT*);
  1059. #endif
  1060.  
  1061.     size_type copy (charT*, size_type, size_type = 0);
  1062.     basic_string<charT, traits, Allocator> copy () const; // Returns deep copy
  1063.     void swap(basic_string<charT, traits, Allocator>& s)
  1064.     {
  1065.         charT * temp = data_; data_ = s.data_; s.data_ = temp;
  1066.     }
  1067.     //
  1068.     // string operations
  1069.     //
  1070.     const charT* c_str () const;
  1071.     const charT* data  () const;
  1072.  
  1073.     size_type find (const basic_string<charT, traits, Allocator>&,
  1074.                     size_type = 0) const;
  1075.     size_type find (const charT*, size_type, size_type) const;
  1076.     size_type find (const charT*, size_type = 0) const;
  1077.     size_type find (charT, size_type = 0) const;
  1078.  
  1079.     size_type rfind (const basic_string<charT, traits, Allocator>&,
  1080.                      size_type = npos) const;
  1081.     size_type rfind (const charT*, size_type, size_type) const;
  1082.     size_type rfind (const charT*, size_type = npos) const;
  1083.     size_type rfind (charT, size_type = npos) const;
  1084.  
  1085.     size_type find_first_of (const basic_string<charT, traits, Allocator>&,
  1086.                              size_type = 0) const;
  1087.     size_type find_first_of (const charT*, size_type, size_type) const;
  1088.     size_type find_first_of (const charT*, size_type = 0) const;
  1089.     size_type find_first_of (charT, size_type = 0) const;
  1090.  
  1091.     size_type find_last_of (const basic_string<charT, traits, Allocator>&,
  1092.                             size_type = npos) const;
  1093.     size_type find_last_of (const charT*, size_type, size_type) const;
  1094.     size_type find_last_of (const charT*, size_type = npos) const;
  1095.     size_type find_last_of (charT, size_type = npos) const;
  1096.  
  1097.     size_type find_first_not_of (const basic_string<charT, traits, Allocator>&,
  1098.                                  size_type = 0) const;
  1099.     size_type find_first_not_of (const charT*, size_type ,
  1100.                                  size_type) const;
  1101.     size_type find_first_not_of (const charT*, size_type = 0) const;
  1102.     size_type find_first_not_of (charT, size_type = 0) const;
  1103.  
  1104.     size_type find_last_not_of (const basic_string<charT, traits, Allocator>&,
  1105.                                 size_type = npos) const;
  1106.     size_type find_last_not_of (const charT*, size_type, size_type) const;
  1107.     size_type find_last_not_of (const charT*, size_type = npos) const;
  1108.     size_type find_last_not_of (charT, size_type = npos) const;
  1109.  
  1110.     basic_string<charT, traits, Allocator> substr (size_type = 0,
  1111.                                                    size_type = npos) const;
  1112.  
  1113.     int compare(const basic_string<charT, traits, Allocator>&,
  1114.                 size_type = 0,
  1115.                 size_type = npos) const;
  1116.     int compare (charT*, size_type, size_type) const;
  1117.     int compare (charT*, size_type = 0) const;
  1118.  
  1119.  protected:
  1120.  
  1121.     size_type getCapac () const { return pref()->getCapac(); }
  1122.  
  1123.     void clobber (size_type); // Remove old contents
  1124.     void cow ()               // Do copy on write as necessary
  1125.     {
  1126. #ifdef RWSTD_MULTI_THREAD
  1127.         RWSTDGuard guard(pref()->mutex_);
  1128. #endif
  1129.         if (pref()->references() > 1)
  1130.             unSafeClone();
  1131.     }
  1132.     void cow (size_type nc)     // Do copy on write w/ new capacity
  1133.     {
  1134. #ifdef RWSTD_MULTI_THREAD
  1135.         RWSTDGuard guard(pref()->mutex_);
  1136. #endif
  1137.         if (pref()->references() > 1 || getCapac() < nc)
  1138.             unSafeClone(nc);
  1139.     }
  1140.  
  1141.  private:
  1142.  
  1143.     typedef string_ref<charT,traits,Allocator> string_ref_type;
  1144.  
  1145.     static charT eos () { return traits::eos(); }
  1146.  
  1147.     //
  1148.     // Make a distinct copy of self
  1149.     //
  1150.     void clone ()
  1151.     {
  1152. #ifdef RWSTD_MULTI_THREAD
  1153.         RWSTDGuard guard(pref()->mutex_);
  1154. #endif
  1155.         unSafeClone();
  1156.     }
  1157.     void unSafeClone ();
  1158.     //
  1159.     // Make a distinct copy w/ new capacity nc
  1160.     //
  1161.     void clone (size_type nc)
  1162.     {
  1163. #ifdef RWSTD_MULTI_THREAD
  1164.         RWSTDGuard guard(pref()->mutex_);
  1165. #endif
  1166.         unSafeClone(nc);
  1167.     }
  1168.     void unSafeClone (size_type);
  1169.  
  1170.     string_ref_type *  pref () const
  1171.     {
  1172.         return (string_ref_type*) (((string_ref_type*) data_) - 1);
  1173.     }
  1174.     //
  1175.     // Null string ref
  1176.     //
  1177. #ifndef RWSTD_NO_STATIC_DEF3
  1178.     static const null_string_ref_rep<charT, traits, Allocator> nullref;
  1179. #endif
  1180.  
  1181.     static string_ref<charT, traits, Allocator> * getNullRep ()
  1182. #ifndef RWSTD_NO_STATIC_DEF3
  1183.     { return (string_ref<charT, traits, Allocator> *) &nullref; }
  1184. #else
  1185.     { return (string_ref<charT, traits, Allocator> *) &nullref[0]; }
  1186. #endif
  1187.  
  1188.     string_ref<charT, traits, Allocator> * getRep (size_type capac,
  1189.                                                    size_type nchar,
  1190.                                                    Allocator& alloc);
  1191.     charT*    data_;
  1192.     Allocator alloc_;
  1193. };
  1194.  
  1195. #ifndef RWSTD_NO_EXPLICIT_INSTANTIATION
  1196. template class RWSTDExportTemplate RWSTD_ALLOC_TYPE(char);
  1197.  
  1198. template class RWSTDExportTemplate string_ref<char,string_char_traits<char>, allocator<char> >;
  1199.  
  1200. template class RWSTDExportTemplate
  1201.  basic_string<char, string_char_traits<char>, RWSTD_ALLOC_TYPE(char) >;
  1202.  
  1203. #ifndef RWSTD_NO_WSTR
  1204. template class RWSTDExportTemplate
  1205.  basic_string<wchar_t, string_char_traits<wchar_t>, RWSTD_ALLOC_TYPE(wchar_t) >;
  1206. #endif
  1207. #endif
  1208.  
  1209. //
  1210. // Standard Type Definitions
  1211. //
  1212. typedef basic_string<char, string_char_traits<char>, RWSTD_ALLOC_TYPE(char) >
  1213.   string;
  1214.  
  1215. #ifndef RWSTD_NO_WSTR
  1216. typedef basic_string<wchar_t, string_char_traits<wchar_t>, RWSTD_ALLOC_TYPE(wchar_t) >
  1217.   wstring;
  1218. #endif
  1219.  
  1220. #ifndef RWSTD_NO_NAMESPACE
  1221. }
  1222. #endif
  1223.  
  1224. //
  1225. // The following has to go after the declaration of the string
  1226. // classes because of cross references.
  1227. //
  1228. #ifdef RW_STD_EXCEPT
  1229. #include <stdexcep>
  1230. #endif
  1231.  
  1232. #ifndef RWSTD_NO_NAMESPACE
  1233. namespace std {
  1234. #endif
  1235.  
  1236. #if defined(RWSTD_NO_DESTROY_BUILTIN) || defined(RWSTD_NO_DESTROY_NONBUILTIN)
  1237. //
  1238. // Specializations for STL destroy
  1239. //
  1240. inline void destroy (string**)    {;}
  1241. inline void destroy (string***)   {;}
  1242. inline void destroy (string****)  {;}
  1243. #ifndef RWSTD_NO_WSTR
  1244. inline void destroy (wstring**)   {;}
  1245. inline void destroy (wstring***)  {;}
  1246. inline void destroy (wstring****) {;}
  1247. #endif
  1248. #endif
  1249.  
  1250. //
  1251. // Inline member functions for class string_ref
  1252. //
  1253.  
  1254. template <class charT, class traits, class Allocator >
  1255. inline void string_ref<charT, traits, Allocator>::unLink(Allocator& alloc)
  1256. {
  1257.     if (removeReference() == 0)
  1258.         alloc.deallocate((charT*)this);
  1259. }
  1260.  
  1261. template <class charT, class traits, class Allocator >
  1262. inline void string_ref<charT, traits, Allocator>::unSafeunLink(Allocator& alloc)
  1263. {
  1264.     if (unSafeRemoveReference() == 0)
  1265.         alloc.deallocate((charT*)this);
  1266. }
  1267.  
  1268. //
  1269. // Inline member functions for class basic_string
  1270. //
  1271.  
  1272. template <class charT, class traits, class Allocator >
  1273. inline basic_string<charT, traits, Allocator>
  1274.   ::basic_string (const Allocator& alloc)
  1275. {
  1276.     data_ = getNullRep()->data();
  1277.     getNullRep()->addReference();
  1278.     alloc_ = alloc;
  1279. }
  1280.  
  1281. template <class charT, class traits, class Allocator >
  1282. inline
  1283. basic_string<charT, traits, Allocator>
  1284.   ::basic_string (const basic_string<charT, traits, Allocator> & s)
  1285. {
  1286.     data_ = s.data_;
  1287.     pref()->addReference();
  1288. }
  1289.  
  1290. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  1291. template <class charT, class traits, class Allocator>
  1292. template <class InputIterator>
  1293. basic_string<charT, traits, Allocator>::basic_string (InputIterator first,
  1294.                                                       InputIterator last,
  1295.                                                       const Allocator& alloc)
  1296. {
  1297.     data_ = getNullRep()->data();
  1298.     getNullRep()->addReference();
  1299.     alloc_ = alloc;
  1300.     while (first != last) append(1,*first++);
  1301. }
  1302. #else
  1303. template <class charT, class traits, class Allocator >
  1304. basic_string<charT, traits, Allocator>::basic_string (const charT* first,
  1305.                                                       const charT* last,
  1306.                                                       const Allocator& alloc)
  1307. {
  1308.     data_ = getNullRep()->data();
  1309.     getNullRep()->addReference();
  1310.     alloc_ = alloc;
  1311.     while (first != last) append(1,*first++);
  1312. }
  1313. #endif
  1314.  
  1315. template <class charT, class traits, class Allocator >
  1316. inline basic_string<charT, traits, Allocator>::~basic_string ()
  1317. {
  1318.     pref()->unLink(alloc_);
  1319. }
  1320.  
  1321. template <class charT, class traits, class Allocator >
  1322. inline basic_string<charT, traits, Allocator> &
  1323. basic_string<charT, traits, Allocator>::operator= (charT c)
  1324. {
  1325.     return *this = basic_string<charT, traits, Allocator>(1,c);
  1326. }
  1327.  
  1328. template <class charT, class traits, class Allocator >
  1329. inline basic_string<charT, traits, Allocator> &
  1330. basic_string<charT, traits, Allocator>::operator+= (const basic_string<charT, traits, Allocator>& s)
  1331. {
  1332.     return append(s);
  1333. }
  1334.  
  1335. template <class charT, class traits, class Allocator >
  1336. inline basic_string<charT, traits, Allocator> &
  1337. basic_string<charT, traits, Allocator>::operator+= (const charT* s)
  1338. {
  1339.     return append(s);
  1340. }
  1341.  
  1342. template <class charT, class traits, class Allocator >
  1343. inline basic_string<charT, traits, Allocator> &
  1344. basic_string<charT, traits, Allocator>::operator+= (charT c)
  1345. {
  1346.     return append((size_type) 1, c);
  1347. }
  1348.  
  1349. template <class charT, class traits, class Allocator >
  1350. inline basic_string<charT, traits, Allocator> &
  1351. basic_string<charT, traits, Allocator>::append (const charT* s, size_type n)
  1352. {
  1353.     return append(basic_string<charT,traits,Allocator>(s,n));
  1354. }
  1355.  
  1356. template <class charT, class traits, class Allocator >
  1357. inline basic_string<charT, traits, Allocator> &
  1358. basic_string<charT, traits, Allocator>::append (const charT* s)
  1359. {
  1360.     return append(basic_string<charT,traits,Allocator>(s));
  1361. }
  1362.  
  1363. template <class charT, class traits, class Allocator >
  1364. inline basic_string<charT, traits, Allocator> &
  1365. basic_string<charT, traits, Allocator>::append (size_type n, charT c)
  1366. {
  1367.     return append(basic_string<charT,traits,Allocator>(n,c));
  1368. }
  1369.  
  1370. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  1371. template<class charT, class traits, class Allocator>
  1372. template<class InputIterator>
  1373. inline basic_string<charT, traits, Allocator>&
  1374. basic_string<charT, traits, Allocator>::append (InputIterator first,
  1375.                                                 InputIterator last )
  1376. {
  1377.     return append(basic_string<charT, traits, Allocator>(first, last));
  1378. }
  1379. #else
  1380. template <class charT, class traits, class Allocator >
  1381. inline basic_string<charT, traits, Allocator>&
  1382. basic_string<charT, traits, Allocator>::append (const charT* first,
  1383.                                                 const charT* last)
  1384. {
  1385.     return append(basic_string<charT, traits, Allocator>(first, last));
  1386. }
  1387. #endif
  1388.  
  1389. template <class charT, class traits, class Allocator >
  1390. inline basic_string<charT, traits, Allocator> &
  1391. basic_string<charT, traits, Allocator>::assign (const charT* s, size_type n)
  1392. {
  1393.     return assign(basic_string<charT,traits,Allocator>(s,n));
  1394. }
  1395.  
  1396. template <class charT, class traits, class Allocator >
  1397. inline basic_string<charT, traits, Allocator> &
  1398. basic_string<charT, traits, Allocator>::assign (const charT* s)
  1399. {
  1400.     return assign(basic_string<charT,traits,Allocator>(s));
  1401. }
  1402.  
  1403. template <class charT, class traits, class Allocator >
  1404. inline basic_string<charT, traits, Allocator> &
  1405. basic_string<charT, traits, Allocator>::assign (size_type n, charT c)
  1406. {
  1407.     return assign(basic_string<charT,traits,Allocator>(n,c));
  1408. }
  1409.  
  1410. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  1411. template<class charT, class traits, class Allocator>
  1412. template<class InputIterator>
  1413. basic_string<charT, traits, Allocator>&
  1414. basic_string<charT, traits, Allocator>::assign (InputIterator first,
  1415.                                                 InputIterator last)
  1416. {
  1417.     return assign(basic_string<charT, traits, Allocator>(first, last));
  1418. }
  1419. #else
  1420. template <class charT, class traits, class Allocator >
  1421. basic_string<charT, traits, Allocator>&
  1422. basic_string<charT, traits, Allocator>::assign (const charT* first,
  1423.                                                 const charT* last)
  1424. {
  1425.     return assign(basic_string<charT, traits, Allocator>(first, last));
  1426. }
  1427. #endif
  1428.  
  1429. template <class charT, class traits, class Allocator >
  1430. inline basic_string<charT, traits, Allocator> &
  1431. basic_string<charT, traits, Allocator>::insert (size_type pos,
  1432.                                                 const charT* s,
  1433.                                                 size_type n)
  1434. {
  1435.     return insert(pos, basic_string<charT,traits,Allocator>(s,n));
  1436. }
  1437.  
  1438. template <class charT, class traits, class Allocator >
  1439. inline basic_string<charT, traits, Allocator> &
  1440. basic_string<charT, traits, Allocator>::insert (size_type pos, const charT* s)
  1441. {
  1442.     return insert(pos, basic_string<charT,traits,Allocator>(s));
  1443. }
  1444.  
  1445. template <class charT, class traits, class Allocator >
  1446. inline basic_string<charT, traits, Allocator> &
  1447. basic_string<charT, traits, Allocator>::insert(size_type pos,
  1448.                                                size_type n,
  1449.                                                charT c)
  1450. {
  1451.     return insert(pos, basic_string<charT,traits,Allocator>(n,c));
  1452. }
  1453.  
  1454. template <class charT, class traits, class Allocator >
  1455. inline basic_string<charT, traits, Allocator>::iterator
  1456. basic_string<charT, traits, Allocator>::insert (iterator p,
  1457.                                                 size_type n,
  1458.                                                 charT c)
  1459. {
  1460.     return replace_aux(p-begin(),0,basic_string<charT,traits,Allocator>(n,c));
  1461. }
  1462.  
  1463. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  1464. template<class charT, class traits, class Allocator>
  1465. template<class InputIterator>
  1466. inline void
  1467. basic_string<charT, traits, Allocator>::insert (iterator p,
  1468.                                                 InputIterator first,
  1469.                                                 InputIterator last)
  1470. {
  1471.     replace(p-begin(), 0, basic_string<charT, traits, Allocator>(first, last));
  1472. }
  1473. #else
  1474. template <class charT, class traits, class Allocator >
  1475. inline void
  1476. basic_string<charT, traits, Allocator>::insert (iterator p,
  1477.                                                 const charT* first,
  1478.                                                 const charT* last)
  1479. {
  1480.     replace(p-begin(), 0, basic_string<charT, traits, Allocator>(first, last));
  1481. }
  1482. #endif
  1483.  
  1484. template <class charT, class traits, class Allocator >
  1485. inline basic_string<charT, traits, Allocator> &
  1486. basic_string<charT, traits, Allocator>::remove (size_type pos, size_type n)
  1487. {
  1488.     RWSTD_THROW(pos > length(), out_of_range, rwse_StringIndexOutOfRange);
  1489.     return replace(pos,
  1490.                    min(n, length() - pos),
  1491.                    basic_string<charT, traits, Allocator>((size_type)0, (charT)0));
  1492. }
  1493.  
  1494. template <class charT, class traits, class Allocator >
  1495. inline basic_string<charT, traits, Allocator> &
  1496. basic_string<charT, traits, Allocator>::remove (iterator it)
  1497. {
  1498.     return replace(it - begin(),
  1499.                    1,
  1500.                    basic_string<charT, traits, Allocator>((size_type)0, (charT)0));
  1501. }
  1502.  
  1503. template <class charT, class traits, class Allocator >
  1504. inline basic_string<charT, traits, Allocator> &
  1505. basic_string<charT, traits, Allocator>::remove (iterator first, iterator last)
  1506. {
  1507.     return replace(first-begin(),
  1508.                    min(last - first, end() - first),
  1509.                    basic_string<charT, traits, Allocator>((size_type)0, (charT)0));
  1510. }
  1511.  
  1512. template <class charT, class traits, class Allocator >
  1513. inline basic_string<charT, traits, Allocator> &
  1514. basic_string<charT, traits, Allocator>::replace (size_type pos1,
  1515.                                                  size_type n1,
  1516.                                                  const basic_string<charT, traits, Allocator> & str,
  1517.                                                  size_type pos2,
  1518.                                                  size_type n2)
  1519. {
  1520.     replace(pos1, n1, str.data(), str.length(), pos2, n2);
  1521.     return *this;
  1522. }
  1523.  
  1524. template <class charT, class traits, class Allocator >
  1525. inline basic_string<charT, traits, Allocator>::iterator
  1526. basic_string<charT, traits, Allocator>::replace_aux (size_type pos1,
  1527.                                                      size_type n1,
  1528.                                                      const basic_string<charT, traits, Allocator> & str,
  1529.                                                      size_type pos2,
  1530.                                                      size_type n2)
  1531. {
  1532.     return replace(pos1, n1, str.data(), str.length(), pos2, n2);
  1533. }
  1534.  
  1535. template <class charT, class traits, class Allocator >
  1536. inline basic_string<charT, traits, Allocator> &
  1537. basic_string<charT, traits, Allocator>::replace (size_type pos,
  1538.                                                  size_type n1,
  1539.                                                  const charT* s,
  1540.                                                  size_type n2)
  1541. {
  1542.     replace(pos, n1, basic_string<charT,traits,Allocator>(s,n2));
  1543.     return *this;
  1544. }
  1545.  
  1546. template <class charT, class traits, class Allocator >
  1547. inline basic_string<charT, traits, Allocator> &
  1548. basic_string<charT, traits, Allocator>::replace (size_type pos,
  1549.                                                  size_type n1,
  1550.                                                  const charT* s)
  1551. {
  1552.     replace(pos, n1, basic_string<charT,traits,Allocator>(s));
  1553.     return *this;
  1554. }
  1555.  
  1556. template <class charT, class traits, class Allocator >
  1557. inline basic_string<charT, traits, Allocator> &
  1558. basic_string<charT, traits, Allocator>::replace (size_type pos,
  1559.                                                  size_type n,
  1560.                                                  size_type n2,
  1561.                                                  charT c)
  1562. {
  1563.     return replace(pos, n, basic_string<charT, traits, Allocator>(n2,c));
  1564. }
  1565.  
  1566. template <class charT, class traits, class Allocator >
  1567. inline basic_string<charT, traits, Allocator>&
  1568. basic_string<charT, traits, Allocator>::replace (iterator first,
  1569.                                                  iterator last,
  1570.                                                  const basic_string<charT, traits, Allocator>& str)
  1571. {
  1572.     return replace(first - begin(), last - first, str);
  1573. }
  1574.  
  1575. template <class charT, class traits, class Allocator >
  1576. inline basic_string<charT, traits, Allocator>&
  1577. basic_string<charT, traits, Allocator>::replace (iterator first,
  1578.                                                  iterator last,
  1579.                                                  const charT* s,
  1580.                                                  size_type n)
  1581. {
  1582.     return replace(first,last,basic_string<charT,traits,Allocator>(s,n));
  1583. }
  1584.  
  1585. template <class charT, class traits, class Allocator >
  1586. inline basic_string<charT, traits, Allocator>&
  1587. basic_string<charT, traits, Allocator>::replace (iterator first,
  1588.                                                  iterator last,
  1589.                                                  const charT* s)
  1590. {
  1591.     return replace(first,last,basic_string<charT,traits,Allocator>(s));
  1592. }
  1593.  
  1594. template <class charT, class traits, class Allocator >
  1595. inline basic_string<charT, traits, Allocator>&
  1596. basic_string<charT, traits, Allocator>::replace (iterator first,
  1597.                                                  iterator last,
  1598.                                                  size_type n,
  1599.                                                  charT c)
  1600. {
  1601.     return replace(first,last,basic_string<charT,traits,Allocator>(n,c));
  1602. }
  1603.  
  1604. #ifndef RWSTD_NO_MEMBER_TEMPLATES
  1605. template<class charT, class traits, class Allocator>
  1606. template<class InputIterator>
  1607. inline basic_string<charT, traits, Allocator>&
  1608. basic_string<charT, traits, Allocator>::replace (iterator first1,
  1609.                                                  iterator last1,
  1610.                                                  InputIterator first2,
  1611.                                                  InputIterator last2)
  1612. {
  1613.     return replace(first1,last1,
  1614.                    basic_string<charT,traits,Allocator>(first2,last2));
  1615. }
  1616. #else
  1617. template <class charT, class traits, class Allocator >
  1618. inline basic_string<charT, traits, Allocator>&
  1619. basic_string<charT, traits, Allocator>::replace (iterator first1,
  1620.                                                  iterator last1,
  1621.                                                  const charT* first2,
  1622.                                                  const charT* last2)
  1623. {
  1624.     return replace(first1,last1,
  1625.                    basic_string<charT,traits,Allocator>(first2,last2));
  1626. }
  1627. #endif
  1628.  
  1629. template <class charT, class traits, class Allocator >
  1630. inline charT basic_string<charT, traits, Allocator>::operator[] (size_type pos) const
  1631. {
  1632.     RWSTD_THROW(pos > size(), out_of_range, rwse_PosBeyondEndOfString);
  1633.     return pos == size() ? traits::eos() : data_[pos];
  1634. }
  1635.  
  1636. template <class charT, class traits, class Allocator >
  1637. inline basic_string<charT, traits, Allocator>::reference
  1638. basic_string<charT, traits, Allocator>::operator[] (size_type pos)
  1639. {
  1640.     RWSTD_THROW(pos >= size(), out_of_range, rwse_PosBeyondEndOfString);
  1641.     cow();
  1642.     return data_[pos];
  1643. }
  1644.  
  1645. template <class charT, class traits, class Allocator >
  1646. inline basic_string<charT, traits, Allocator>::const_reference
  1647. basic_string<charT, traits, Allocator>::at (size_type pos) const
  1648. {
  1649.     RWSTD_THROW(pos >= size(), out_of_range, rwse_PosBeyondEndOfString);
  1650.     return data_[pos];
  1651. }
  1652.  
  1653. template <class charT, class traits, class Allocator >
  1654. inline basic_string<charT, traits, Allocator>::reference
  1655. basic_string<charT, traits, Allocator>::at (size_type pos)
  1656. {
  1657.     RWSTD_THROW(pos >= size(), out_of_range, rwse_PosBeyondEndOfString);
  1658.     return data_[pos];
  1659. }
  1660.  
  1661. template <class charT, class traits, class Allocator >
  1662. inline const charT* basic_string<charT, traits, Allocator>::c_str () const
  1663. {
  1664.     return data_;
  1665. }
  1666.  
  1667. template <class charT, class traits, class Allocator >
  1668. inline const charT* basic_string<charT, traits, Allocator>::data () const
  1669. {
  1670.     return length() == 0 ? (charT*) 0 : data_;
  1671. }
  1672.  
  1673. template <class charT, class traits, class Allocator >
  1674. inline basic_string<charT, traits, Allocator>::size_type
  1675. basic_string<charT, traits, Allocator>::length () const
  1676. {
  1677.     return pref()->nchars_;
  1678. }
  1679.  
  1680. template <class charT, class traits, class Allocator >
  1681. void
  1682. basic_string<charT, traits, Allocator>::resize (size_type n)
  1683. {
  1684.     resize(n, eos());
  1685. }
  1686.  
  1687. template <class charT, class traits, class Allocator >
  1688. basic_string<charT, traits, Allocator>::size_type
  1689. basic_string<charT, traits, Allocator>::capacity () const
  1690. {
  1691.     return getCapac();
  1692. }
  1693.  
  1694. template <class charT, class traits, class Allocator >
  1695. inline void basic_string<charT, traits, Allocator>::reserve(size_type res_arg)
  1696. {
  1697.     if (res_arg > getCapac()) clone(res_arg);
  1698. }
  1699.  
  1700. template <class charT, class traits, class Allocator >
  1701. inline basic_string<charT, traits, Allocator>
  1702. basic_string<charT, traits, Allocator>::copy () const
  1703. {
  1704.     basic_string<charT, traits, Allocator> temp(*this); // Make referenced copy
  1705.     temp.clone();   // Make a distinct copy
  1706.     return temp;
  1707. }
  1708.  
  1709. template <class charT, class traits, class Allocator >
  1710. inline basic_string<charT, traits, Allocator>::size_type
  1711. basic_string<charT, traits, Allocator>::find (const charT* s,
  1712.                                               size_type pos,
  1713.                                               size_type n) const
  1714. {
  1715.     return find(basic_string<charT, traits, Allocator>(s, n), pos);
  1716. }
  1717.  
  1718. template <class charT, class traits, class Allocator >
  1719. inline basic_string<charT, traits, Allocator>::size_type
  1720. basic_string<charT, traits, Allocator>::find (const charT* s,
  1721.                                               size_type pos) const
  1722. {
  1723.     return find(basic_string<charT, traits, Allocator>(s), pos);
  1724. }
  1725.  
  1726. template <class charT, class traits, class Allocator >
  1727. inline basic_string<charT, traits, Allocator>::size_type
  1728. basic_string<charT, traits, Allocator>::find (charT c, size_type pos) const
  1729. {
  1730.     return find(basic_string<charT, traits, Allocator>(1, c), pos);
  1731. }
  1732.  
  1733. template <class charT, class traits, class Allocator >
  1734. inline basic_string<charT, traits, Allocator>::size_type
  1735. basic_string<charT, traits, Allocator>::rfind (const charT* s,
  1736.                                                size_type pos,
  1737.                                                size_type n) const
  1738. {
  1739.     return rfind(basic_string<charT, traits, Allocator>(s,n), pos);
  1740. }
  1741.  
  1742. template <class charT, class traits, class Allocator >
  1743. inline basic_string<charT, traits, Allocator>::size_type
  1744. basic_string<charT, traits, Allocator>::rfind (const charT* s, size_type pos)
  1745. const
  1746. {
  1747.     return rfind(basic_string<charT, traits, Allocator>(s), pos);
  1748. }
  1749.  
  1750. template <class charT, class traits, class Allocator >
  1751. inline basic_string<charT, traits, Allocator>::size_type
  1752. basic_string<charT, traits, Allocator>::rfind (charT c, size_type pos) const
  1753. {
  1754.     return rfind(basic_string<charT, traits, Allocator>(1, c), pos);
  1755. }
  1756.  
  1757. template <class charT, class traits, class Allocator >
  1758. inline basic_string<charT, traits, Allocator>::size_type
  1759. basic_string<charT, traits, Allocator>::find_first_of (const charT* s,
  1760.                                                        size_type pos,
  1761.                                                        size_type n) const
  1762. {
  1763.     return find_first_of(basic_string<charT, traits, Allocator>(s, n), pos);
  1764. }
  1765.  
  1766. template <class charT, class traits, class Allocator >
  1767. inline basic_string<charT, traits, Allocator>::size_type
  1768. basic_string<charT, traits, Allocator>::find_first_of (const charT* s,
  1769.                                                        size_type pos) const
  1770. {
  1771.     return find_first_of(basic_string<charT, traits, Allocator>(s), pos);
  1772. }
  1773.  
  1774. template <class charT, class traits, class Allocator >
  1775. inline basic_string<charT, traits, Allocator>::size_type
  1776. basic_string<charT, traits, Allocator>::find_first_of (charT c, size_type pos) const
  1777. {
  1778.     return find_first_of(basic_string<charT, traits, Allocator>(1, c), pos);
  1779. }
  1780.  
  1781. template <class charT, class traits, class Allocator >
  1782. inline basic_string<charT, traits, Allocator>::size_type
  1783. basic_string<charT, traits, Allocator>::find_last_of (const charT* s,
  1784.                                                       size_type pos,
  1785.                                                       size_type n) const
  1786. {
  1787.     return find_last_of(basic_string<charT, traits, Allocator>(s,n), pos);
  1788. }
  1789.  
  1790. template <class charT, class traits, class Allocator >
  1791. inline basic_string<charT, traits, Allocator>::size_type
  1792. basic_string<charT, traits, Allocator>::find_last_of (const charT* s,
  1793.                                                       size_type pos) const
  1794. {
  1795.     return find_last_of(basic_string<charT, traits, Allocator>(s), pos);
  1796. }
  1797.  
  1798. template <class charT, class traits, class Allocator >
  1799. inline basic_string<charT, traits, Allocator>::size_type
  1800. basic_string<charT, traits, Allocator>::find_last_of (charT c, size_type pos)
  1801. const
  1802. {
  1803.     return find_last_of(basic_string<charT, traits, Allocator>(1, c), pos);
  1804. }
  1805.  
  1806. template <class charT, class traits, class Allocator >
  1807. inline basic_string<charT, traits, Allocator>::size_type
  1808. basic_string<charT, traits, Allocator>::find_first_not_of (const charT* s,
  1809.                                                            size_type pos,
  1810.                                                            size_type n) const
  1811. {
  1812.     return find_first_not_of(basic_string<charT,traits,Allocator>(s, n), pos);
  1813. }
  1814.  
  1815. template <class charT, class traits, class Allocator >
  1816. inline basic_string<charT, traits, Allocator>::size_type
  1817. basic_string<charT, traits, Allocator>::find_first_not_of (const charT* s,
  1818.                                                            size_type pos) const
  1819. {
  1820.     return find_first_not_of(basic_string<charT, traits, Allocator>(s), pos);
  1821. }
  1822.  
  1823. template <class charT, class traits, class Allocator >
  1824. inline basic_string<charT, traits, Allocator>::size_type
  1825. basic_string<charT, traits, Allocator>::find_first_not_of (charT c,
  1826.                                                            size_type pos) const
  1827. {
  1828.     return find_first_not_of(basic_string<charT,traits,Allocator>(1, c), pos);
  1829. }
  1830.  
  1831. template <class charT, class traits, class Allocator >
  1832. inline basic_string<charT, traits, Allocator>::size_type
  1833. basic_string<charT, traits, Allocator>::find_last_not_of(const charT* s,
  1834.                                                          size_type pos,
  1835.                                                          size_type n) const
  1836. {
  1837.     return find_last_not_of(basic_string<charT, traits, Allocator>(s,n), pos);
  1838. }
  1839.  
  1840. template <class charT, class traits, class Allocator >
  1841. inline basic_string<charT, traits, Allocator>::size_type
  1842. basic_string<charT, traits, Allocator>::find_last_not_of (const charT* s,
  1843.                                                           size_type pos) const
  1844. {
  1845.     return find_last_not_of(basic_string<charT, traits, Allocator>(s), pos);
  1846. }
  1847.  
  1848. template <class charT, class traits, class Allocator >
  1849. inline basic_string<charT, traits, Allocator>::size_type
  1850. basic_string<charT, traits, Allocator>::find_last_not_of (charT c,
  1851.                                                           size_type pos) const
  1852. {
  1853.     return find_last_not_of(basic_string<charT, traits, Allocator>(1, c), pos);
  1854. }
  1855.  
  1856. template <class charT, class traits, class Allocator >
  1857. inline int
  1858. basic_string<charT, traits, Allocator>::compare (charT* s,
  1859.                                                  size_type pos,
  1860.                                                  size_type n) const
  1861. {
  1862.     return compare(basic_string<charT, traits, Allocator>(s,n), pos);
  1863. }
  1864.  
  1865. template <class charT, class traits, class Allocator >
  1866. inline int
  1867. basic_string<charT, traits, Allocator>::compare (charT* s, size_type pos) const
  1868. {
  1869.     return compare(basic_string<charT, traits, Allocator>(s), pos);
  1870. }
  1871.  
  1872. //
  1873. // Inlined non-member operators
  1874. //
  1875.  
  1876. template <class charT, class traits, class Allocator >
  1877. inline basic_string<charT, traits, Allocator> operator+(
  1878.   const basic_string<charT, traits, Allocator>& lhs,
  1879.   const basic_string<charT, traits, Allocator>& rhs)
  1880. {
  1881.     return basic_string<charT, traits, Allocator>(lhs).append(rhs);
  1882. }
  1883.  
  1884. template <class charT, class traits, class Allocator >
  1885. inline basic_string<charT, traits, Allocator> operator+(
  1886.   const charT*                                  lhs,
  1887.   const basic_string<charT, traits, Allocator>& rhs)
  1888. {
  1889.     return basic_string<charT, traits, Allocator>(lhs).append(rhs);
  1890. }
  1891.  
  1892. template <class charT, class traits, class Allocator >
  1893. inline basic_string<charT, traits, Allocator> operator+(
  1894.   charT lhs, const basic_string<charT, traits, Allocator>& rhs)
  1895. {
  1896.     return basic_string<charT, traits, Allocator>(1,lhs).append(rhs);
  1897. }
  1898.  
  1899. template <class charT, class traits, class Allocator >
  1900. inline basic_string<charT, traits, Allocator> operator+(
  1901.   const basic_string<charT, traits, Allocator>& lhs,
  1902.   const charT*                                  rhs)
  1903. {
  1904.     return basic_string<charT,traits,Allocator>(lhs).append(basic_string<charT, traits, Allocator>(rhs));
  1905. }
  1906.  
  1907. template <class charT, class traits, class Allocator >
  1908. inline basic_string<charT, traits, Allocator> operator+(
  1909.   const basic_string<charT, traits, Allocator>& lhs,
  1910.   charT                                         rhs)
  1911. {
  1912.     return basic_string<charT,traits,Allocator>(lhs).append(basic_string<charT, traits, Allocator>(1,rhs));
  1913. }
  1914.  
  1915. template <class charT, class traits, class Allocator >
  1916. inline bool operator==(
  1917.   const basic_string<charT, traits, Allocator>& lhs,
  1918.   const basic_string<charT, traits, Allocator>& rhs)
  1919. {
  1920.     return lhs.compare(rhs) == 0 ? true : false ;
  1921. }
  1922.  
  1923. template <class charT, class traits, class Allocator >
  1924. inline bool operator==(
  1925.   const charT*                                  lhs,
  1926.   const basic_string<charT, traits, Allocator>& rhs)
  1927. {
  1928.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)==0?true:false;
  1929. }
  1930.  
  1931. template <class charT, class traits, class Allocator >
  1932. inline bool operator==(
  1933.   const basic_string<charT, traits, Allocator>& lhs,
  1934.   const charT*                                  rhs)
  1935. {
  1936.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))==0?true:false;
  1937. }
  1938.  
  1939. template <class charT, class traits, class Allocator >
  1940. inline bool operator<(
  1941.   const basic_string<charT, traits, Allocator>& lhs,
  1942.   const basic_string<charT, traits, Allocator>& rhs)
  1943. {
  1944.     return lhs.compare(rhs) < 0 ? true:false ;
  1945. }
  1946.  
  1947. template <class charT, class traits, class Allocator >
  1948. inline bool operator<(
  1949.   const charT*                                  lhs,
  1950.   const basic_string<charT, traits, Allocator>& rhs)
  1951. {
  1952.     return basic_string<charT,traits,Allocator>(lhs).compare(rhs)<0?true:false;
  1953. }
  1954.  
  1955. template <class charT, class traits, class Allocator >
  1956. inline bool operator<(
  1957.   const basic_string<charT, traits, Allocator>& lhs,
  1958.   const charT*                                  rhs)
  1959. {
  1960.   return lhs.compare(basic_string<charT,traits,Allocator>(rhs))<0?true:false;
  1961. }
  1962.  
  1963. #ifndef RWSTD_NO_PART_SPEC_OVERLOAD
  1964. template <class charT, class traits, class Allocator >
  1965. inline bool operator!=(
  1966.   const basic_string<charT, traits, Allocator>& lhs,
  1967.   const basic_string<charT, traits, Allocator>& rhs)
  1968. {
  1969.     return lhs.compare(rhs) != 0 ? true : false;
  1970. }
  1971. #endif
  1972.  
  1973. template <class charT, class traits, class Allocator >
  1974. inline bool operator!=(
  1975.   const charT*                                  lhs,
  1976.   const basic_string<charT, traits, Allocator>& rhs)
  1977. {
  1978.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)!=0?true:false;
  1979. }
  1980.  
  1981. template <class charT, class traits, class Allocator >
  1982. inline bool operator!=(
  1983.   const basic_string<charT, traits, Allocator>& lhs,
  1984.   const charT*                                  rhs)
  1985. {
  1986.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))!=0?true:false;
  1987. }
  1988.  
  1989. #ifndef RWSTD_NO_PART_SPEC_OVERLOAD
  1990. template <class charT, class traits, class Allocator >
  1991. inline bool operator>(
  1992.   const basic_string<charT, traits, Allocator>& lhs,
  1993.   const basic_string<charT, traits, Allocator>& rhs)
  1994. {
  1995.     return lhs.compare(rhs) > 0 ? true : false;
  1996. }
  1997. #endif
  1998.  
  1999. template <class charT, class traits, class Allocator >
  2000. inline bool operator>(
  2001.   const charT*                                  lhs,
  2002.   const basic_string<charT, traits, Allocator>& rhs)
  2003. {
  2004.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)>0?true:false;
  2005. }
  2006.  
  2007. template <class charT, class traits, class Allocator >
  2008. inline bool operator>(
  2009.   const basic_string<charT, traits, Allocator>& lhs,
  2010.   const charT*                                  rhs)
  2011. {
  2012.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))>0?true:false;
  2013. }
  2014.  
  2015. #ifndef RWSTD_NO_PART_SPEC_OVERLOAD
  2016. template <class charT, class traits, class Allocator >
  2017. inline bool operator<=(
  2018.   const basic_string<charT, traits, Allocator>& lhs,
  2019.   const basic_string<charT, traits, Allocator>& rhs)
  2020. {
  2021.     return lhs.compare(rhs) <= 0 ? true : false;
  2022. }
  2023. #endif
  2024.  
  2025. template <class charT, class traits, class Allocator >
  2026. inline bool operator<=(
  2027.   const charT*                                  lhs,
  2028.   const basic_string<charT, traits, Allocator>& rhs)
  2029. {
  2030.   return basic_string<charT,traits,Allocator>(lhs).compare(rhs)<=0?true:false;
  2031. }
  2032.  
  2033. template <class charT, class traits, class Allocator >
  2034. inline bool operator<=(
  2035.   const basic_string<charT, traits, Allocator>& lhs,
  2036.   const charT*                                  rhs)
  2037. {
  2038.   return lhs.compare(basic_string<charT,traits,Allocator>(rhs))<=0?true:false;
  2039. }
  2040.  
  2041. #ifndef RWSTD_NO_PART_SPEC_OVERLOAD
  2042. template <class charT, class traits, class Allocator >
  2043. inline bool operator>=(
  2044.   const basic_string<charT, traits, Allocator>& lhs,
  2045.   const basic_string<charT, traits, Allocator>& rhs)
  2046. {
  2047.     return lhs.compare(rhs) >= 0 ? true:false;
  2048. }
  2049. #endif
  2050.  
  2051. template <class charT, class traits, class Allocator >
  2052. inline bool operator>=(
  2053.   const charT*                                  lhs,
  2054.   const basic_string<charT, traits, Allocator>& rhs)
  2055. {
  2056.    return basic_string<charT,traits,Allocator>(lhs).compare(rhs)>=0?true:false;
  2057. }
  2058.  
  2059. template <class charT, class traits, class Allocator >
  2060. inline bool operator>=(
  2061.   const basic_string<charT, traits, Allocator>& lhs,
  2062.   const charT*                                  rhs)
  2063. {
  2064.    return lhs.compare(basic_string<charT,traits,Allocator>(rhs))>=0?true:false;
  2065. }
  2066.  
  2067. #ifdef RW_STD_IOSTREAM
  2068.  
  2069. template<class charT, class traits, class IS_traits, class Allocator>
  2070. basic_istream<charT, IS_traits > &
  2071. operator >> (
  2072.   basic_istream<charT, IS_traits >& is,
  2073.   basic_string<charT, traits, Allocator >&  str);
  2074.  
  2075. template<class charT, class traits, class IS_traits, class Allocator>
  2076. basic_ostream<charT, IS_traits > &
  2077. operator << (
  2078.   basic_ostream<charT, IS_traits > &     os,
  2079.   const basic_string<charT, traits, Allocator >& str);
  2080.  
  2081. template<class charT, class IS_traits, class STR_traits, class STR_Alloc>
  2082. basic_istream<charT, IS_traits>&
  2083. getline(
  2084.   basic_istream<charT, IS_traits>&            is,
  2085.   basic_string<charT, STR_traits, STR_Alloc>& str,
  2086.   charT delim
  2087. #if 0
  2088. = IS_traits::newline()
  2089. #endif
  2090. );
  2091.  
  2092. #else
  2093.  
  2094. template<class charT, class traits, class Allocator>
  2095. istream & operator >> (
  2096.   istream & is, basic_string<charT, traits, Allocator > & str);
  2097.  
  2098. template<class charT, class traits, class Allocator>
  2099. ostream& operator << (
  2100.   ostream & os, const basic_string<charT, traits, Allocator > & str);
  2101.  
  2102. #ifdef RWSTD_NO_SPEC_OVERLOAD
  2103. ostream& RWSTDExport operator<< (ostream&, const string&);
  2104. #ifndef RWSTD_NO_WSTR
  2105. ostream& RWSTDExport operator <<(ostream&,wstring&);
  2106. #endif
  2107. #endif
  2108.  
  2109. template<class charT, class traits, class Allocator>
  2110. istream& getline(istream& is,
  2111.           basic_string<charT, traits,Allocator>& str, charT delim);
  2112.  
  2113. #endif
  2114. #ifndef RWSTD_NO_NAMESPACE
  2115. }
  2116. #endif
  2117.  
  2118. #ifdef RWSTD_COMPILE_INSTANTIATE
  2119. #include <string.cc>
  2120. #endif
  2121.  
  2122. #endif  /*defined __STD_STRING*/
  2123.  
  2124. #endif  /* __USING_STD_NAMES__ */
  2125.