forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.cpp
27 lines (22 loc) · 845 Bytes
/
Data.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
// Copyright © 2017-2022 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#include "Data.h"
namespace TW {
Data subData(const Data& data, size_t startIndex, size_t length) {
if (startIndex >= data.size()) {
return Data();
}
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()) {
return Data();
}
const size_t subLength = data.size() - startIndex;
return TW::data(data.data() + startIndex, subLength);
}
} // namespace TW