libzypp 17.28.8
ByteArray.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_BYTEARRAY_H
10#define ZYPP_BYTEARRAY_H
11
12#include <vector>
13#include <cstring>
14#include <string>
15#include <string_view>
16
17namespace zypp {
18 class ByteArray : public std::vector<char>
19 {
20 public:
21 using vector<char>::vector;
22 explicit ByteArray ( const char *data, const int len = -1 ) : ByteArray( data, data + (len == -1 ? strlen(data) : len) ) { }
23 std::string asString () const {
24 if ( size() == 0 )
25 return std::string();
26 return std::string( data(), size() );
27 }
28
29#ifdef __cpp_lib_string_view
30 std::string_view asStringView () const {
31 if ( size() == 0 )
32 return std::string_view();
33 return std::string_view( data(), size() );
34 }
35#endif
36 };
37
38 class UByteArray : public std::vector<unsigned char>
39 {
40 public:
41 using vector<unsigned char>::vector;
42 explicit UByteArray ( const char *data, const int len = -1 ) : UByteArray( data, data + (len == -1 ? strlen(data) : len) ) { }
43 };
44}
45
46
47#endif
std::string asString() const
Definition: ByteArray.h:23
ByteArray(const char *data, const int len=-1)
Definition: ByteArray.h:22
UByteArray(const char *data, const int len=-1)
Definition: ByteArray.h:42
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2