-
Notifications
You must be signed in to change notification settings - Fork 2
/
binarylexeme.cpp
61 lines (43 loc) · 1.74 KB
/
binarylexeme.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "stdafx.h"
#include "binarylexeme.h"
#include "fileprocessing.h"
namespace bpatch
{
using namespace std;
const span<const char>& AbstractBinaryLexeme::Replace(size_t at, size_t alength, unique_ptr<AbstractBinaryLexeme>& awith)
{
auto cBegin = dataSequence_.cbegin();
dataSequence_.erase(cBegin + at, cBegin + at + alength);
cBegin = dataSequence_.cbegin();
dataSequence_.insert(cBegin + at, awith->dataSequence_.cbegin(), awith->dataSequence_.cend());
access_ = span<char>(dataSequence_.data(), dataSequence_.size());
return access_;
}
unique_ptr<AbstractBinaryLexeme> AbstractBinaryLexeme::LexemeFromVector(vector<char>&& asrcVec)
{
return unique_ptr<AbstractBinaryLexeme>(new AbstractBinaryLexeme(move(asrcVec)));
}
inline vector<char> CreateVectorWithData(const char* const pData, const size_t sz)
{
return vector<char>(pData, pData + sz);
}
unique_ptr<AbstractBinaryLexeme> AbstractBinaryLexeme::LexemeFromStringView(const string_view asrc)
{
return LexemeFromVector(CreateVectorWithData(asrc.data(), asrc.size()));
}
unique_ptr<AbstractBinaryLexeme> AbstractBinaryLexeme::LexemeFromSpan(const span<const char> asrc)
{
return LexemeFromVector(CreateVectorWithData(asrc.data(), asrc.size()));
}
unique_ptr<AbstractBinaryLexeme> AbstractBinaryLexeme::LexemeFromLexeme(unique_ptr<AbstractBinaryLexeme>& source, const size_t length)
{
auto& srcSpan = source->access();
const size_t finalSize = srcSpan.size() < length ? srcSpan.size() : length;
return LexemeFromSpan(span<const char>(srcSpan.data(), finalSize));
}
AbstractBinaryLexeme::AbstractBinaryLexeme(vector<char>&& asrcVec)
: dataSequence_(move(asrcVec))
, access_(dataSequence_.data(), dataSequence_.size())
{
}
};// namespace bpatch