| 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 <memory> |
|---|
| 22 | #include <cstring> |
|---|
| 23 | #include <boost/assert.hpp> |
|---|
| 24 | #include <boost/regex/v4/regex_raw_buffer.hpp> |
|---|
| 25 | |
|---|
| 26 | #if defined(BOOST_NO_STDC_NAMESPACE) |
|---|
| 27 | namespace std{ |
|---|
| 28 | using ::memcpy; |
|---|
| 29 | using ::memmove; |
|---|
| 30 | } |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | namespace boost{ namespace re_detail{ |
|---|
| 35 | |
|---|
| 36 | void BOOST_REGEX_CALL raw_storage::resize(size_type n) |
|---|
| 37 | { |
|---|
| 38 | register size_type newsize = start ? last - start : 1024; |
|---|
| 39 | while(newsize < n) |
|---|
| 40 | newsize *= 2; |
|---|
| 41 | register size_type datasize = end - start; |
|---|
| 42 | // extend newsize to WORD/DWORD boundary: |
|---|
| 43 | newsize = (newsize + padding_mask) & ~(padding_mask); |
|---|
| 44 | |
|---|
| 45 | // allocate and copy data: |
|---|
| 46 | register pointer ptr = static_cast<pointer>(::operator new(newsize)); |
|---|
| 47 | BOOST_REGEX_NOEH_ASSERT(ptr) |
|---|
| 48 | std::memcpy(ptr, start, datasize); |
|---|
| 49 | |
|---|
| 50 | // get rid of old buffer: |
|---|
| 51 | ::operator delete(start); |
|---|
| 52 | |
|---|
| 53 | // and set up pointers: |
|---|
| 54 | start = ptr; |
|---|
| 55 | end = ptr + datasize; |
|---|
| 56 | last = ptr + newsize; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void* BOOST_REGEX_CALL raw_storage::insert(size_type pos, size_type n) |
|---|
| 60 | { |
|---|
| 61 | BOOST_ASSERT(pos <= size_type(end - start)); |
|---|
| 62 | if(size_type(last - end) < n) |
|---|
| 63 | resize(n + (end - start)); |
|---|
| 64 | register void* result = start + pos; |
|---|
| 65 | std::memmove(start + pos + n, start + pos, (end - start) - pos); |
|---|
| 66 | end += n; |
|---|
| 67 | return result; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | }} // namespaces |
|---|