~aleteoryx/muditaos

ref: 2276ceed679b93a3a891e4f5739ade9e13991c5a muditaos/module-utils/ucs2/UCS2.hpp -rw-r--r-- 2.1 KiB
2276ceed — Radoslaw Wicik [EGD-3743] Update copyrights in fies 5 years ago
                                                                                
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * UCS2.hpp
 *
 *  Created on: 24 wrz 2019
 *      Author: kuba
 */

#ifndef MODULE_UTILS_UCS2_UCS2_HPP_
#define MODULE_UTILS_UCS2_UCS2_HPP_

#include <cstdint>
#include "utf8/UTF8.hpp"

class UCS2
{
  private:
    // pointer to memory where ucs2 characters are stored.
    uint16_t *buffer = nullptr;
    // size in bytes of memory that was allcated to the buffer
    uint32_t sizeAllocated = 0;
    // size in bytes of memory used in buffer
    uint32_t sizeUsed = 0;
    // number of characters in the string. its equal to size of allocated memory plus null terminator
    uint32_t length = 0;
    //
    static const uint32_t ucs2bufferExt;
    void clear(void);

  public:
    // default constructor
    UCS2(void);
    //
    //    UCS2( uint16_t* text);
    /*
     * @brief Initializes new ucs2 string from utf8 string. It's used to convert text from
     * utf8 to ucs2.
     * @param string utf8 string to convert
     */
    UCS2(const UTF8 &string);
    /*
     * @brief Initializes new ucs2 string from std::string. It's used to convert text from
     * modem message format to ucs2.
     * @param string std::string to convert
     */
    UCS2(const std::string &string);
    UCS2(UCS2 &ucs);
    ~UCS2(void);
    const char *c_str(void)
    {
        return reinterpret_cast<const char *>(buffer);
    }
    /*
     * @brief It's converting ucs2 to utf string.
     * @return utf8 string
     */
    UTF8 toUTF8(void);
    void append(const uint16_t &ucs2char);
    /*
     * @brief It's converting text coded in ucs2 to string. Used to send data to modem.
     * @return coded string
     */
    std::string modemStr(void);
    uint32_t getLength(void)
    {
        return length;
    };
    uint32_t getSizeUsed(void)
    {
        return sizeUsed;
    };
    uint32_t getSizeAlocated(void)
    {
        return sizeAllocated;
    };
    uint16_t *getData(void)
    {
        return buffer;
    };
};

#endif /* MODULE_UTILS_UCS2_UCS2_HPP_ */