-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathData.cpp
More file actions
25 lines (20 loc) · 747 Bytes
/
Data.cpp
File metadata and controls
25 lines (20 loc) · 747 Bytes
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
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
#include "Data.h"
namespace TW {
Data subData(const Data& data, size_t startIndex, size_t length) {
if (startIndex >= data.size()) {
throw std::invalid_argument("invalid subData arguments");
}
const size_t subLength = std::min(length, data.size() - startIndex); // guard against over-length
return TW::data(data.data() + startIndex, subLength);
}
Data subData(const Data& data, size_t startIndex) {
if (startIndex >= data.size()) {
throw std::invalid_argument("invalid subData arguments");
}
const size_t subLength = data.size() - startIndex;
return TW::data(data.data() + startIndex, subLength);
}
} // namespace TW