blob: 0006cdbcac90425d8b4e6e3d898be7163a941bdb [file] [log] [blame]
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _MTP_STRING_BUFFER_H
18#define _MTP_STRING_BUFFER_H
19
20#include <log/log.h>
21#include <stdint.h>
22#include <string>
23
24// Max Character number of a MTP String
25#define MTP_STRING_MAX_CHARACTER_NUMBER 255
26
27class MtpDataPacket;
28
29// Represents a utf8 string, with a maximum of 255 characters
30class MtpStringBuffer {
31
32private:
33 std::string mString;
34
35public:
36 MtpStringBuffer() {};
37 ~MtpStringBuffer() {};
38
39 explicit MtpStringBuffer(const char* src);
40 explicit MtpStringBuffer(const uint16_t* src);
41 MtpStringBuffer(const MtpStringBuffer& src);
42
43 void set(const char* src);
44 void set(const uint16_t* src);
45
46 inline void append(const char* other);
47 inline void append(MtpStringBuffer &other);
48
49 bool readFromPacket(MtpDataPacket* packet);
50 void writeToPacket(MtpDataPacket* packet) const;
51
52 inline bool isEmpty() const { return mString.empty(); }
53 inline int size() const { return mString.length(); }
54
55 inline operator const char*() const { return mString.c_str(); }
56};
57
58inline void MtpStringBuffer::append(const char* other) {
59 mString += other;
60}
61
62inline void MtpStringBuffer::append(MtpStringBuffer &other) {
63 mString += other.mString;
64}
65
66#endif // _MTP_STRING_BUFFER_H