basic_string_cc.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
11 /***************************************************************************
12  *
13  * string.cc - definitions of the C++ Standard Library string members
14  *
15  * $Id: string.cc 772572 2009-05-07 09:43:22Z faridz $
16  *
17  ***************************************************************************
18  *
19  * Licensed to the Apache Software Foundation (ASF) under one or more
20  * contributor license agreements. See the NOTICE file distributed
21  * with this work for additional information regarding copyright
22  * ownership. The ASF licenses this file to you under the Apache
23  * License, Version 2.0 (the "License"); you may not use this file
24  * except in compliance with the License. You may obtain a copy of
25  * the License at
26  *
27  * http://www.apache.org/licenses/LICENSE-2.0
28  *
29  * Unless required by applicable law or agreed to in writing, software
30  * distributed under the License is distributed on an "AS IS" BASIS,
31  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
32  * implied. See the License for the specific language governing
33  * permissions and limitations under the License.
34  *
35  * Copyright 1994-2008 Rogue Wave Software, Inc.
36  *
37  **************************************************************************
38  *
39  * NOTICE: This File contains modifications made by Bentley Systems Inc. where designated.
40  *
41  *************************************************************************/
42 
43 // *** BENTLEY_CHANGE
45 
46 #ifdef _RWSTD_MSVC
47  // shut up the dumb MSVC warning C4345:
48  // behavior change: an object with POD type constructed with
49  // an initializer of the form () will be default-initialized
50 # pragma warning (push)
51 # pragma warning (disable: 4345)
52 #endif // _RWSTD_MSVC
53 
54 
55 // *** BENTLEY_CHANGE
56 NAMESPACE_BENTLEY_BSTDCXX_BEGIN
57 
58 
59 #ifndef _RWSTD_NO_STATIC_CONST_MEMBER_INIT
60 # if !defined (_RWSTD_MSVC) || _RWSTD_MSVC > 1300
61  // MSVC 7.0 allows initializers for static const integral members
62  // but out-of-line definitions cause multiply defined symbol errors
63  // (see PR #26562)
64 
65 # ifndef _RWSTD_NO_STRING_NPOS_TYPE
66 
67 template <class _CharT, class _Traits, class _Allocator>
70 npos /* = SIZE_MAX */;
71 
72 # else // if defined (_RWSTD_NO_STRING_NPOS_TYPE)
73 
74 template <class _CharT, class _Traits, class _Allocator>
75 const _RWSTD_SIZE_T
77 npos /* = SIZE_MAX */;
78 
79 # endif // _RWSTD_NO_STRING_NPOS_TYPE
80 # endif // MSVC > 7.0
81 #endif // _RWSTD_NO_STATIC_CONST_MEMBER_INIT
82 
83 
84 #ifndef _RWSTD_NO_COLLAPSE_TEMPLATE_STATICS
85 
86 template <class _CharT, class _Traits, class _Allocator>
87 BC__RW::__null_ref<_CharT, _Traits, _Allocator>
89 _C_null_ref;
90 
91 #endif // _RWSTD_NO_COLLAPSE_TEMPLATE_STATICS
92 
93 
94 template <class _CharT, class _Traits, class _Allocator>
97 _C_get_rep (size_type __cap, size_type __len)
98 {
99  if (__cap > max_size ()) {
100  __cap = __len;
101 
102  _RWSTD_REQUIRES (__cap <= max_size (),
103  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
104  _RWSTD_FUNC ("basic_string::_C_get_rep (size_type, "
105  "size_type)"),
106  __cap, max_size ()));
107  }
108 
109  _RWSTD_REQUIRES (__len <= __cap,
110  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
111  _RWSTD_FUNC ("basic_string::_C_get_rep (size_type, "
112  "size_type)"),
113  __len, __cap));
114 
115  if (!__cap) {
116  _RWSTD_ASSERT (!__len);
117  return _C_nullref ();
118  }
119 
120  // allocate, initialize the __string_ref, and initialize each character
121  _C_string_ref_type* const __ret =
122  _RWSTD_STATIC_CAST (_C_string_ref_type*,
123  _RWSTD_STATIC_CAST (void*,
124  _RWSTD_VALUE_ALLOC (_C_value_alloc_type, *this,
125  allocate ( __cap + sizeof (_C_string_ref_type)
126  / sizeof (value_type) + 2))));
127 
128  // avoid copy construction (mutex isn't copy-constructible)
129  // _C_ref_alloc_type (*this).construct (__ret, _C_string_ref_type ());
130  new (__ret) _C_string_ref_type ();
131 
132  // set initial reference count, capacity, and length
133  __ret->_C_init (__cap, __len);
134 
135  _RWSTD_VALUE_ALLOC (_C_value_alloc_type, *this,
136  construct (__ret->data () + __len, value_type ()));
137 
138  return __ret;
139 }
140 
141 
142 template <class _CharT, class _Traits, class _Allocator>
144 basic_string (const basic_string &__s, size_type __pos, size_type __n,
145  const allocator_type& __alloc /* = allocator_type () */)
146  : allocator_type (__alloc)
147 {
148  _RWSTD_REQUIRES (__pos <= __s.size (),
149  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
150  _RWSTD_FUNC ("basic_string::basic_string (const "
151  "basic_string&, size_type, size_type)"),
152  __pos, __s.size ()));
153 
154  size_type __slen = __s.size () - __pos;
155  size_type __rlen = __n < __slen ? __n : __slen;
156  size_type __nlen = __n == npos ? 0 : __n;
157  size_type __maxlen = __nlen > __rlen ? __nlen : __rlen;
158  if (__maxlen)
159  _C_data = _C_get_rep (_C_grow (size_type (), __maxlen),
160  __rlen)->data ();
161  else
162  _C_data = _C_get_rep (__maxlen, __rlen)->data ();
163 
164  traits_type::copy (_C_data, &__s._C_data [__pos], __rlen);
165 }
166 
167 
168 template <class _CharT, class _Traits, class _Allocator>
170 basic_string (size_type __n, value_type __c,
171  const allocator_type &__alloc /* = allocator_type () */)
172  : allocator_type (__alloc)
173 {
174  _RWSTD_REQUIRES (__n <= max_size (),
175  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
176  _RWSTD_FUNC ("basic_string::basic_string (size_type, "
177  "value_type)"),
178  __n, max_size ()));
179 
180  if (__n)
181  _C_data = _C_get_rep (_C_grow (size_type (), __n), __n)->data ();
182  else
183  _C_data = _C_nullref ()->data ();
184 
185  traits_type::assign (_C_data, __n, __c);
186 }
187 
188 
189 template <class _CharT, class _Traits, class _Allocator>
191 basic_string (const_pointer __s, size_type __n,
192  const allocator_type &__alloc /* = allocator_type () */)
193  : allocator_type (__alloc)
194 {
195  // extension: if `s' is 0 then `n' uninitialized elements are allocated
196 
197  _RWSTD_REQUIRES (__n <= max_size (),
198  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
199  _RWSTD_FUNC ("basic_string::basic_string (const_pointer,"
200  "size_type, const allocator_type&)"),
201  __n, max_size ()));
202 
203  _C_data = __n ?
204  _C_get_rep (_C_grow (size_type (), __n), __n)->data ()
205  : _C_nullref ()->data ();
206 
207  if (__s)
208  traits_type::copy (_C_data, __s, __n);
209 }
210 
211 template <class _CharT, class _Traits, class _Allocator>
213 basic_string (const_pointer __s,
214  const allocator_type &__alloc /* = allocator_type () */)
215  : allocator_type (__alloc)
216 {
217  // BENTLEY_CHANGE
218  //_RWSTD_ASSERT (__s != 0);
219  //const size_type __n = traits_type::length (__s);
220  const size_type __n = __s? traits_type::length (__s): 0;
221 
222  _C_data = __n ?
223  _C_get_rep (_C_grow (size_type (), __n), __n)->data ()
224  : _C_nullref ()->data ();
225 
226  traits_type::copy (_C_data, __s, __n);
227 }
228 
229 
230 template <class _CharT, class _Traits, class _Allocator>
232 basic_string (const_pointer __first, const_pointer __last,
233  const allocator_type &__alloc /* = allocator_type () */)
234  : allocator_type (__alloc)
235 {
236  const size_type __n = size_type (__last - __first);
237 
238  _C_data = __n ?
239  _C_get_rep (_C_grow (size_type (), __n), __n)->data ()
240  : _C_nullref ()->data ();
241 
242  traits_type::copy (_C_data, __first, __n);
243 }
244 
245 template <class _CharT, class _Traits, class _Allocator>
248 operator= (const basic_string &__rhs)
249 {
250  if (size_type (0) < size_type (__rhs._C_pref ()->_C_get_ref ())) {
251  // `rhs' has reference counting enabled
252  __rhs._C_pref ()->_C_inc_ref ();
253  _C_unlink (__rhs._C_data);
254  }
255  else if (this != &__rhs)
256  // `rhs' has reference counting disabled
257  replace (size_type (), size (), __rhs.data (), __rhs.size ());
258 
259  return *this;
260 }
261 
262 
263 template <class _CharT, class _Traits, class _Allocator>
266 assign (const basic_string &__str, size_type __pos, size_type __n)
267 {
268  _RWSTD_REQUIRES (__pos <= __str.size (),
269  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
270  _RWSTD_FUNC ("basic_string::assign (basic_string&, "
271  "size_type, size_type)"),
272  __pos, __str.size ()));
273 
274  const size_type __rlen = _C_min (__str.size () - __pos, __n);
275 
276  return replace (size_type (), size (), __str, __pos, __rlen);
277 }
278 
279 
280 template <class _CharT, class _Traits, class _Allocator>
283 insert (size_type __pos1,
284  const basic_string& __str, size_type __pos2, size_type __n)
285 {
286  _RWSTD_REQUIRES (__pos1 <= size () && __pos2 <= __str.size (),
287  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
288  _RWSTD_FUNC ("basic_string::insert (size_type, const "
289  "basic_string&, size_type, size_type)"),
290  __pos1 > size () ? __pos1:__pos2, __str.size ()));
291 
292  const size_type __rlen = _C_min (__str.size () - __pos2, __n);
293 
294  _RWSTD_REQUIRES (size () <= max_size () - __rlen,
295  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
296  _RWSTD_FUNC ("basic_string::insert (size_type, const "
297  "basic_string&, size_type, size_type)"),
298  size (), max_size () - __rlen));
299 
300  return replace (__pos1, size_type (), __str, __pos2, __n);
301 }
302 
303 
304 template <class _CharT, class _Traits, class _Allocator>
307 insert (size_type __pos1, const basic_string &__str)
308 {
309  _RWSTD_REQUIRES (__pos1 <= size (),
310  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
311  _RWSTD_FUNC ("basic_string::insert (size_type, const "
312  "basic_string&)"),
313  __pos1, size ()));
314 
315  _RWSTD_REQUIRES (size () <= max_size () - __str.size (),
316  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
317  _RWSTD_FUNC ("basic_string::insert (size_type, "
318  "const basic_string&)"),
319  size (), max_size () - __str.size ()));
320 
321  return replace (__pos1, size_type (), __str);
322 }
323 
324 
325 template <class _CharT, class _Traits, class _Allocator>
328 replace (size_type __pos1, size_type __n1, const_pointer __s, size_type __n2)
329 {
330  const size_type __size0 = size ();
331 
332  if (npos == __n2)
333  __n2 = traits_type::length (__s);
334 
335  _RWSTD_REQUIRES (__pos1 <= __size0,
336  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
337  _RWSTD_FUNC ("basic_string::replace (size_type, size_type"
338  ", const_pointer, size_type)"),
339  __pos1, __size0 > __n2 ? __size0 : __n2));
340 
341  // number of characters to delete
342  const size_type __xlen = _C_min (__n1, __size0 - __pos1);
343 
344  _RWSTD_REQUIRES (__n2 <= max_size (),
345  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
346  _RWSTD_FUNC ("basic_string::replace (size_type, size_type"
347  ", const_pointer, size_type)"),
348  __n2, max_size ()));
349 
350  _RWSTD_REQUIRES (__size0 - __xlen <= max_size () - __n2,
351  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
352  _RWSTD_FUNC ("basic_string::replace (size_type, size_type"
353  ", const_pointer, size_type)"),
354  __size0 - __xlen, max_size () - __n2));
355 
356  // compute the resulting string size
357  const size_type __size1 = __size0 - __xlen + __n2;
358 
359  if (__size1) {
360 
361  // compute the length of the bit at the end
362  const size_type __rem = __size0 - __xlen - __pos1;
363 
364  // check for shared representation, insufficient capacity,
365  // and overlapping regions
366  if ( size_type (1) < size_type (_C_pref ()->_C_get_ref ())
367  || capacity () < __size1
368  || __s >= data () && __s < data () + __size0) {
369 
370  // Need to allocate a new reference.
371  const size_type __cap = _C_grow (__size0, __size1);
372 
373  const pointer __data = _C_get_rep (__cap, __size1)->data ();
374 
375  traits_type::copy (__data, _C_data, __pos1);
376 
377  traits_type::copy (__data + __pos1, __s, __n2);
378 
379  traits_type::copy (__data + __pos1 + __n2,
380  _C_data + __pos1 + __n1, __rem);
381 
382  _C_unlink (__data);
383  }
384  else {
385  // current reference has enough space
386 
387  const pointer __beg = _C_data + __pos1;
388 
389  traits_type::move (__beg + __n2, __beg + __n1, __rem);
390 
391  traits_type::copy (__beg, __s, __n2);
392 
393  traits_type::assign (_C_data [__size1], value_type ());
394 
395  _C_pref ()->_C_size._C_size = __size1;
396  }
397  }
398  else {
399  // special case a substitution that leaves the string empty.
400  clear ();
401  }
402 
403  return *this;
404 }
405 
406 
407 template <class _CharT, class _Traits, class _Allocator>
410 replace (size_type __pos, size_type __len, size_type __count, value_type __val)
411 {
412  // replaces `len' characters at position `pos'
413  // with `count' copies of the character `val'
414 
415  const size_type __size0 = size ();
416 
417  _RWSTD_REQUIRES (__pos <= __size0,
418  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
419  _RWSTD_FUNC ("basic_string::replace (size_type, "
420  "size_type, size_type, value_type)"),
421  __pos, __size0));
422 
423  const size_type __xlen = _C_min (__size0 - __pos, __len);
424 
425  _RWSTD_REQUIRES (__size0 - __xlen <= max_size () - __count,
426  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
427  _RWSTD_FUNC ("basic_string::replace (size_type, "
428  "size_type, size_type, value_type)"),
429  __size0 - __xlen, max_size () - __count));
430 
431  // compute the resulting string size
432  const size_type __size1 = __size0 - __xlen + __count;
433 
434  if (__size1) {
435 
436  // compute the length of the bit at the end
437  const size_type __rem = __size0 - __xlen - __pos;
438 
439  // check for shared representation, insufficient capacity
440  if ( capacity () < __size1
441  || size_type (1) < size_type (_C_pref ()->_C_get_ref ())) {
442 
443  // need to allocate a new reference
444  const size_type __cap = _C_grow (__size0, __size1);
445 
446  const pointer __data = _C_get_rep (__cap, __size1)->data ();
447 
448  traits_type::copy (__data, _C_data, __pos);
449 
450  traits_type::assign (__data + __pos, __count, __val);
451 
452  traits_type::copy (__data + (__pos + __count),
453  _C_data + (__pos + __len), __rem);
454 
455  _C_unlink (__data);
456  }
457  else {
458  // current reference is not shared and has enough space
459 
460  const pointer __beg = _C_data + __pos;
461 
462  traits_type::move (__beg + __count, __beg + __len, __rem);
463 
464  traits_type::assign (__beg, __count, __val);
465 
466  // append the terminating NUL character
467  traits_type::assign (_C_data [__size1], value_type ());
468 
469  _C_pref ()->_C_size._C_size = __size1;
470  }
471  }
472  else {
473  // special case a substitution that leaves the string empty.
474  clear ();
475  }
476 
477  return *this;
478 }
479 
480 
481 #ifdef _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
482 
483 _EXPORT
484 template <class _CharT, class _Traits, class _Alloc,
485  class _StringIter, class _InputIter>
486 BENTLEY_BSTDCXX::basic_string<_CharT, _Traits, _Alloc>&
487 __rw_replace (basic_string<_CharT, _Traits, _Alloc> &__s,
488  _StringIter __first1, _StringIter __last1,
489  _InputIter __first2, _InputIter __last2) {
490 
491  typedef _Traits traits_type;
492  typedef typename traits_type::char_type value_type;
493  typedef _Alloc allocator_type;
494  typedef typename allocator_type::size_type size_type;
495 
496  typedef basic_string<_CharT, _Traits, _Alloc> _C_string_type;
497 
498  typedef BC__RW::__string_ref<value_type, traits_type, allocator_type>
499  _C_string_ref_type;
500 
501 
502 #else // !defined (_RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES)
503 
504 template<class _CharT, class _Traits, class _Allocator>
505 template<class _InputIter>
508 replace (iterator __first1, iterator __last1,
509  _InputIter __first2, _InputIter __last2, void*)
510 {
511  typedef basic_string _C_string_type;
512 
513  basic_string &__s = *this;
514 
515 #endif // _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
516 
517  _RWSTD_ASSERT_RANGE (__first1,
518  __s._C_make_iter (__s._C_data + __s.size ()));
519  _RWSTD_ASSERT_RANGE (__first1, __last1);
520  _RWSTD_ASSERT_RANGE (__first2, __last2);
521 
522  if (__first2 == __last2) {
523  if (__first1 == __last1)
524  return __s;
525 
526  const size_type __pos = __s._C_off (__first1);
527  const size_type __n = __s._C_off (__first1, __last1);
528  return __s.replace (__pos, __n, size_type (), value_type ());
529  }
530 
531  // use a (probably) faster algorithm if possible
532  if (bc___is_bidirectional_iterator (_RWSTD_ITERATOR_CATEGORY(_InputIter,
533  __last2)))
534  return __s.__replace_aux (__first1, __last1, __first2, __last2);
535 
536  _C_string_type __s3;
537  typename _C_string_type::iterator __first3 = __s3.begin ();
538 
539  for ( ; !(__first2 == __last2); ++__first2, ++__first3) {
540 
541  const size_type __off = __s3._C_off (__first3);
542 
543  _RWSTD_REQUIRES (__off <= __s3.max_size (),
544  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
545  _RWSTD_FUNC ("basic_string::replace (iterator, "
546  "iterator, InputIterator, "
547  "InputIterator)"),
548  __s3._C_off (__first3), __s3.max_size ()));
549 
550  // extend the string if necessary
551  if (__s3.end () == __first3) {
552  // compute the size of new buffer
553  const size_type __cap = __s3._C_grow (__s3.size (), size_type ());
554 
555  // allocate a new buffer
556  _C_string_ref_type *__tmp = __s3._C_get_rep (__cap, __cap);
557 
558  // copy data from old to new, leaving a hole for additions
559  traits_type::copy (__tmp->data (), __s3._C_data, __off);
560  __s3._C_unlink (__tmp->data ());
561  __first3 = __s3._C_make_iter (__s3._C_data + __off);
562  }
563 
564  // copy data over
565  traits_type::assign (*__first3, *__first2);
566  }
567 
568  const size_type __size = __s3._C_off (__first3);
569  traits_type::assign (__s3._C_data [__size], value_type ());
570  __s3._C_pref ()->_C_size._C_size = __size;
571 
572  return __s.__replace_aux (__first1, __last1, __s3.begin (), __s3.end ());
573 }
574 
575 // Special function for random access and bi-directional iterators
576 // Avoids the possibility of multiple allocations
577 // We still have to copy characters over one at a time.
578 
579 #ifdef _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
580 
581 _EXPORT
582 template <class _CharT, class _Traits, class _Alloc,
583  class _StringIter, class _InputIter>
585 __rw_replace_aux (basic_string<_CharT, _Traits, _Alloc> &__s,
586  _StringIter __first1, _StringIter __last1,
587  _InputIter __first2, _InputIter __last2)
588 {
589  typedef _Traits traits_type;
590  typedef typename traits_type::char_type value_type;
591  typedef _Alloc allocator_type;
592  typedef typename allocator_type::size_type size_type;
593  typedef typename allocator_type::difference_type difference_type;
594  typedef typename allocator_type::pointer pointer;
595  typedef typename allocator_type::const_pointer const_pointer;
596  typedef typename allocator_type::const_reference const_reference;
597 
598  typedef BC__RW::__string_ref<value_type, traits_type, allocator_type>
599  _C_string_ref_type;
600 
601 #else // if !defined (_RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES)
602 
603 template<class _CharT, class _Traits, class _Allocator>
604 template<class _InputIter>
607 __replace_aux (iterator __first1, iterator __last1,
608  _InputIter __first2, _InputIter __last2)
609 {
610  basic_string &__s = *this;
611 
612 #endif // _RWSTD_NO_STRING_OUTLINED_MEMBER_TEMPLATES
613 
614  _RWSTD_ASSERT_RANGE (__first1, __s._C_make_iter (__s._C_data
615  + __s.size ()));
616  _RWSTD_ASSERT_RANGE (__first1, __last1);
617  _RWSTD_ASSERT_RANGE (__first2, __last2);
618 
619  const size_type __n2 = BC__DISTANCE (__first2, __last2, size_type);
620  const size_type __n = __s._C_off (__first1, __last1);
621  const size_type __pos = __s._C_off (__first1);
622  const size_type __ssize = __s.size ();
623 
624  _RWSTD_REQUIRES (__pos <= __ssize,
625  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
626  _RWSTD_FUNC ("basic_string::__replace_aux (iterator, "
627  "iterator, InputIterator, InputIterator)"),
628  __pos, __ssize));
629 
630  size_type __slen = __ssize - __pos;
631  size_type __xlen = __n < __slen ? __n : __slen;
632 
633  _RWSTD_REQUIRES (__ssize - __xlen <= __s.max_size () - __n2,
634  std::length_error, (_RWSTD_ERROR_LENGTH_ERROR,
635  _RWSTD_FUNC ("basic_string::__replace_aux (iterator, "
636  "iterator, InputIterator, InputIterator)"),
637  __ssize - __xlen, __s.max_size () - __n2));
638 
639  size_type __len = __ssize - __xlen + __n2; // Final string length.
640 
641  if (!__len) {
642  // Special case a substitution that leaves the string empty.
643  __s._C_unlink (__s._C_nullref ()->data ());
644  }
645  else {
646  size_type __d = 0;
647  // length of bit at the end
648  size_type __rem = __ssize - __xlen - __pos;
649  // Check for shared representation, insufficient capacity
650  if ( __s.capacity () < __len
651  || size_type (1) < size_type (__s._C_pref ()->_C_get_ref ()))
652  {
653  // Need to allocate a new reference.
654  const size_type __cap = __s._C_grow (__ssize, __len);
655 
656  _C_string_ref_type * __temp = __s._C_get_rep (__cap, __len);
657  if (__pos)
658  traits_type::copy (__temp->data (), __s._C_data, __pos);
659  for (__d = 0; __d < __n2; __d++)
660  traits_type::assign (*(__temp->data ()+__pos + __d),
661  *__first2++);
662  if (__rem)
663  traits_type::copy (__temp->data () + __pos + __n2,
664  __s._C_data + __pos + __n, __rem);
665  __s._C_unlink (__temp->data ());
666  }
667  else {
668  // Current reference has enough room.
669  if (__rem)
670  traits_type::move (__s._C_data + __pos + __n2,
671  __s._C_data + __pos + __n,
672  __rem);
673 
674  for (__d = 0; __d < __n2; __d++)
675  traits_type::assign (*(__s._C_data + __pos + __d),
676  *__first2++);
677 
678  __s._C_pref ()->_C_size._C_size = __len;
679  traits_type::assign (__s._C_data [__len], value_type ());
680  }
681  }
682  return __s;
683 }
684 
685 
686 template <class _CharT, class _Traits, class _Allocator>
689 copy (pointer __s, size_type __n, size_type __pos) const
690 {
691  _RWSTD_REQUIRES (__pos <= size (),
692  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
693  _RWSTD_FUNC ("basic_string::copy (pointer, size_type, "
694  "size_type)"),
695  __pos, size ()));
696 
697  const size_type __rlen = _C_min (size () - __pos, __n);
698 
699  traits_type::copy (__s, _C_data + __pos, __rlen);
700 
701  return __rlen;
702 }
703 
704 
705 template <class _CharT, class _Traits, class _Allocator>
708 find (const_pointer __seq, size_type __off, size_type __len) const
709 {
710  const size_type __size = size ();
711 
712  if (__size < __off)
713  return npos;
714 
715  _RWSTD_ASSERT (__seq != 0 || __len == 0);
716 
717  const const_pointer __end = _C_data + __size;
718  const const_pointer __seq_end = __seq + __len;
719 
720  // `first' is set to point to the first occurrence of the first
721  // element of the sought sequence in the controlling sequence
722  // if one exists, otherwise to 0
723  const_pointer __first = const_pointer ();
724 
725  for (const_pointer __next = _C_data + __off; ; __next = __first) {
726 
727  // compute the legth of the rest of the controlling sequene
728  // and break out when it's shorter than the sought sequence
729  const size_type __ext = size_type (__end - __next);
730 
731  if (__ext < __len)
732  break;
733 
734  __first = const_pointer ();
735 
736  for (const_pointer __n = __next, __s = __seq; ; ++__n, ++__s) {
737 
738  if (__seq_end == __s)
739  return size_type (__next - _C_data);
740 
741  if (traits_type::eq (*__n, *__s)) {
742  if (const_pointer () == __first && __n != __next && traits_type::eq (*__n, *__seq))
743  __first = __n;
744  }
745  else {
746  if (const_pointer () == __first) {
747  // look for the first occurrence of the first element
748  // of the sought sequence in the rest of the cotrolling
749  // sequence
750  __first = traits_type::find (__n, __end - __n, *__seq);
751 
752  if (const_pointer () == __first)
753  return npos;
754  }
755  break;
756  }
757  }
758  }
759 
760  return npos;
761 }
762 
763 
764 template <class _CharT, class _Traits, class _Allocator>
767 rfind (const_pointer __s, size_type __pos, size_type __n) const
768 {
769  _RWSTD_ASSERT (__s != 0);
770 
771  if (size () < __n)
772  return npos;
773 
774  size_type __slen = size () - __n;
775  size_type __xpos_start = __slen < __pos ? __slen : __pos;
776 
777  for (size_type __xpos = __xpos_start + 1; __xpos != 0 ; __xpos--) {
778  if (!traits_type::compare (_C_data + __xpos - 1, __s, __n))
779  return __xpos - 1;
780  }
781 
782  return npos;
783 }
784 
785 
786 template <class _CharT, class _Traits, class _Allocator>
789 find_first_of (const_pointer __s, size_type __pos, size_type __n) const
790 {
791  _RWSTD_ASSERT (__s != 0);
792 
793  for (size_type __xpos = __pos; __xpos < size () ; __xpos++) {
794  for (size_type __i = 0; __i < __n ; __i++)
795  if (traits_type::eq (_C_data [__xpos], __s [__i]))
796  return __xpos;
797  }
798 
799  return npos;
800 }
801 
802 
803 template <class _CharT, class _Traits, class _Allocator>
806 find_last_of (const_pointer __s, size_type __pos, size_type __n) const
807 {
808  _RWSTD_ASSERT (__s != 0);
809 
810  if (size ()) {
811  size_type __slen = size () - 1;
812  size_type __xpos_start = __pos < __slen ? __pos : __slen;
813  for (size_type __xpos = __xpos_start+1; __xpos != 0 ; __xpos--) {
814  for (size_type __i = 0; __i < __n ; __i++)
815  if (traits_type::eq (_C_data [__xpos - 1], __s [__i]))
816  return __xpos - 1;
817  }
818  }
819 
820  return npos;
821 }
822 
823 
824 template <class _CharT, class _Traits, class _Allocator>
827 find_first_not_of (const_pointer __s, size_type __pos, size_type __n) const
828 {
829  _RWSTD_ASSERT (__s != 0);
830 
831  for (size_type __xpos = __pos; __xpos < size () ; __xpos++) {
832  bool __found = false;
833  for (size_type __i = 0; __i < __n ; __i++) {
834  if (traits_type::eq (_C_data [__xpos], __s [__i])) {
835  __found = true;
836  break;
837  }
838  }
839  if (!__found)
840  return __xpos;
841  }
842 
843  return npos;
844 }
845 
846 
847 template <class _CharT, class _Traits, class _Allocator>
850 find_last_not_of (const_pointer __s, size_type __pos, size_type __n) const
851 {
852  _RWSTD_ASSERT (__s != 0);
853 
854  if (size ()) {
855  size_type __slen = size () - 1;
856  size_type __xpos_start = __pos < __slen ? __pos : __slen;
857  for (size_type __xpos = __xpos_start + 1; __xpos != 0 ; __xpos--) {
858  bool __found = false;
859  for (size_type __i = 0; __i < __n ; __i++) {
860  if (traits_type::eq (_C_data [__xpos - 1], __s [__i])) {
861  __found = true;
862  break;
863  }
864  }
865  if (!__found)
866  return __xpos - 1;
867  }
868  }
869 
870  return npos;
871 }
872 
873 
874 template <class _CharT, class _Traits, class _Allocator>
877 substr (size_type __pos, size_type __n) const
878 {
879  _RWSTD_REQUIRES (__pos <= size (),
880  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
881  _RWSTD_FUNC ("basic_string::substr (size_type, "
882  "size_type) const"),
883  __pos, size ()));
884 
885  size_type __slen = size () - __pos;
886  size_type __rlen = __n < __slen ? __n : __slen;
887  return basic_string (_C_data + __pos, __rlen);
888 }
889 
890 
891 template <class _CharT, class _Traits, class _Allocator>
893 compare (size_type __pos1, size_type __n1,
894  const basic_string& __str, size_type __pos2, size_type __n2) const
895 {
896  _RWSTD_REQUIRES (__pos2 <= __str.size (),
897  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
898  _RWSTD_FUNC ("basic_string::compare (size_type, "
899  "size_type, const basic_string&, "
900  "size_type, size_type) const"),
901  __pos2, __str.size ()));
902 
903  if (__str.size () - __pos2 < __n2)
904  __n2 = __str.size () - __pos2;
905 
906  return compare (__pos1, __n1, __str.c_str () + __pos2, __n2);
907 }
908 
909 
910 template <class _CharT, class _Traits, class _Allocator>
912 compare (size_type __pos, size_type __n1,
913  const_pointer __s, size_type __n2) const
914 {
915  _RWSTD_REQUIRES (__pos <= size (),
916  std::out_of_range, (_RWSTD_ERROR_OUT_OF_RANGE,
917  _RWSTD_FUNC ("basic_string::compare (size_type, "
918  "size_type, const const_pointer, "
919  "size_type) const"),
920  __pos, size ()));
921 
922  if (size () - __pos < __n1)
923  __n1 = size () - __pos;
924  size_type __rlen = __n1 < __n2 ? __n1 : __n2;
925  int __res = traits_type::compare (_C_data + __pos, __s, __rlen);
926 
927  if (__res == 0)
928  __res = (__n1 < __n2) ? -1 : (__n1 != __n2);
929 
930  return __res;
931 }
932 
933 
934 // *** BENTLEY_CHANGE
935 NAMESPACE_BENTLEY_BSTDCXX_END
936 
937 
938 #ifdef _RWSTD_MSVC
939 # pragma warning (pop)
940 #endif // _RWSTD_MSVC
941 
iterator find(const key_type &__x)
Definition: stdcxx/bstdmap.h:269
basic_string & replace(size_type __pos, size_type __n, const basic_string &__s)
Definition: basic_string.h:516
basic_string & operator=(const basic_string &)
allocator_type::size_type size_type
Definition: basic_string.h:110
const_pointer data() const
Definition: basic_string.h:630
size_type rfind(const basic_string &__str, size_type __pos=npos) const
Definition: basic_string.h:655
iterator _C_make_iter(const pointer &__ptr)
Definition: basic_string.h:125
size_type find_last_not_of(const basic_string &__str, size_type __pos=npos) const
Definition: basic_string.h:731
basic_string copy() const
Definition: basic_string.h:604
int compare(const basic_string &__str) const
basic_string & assign(const basic_string &__str)
Definition: basic_string.h:351
size_type find(const basic_string &__str, size_type __pos=0) const
Definition: basic_string.h:639
size_type find_last_of(const basic_string &__str, size_type __pos=npos) const
Definition: basic_string.h:692
size_type size() const
Definition: basic_string.h:261
size_type capacity() const
Definition: basic_string.h:277
size_type max_size() const
Definition: stdcxx/bstdmap.h:218
basic_string & insert(size_type, const basic_string &)
basic_string(const allocator_type &__alloc=allocator_type())
Definition: basic_string.h:178
size_type find_first_not_of(const basic_string &__str, size_type __pos=0) const
Definition: basic_string.h:711
void clear()
Definition: stdcxx/bstdmap.h:257
A template that has many of the capabilities of std::basic_string.
Definition: basic_string.h:92
size_type max_size() const
const_pointer c_str() const
Definition: basic_string.h:626
size_type size() const
Definition: stdcxx/bstdmap.h:214
size_type find_first_of(const basic_string &__str, size_type __pos=0) const
Definition: basic_string.h:673
basic_string substr(size_type=0, size_type=npos) const

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.