]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/src/regex_raw_buffer.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / regex / src / regex_raw_buffer.cpp
1 /*
2 *
3 * Copyright (c) 2004
4 * John Maddock
5 *
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 *
10 */
11
12 /*
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE regex_raw_buffer.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Member functions for class raw_storage.
17 */
18
19
20 #define BOOST_REGEX_SOURCE
21 #include <boost/config.hpp>
22 #include <memory>
23 #include <cstring>
24 #include <boost/assert.hpp>
25 #include <boost/regex/v4/regex_raw_buffer.hpp>
26
27 #if defined(BOOST_NO_STDC_NAMESPACE)
28 namespace std{
29 using ::memcpy;
30 using ::memmove;
31 }
32 #endif
33
34
35 namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
36
37 void BOOST_REGEX_CALL raw_storage::resize(size_type n)
38 {
39 size_type newsize = start ? last - start : 1024;
40 while(newsize < n)
41 newsize *= 2;
42 size_type datasize = end - start;
43 // extend newsize to WORD/DWORD boundary:
44 newsize = (newsize + padding_mask) & ~(padding_mask);
45
46 // allocate and copy data:
47 pointer ptr = static_cast<pointer>(::operator new(newsize));
48 BOOST_REGEX_NOEH_ASSERT(ptr)
49 if(start)
50 std::memcpy(ptr, start, datasize);
51
52 // get rid of old buffer:
53 ::operator delete(start);
54
55 // and set up pointers:
56 start = ptr;
57 end = ptr + datasize;
58 last = ptr + newsize;
59 }
60
61 void* BOOST_REGEX_CALL raw_storage::insert(size_type pos, size_type n)
62 {
63 BOOST_ASSERT(pos <= size_type(end - start));
64 if(size_type(last - end) < n)
65 resize(n + (end - start));
66 void* result = start + pos;
67 std::memmove(start + pos + n, start + pos, (end - start) - pos);
68 end += n;
69 return result;
70 }
71
72 }} // namespaces