Add #include preprocessing to filamat and matc (#1541)

* Add #include preprocessing to filamat and matc

* Update RELEASE_NOTES

* Fix RELEASE_NOTES

* Use final instead of virtual / override

* Clarify comments

* Use pure virtual for includer functions

* Use a callback instead of an interface

* Rename Includer.h to IncludeCallback.h

* Update comment
This commit is contained in:
Ben Doherty
2019-08-23 11:10:36 -07:00
committed by GitHub
parent 9a47ea1ef0
commit d4943cc70b
21 changed files with 1030 additions and 19 deletions

View File

@@ -18,6 +18,7 @@
#include <utils/compiler.h>
#include <algorithm>
#include <memory>
namespace utils {
@@ -61,4 +62,39 @@ CString& CString::operator=(const CString& rhs) {
return *this;
}
CString& CString::replace(size_type pos, size_type len, const CString& str) noexcept {
assert(pos <= size());
len = std::min(len, size() - pos);
// The new size of the string, after the replacement.
const size_type newSize = size() - len + str.size();
// Allocate enough memory to hold the new string.
Data* p = (Data*) malloc(sizeof(Data) + newSize + 1);
assert(p);
p->length = newSize;
value_type* newStr = (value_type*) (p + 1);
const value_type* beginning = mCStr;
const value_type* replacementStart = mCStr + pos;
const value_type* replacementEnd = replacementStart + len;
const value_type* end = beginning + size();
value_type* ptr = newStr;
ptr = std::uninitialized_copy(beginning, replacementStart, ptr);
ptr = std::uninitialized_copy_n(str.c_str_safe(), str.length(), ptr);
ptr = std::uninitialized_copy(replacementEnd, end, ptr);
// null-terminator
*ptr = 0;
std::swap(mCStr, newStr);
if (newStr) {
free((Data*) newStr - 1);
}
return *this;
}
} // namespace utils