summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base/ByteArray.cpp')
-rw-r--r--Swiften/Base/ByteArray.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/Swiften/Base/ByteArray.cpp b/Swiften/Base/ByteArray.cpp
index 928e145..c3869fc 100644
--- a/Swiften/Base/ByteArray.cpp
+++ b/Swiften/Base/ByteArray.cpp
@@ -9,6 +9,10 @@
#include <fstream>
std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s) {
+ return operator<<(os, s.getDataVector());
+}
+
+std::ostream& operator<<(std::ostream& os, const std::vector<unsigned char>& s) {
std::ios::fmtflags oldFlags = os.flags();
os << std::hex;
for (Swift::ByteArray::const_iterator i = s.begin(); i != s.end(); ++i) {
@@ -37,4 +41,35 @@ void ByteArray::readFromFile(const std::string& file) {
input.close();
}
+std::vector<unsigned char> ByteArray::create(const std::string& s) {
+ return std::vector<unsigned char>(s.begin(), s.end());
+}
+
+std::vector<unsigned char> ByteArray::create(const char* c) {
+ std::vector<unsigned char> data;
+ while (*c) {
+ data.push_back(static_cast<unsigned char>(*c));
+ ++c;
+ }
+ return data;
+}
+
+std::vector<unsigned char> ByteArray::create(const char* c, size_t n) {
+ std::vector<unsigned char> data;
+ if (n > 0) {
+ data.resize(n);
+ memcpy(&data[0], c, n);
+ }
+ return data;
+}
+
+std::vector<unsigned char> ByteArray::create(const unsigned char* c, size_t n) {
+ std::vector<unsigned char> data;
+ if (n > 0) {
+ data.resize(n);
+ memcpy(&data[0], c, n);
+ }
+ return data;
+}
+
}