sources/list.cpp

branch
protocol5
changeset 195
be953e1621d9
parent 191
2e6cbacafdc7
equal deleted inserted replaced
176:060a13878ca0 195:be953e1621d9
1 /* 1 /*
2 Copyright 2016 Teemu Piippo 2 Copyright 2016 - 2021 Teemu Piippo
3 All rights reserved. 3 All rights reserved.
4 4
5 Redistribution and use in source and binary forms, with or without 5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions 6 modification, are permitted provided that the following conditions
7 are met: 7 are met:
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "list.h" 31 #include "list.h"
32 #include "mystring.h"
33 32
34 BEGIN_ZFC_NAMESPACE 33 BEGIN_ZFC_NAMESPACE
35 34
36 /*! 35 /*!
37 * \brief Finds a suitable string representation for the provided byte. 36 * \brief Finds a suitable string representation for the provided byte.
74 return buffer; 73 return buffer;
75 } 74 }
76 } 75 }
77 } 76 }
78 77
79 /*! 78 std::string quote(const std::vector<unsigned char> &bytes)
80 * \brief Constructs a byte array from an initializer list containing bytes. 79 {
81 * \param initializerList List of bytes. 80 std::string result;
82 */
83 ByteArray::ByteArray(std::initializer_list<unsigned char> initializerList) :
84 Vector<unsigned char>(initializerList) {}
85 81
86 /*! 82 for (unsigned char byte : bytes)
87 * \returns a quoted representation of the contents of the byte array.
88 */
89 String ByteArray::quote() const
90 {
91 String result;
92
93 for (unsigned char byte : *this)
94 result += representByte(byte); 83 result += representByte(byte);
95 84
96 return "\"" + result + "\""; 85 return "\"" + result + "\"";
97 } 86 }
98 87

mercurial