summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.78.1/src/unc_text.h
blob: 22217f3b9ca9596fd7bf4e3d539e8f9711b0bbf2 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
 * @file unc_text.h
 * A simple class that handles the chunk text.
 * At the start of processing, the entire file is decoded into a std::vector of ints.
 * This class is intended to hold sections of that large std::vector.
 *
 * @author  Ben Gardner
 * @license GPL v2+
 */

#ifndef UNC_TEXT_H_INCLUDED
#define UNC_TEXT_H_INCLUDED

#include "base_types.h"

#include <deque>
#include <string>
#include <vector>


/**
 *  abbreviations used:
 * - unc_text - uncrustify text
 */

class UncText
{
public:
   typedef std::deque<int>      value_type; // double encoded list of int values
   typedef std::vector<UINT8>   log_type;


   UncText();

   UncText(const UncText &ref);

   UncText(const UncText &ref, size_t idx, size_t len = 0);

   UncText(const char *ascii_text);

   UncText(const std::string &ascii_text);

   UncText(const value_type &data, size_t idx = 0, size_t len = 0);


   ~UncText() = default;


   void resize(size_t new_size);


   void clear();


   //! grab the number of characters
   size_t size() const;


   void set(int ch);

   void set(const UncText &ref);

   void set(const UncText &ref, size_t idx, size_t len = 0);

   void set(const std::string &ascii_text);

   void set(const char *ascii_text);

   void set(const value_type &data, size_t idx = 0, size_t len = 0);


   UncText &operator=(int ch);

   UncText &operator=(const UncText &ref);

   UncText &operator=(const std::string &ascii_text);

   UncText &operator=(const char *ascii_text);


   void insert(size_t idx, int ch);

   void insert(size_t idx, const UncText &ref);


   void erase(size_t idx, size_t len = 1);


   //! Add a unc_text character to an unc_text
   void append(int ch);

   void append(const UncText &ref);

   //! Add a string to an unc_text
   void append(const std::string &ascii_text);

   /**
    * Add a variable length string to an unc_text.
    * The variable length string format is similar as for printf
    *
    * @note the overall length of the string must not exceed 256 characters
    *
    *	@param ascii_text  a variable length string
    */
   void append(const char *ascii_text);

   void append(const value_type &data, size_t idx = 0, size_t len = 0);


   UncText &operator+=(int ch);

   UncText &operator+=(const UncText &ref);

   UncText &operator+=(const std::string &ascii_text);

   UncText &operator+=(const char *ascii_text);


   //! Returns the UTF-8 string for logging
   const char *c_str() const;


   /**
    * compares the content of two unc_text instances
    *
    * @param ref1  first  instance to compare
    * @param ref2  second instance to compare
    * @param len   number of character to compare
    * @param tcare take care of case (lower case/ upper case)                  Issue #2091
    *
    * @retval == 0  both text elements are equal
    * @retval  > 0
    * @retval  < 0
    */
   static int compare(const UncText &ref1, const UncText &ref2, size_t len = 0, bool tcare = false);


   bool equals(const UncText &ref) const;


   //! grab the data as a series of ints for outputting to a file
   const value_type &get() const;


   int operator[](size_t idx) const;


   // throws an exception if out of bounds
   const int &at(size_t idx) const;
   int &at(size_t idx);


   //! returns the last element of the character list
   const int &back() const;


   void push_back(int ch);


   void pop_back();


   void pop_front();


   bool startswith(const UncText &text, size_t idx = 0) const;

   bool startswith(const char *text, size_t idx = 0) const;


   /**
    * look for 'text', beginning with position 'idx'
    *
    * @param text  text to search for
    * @param idx   position to start search
    *
    * @return == -1 if not found
    * @return >=  0 the position
    */
   int find(const char *text, size_t idx = 0) const;


   int rfind(const char *text, size_t idx = 0) const;


   int replace(const char *oldtext, const UncText &newtext);


protected:
   void update_logtext();

   value_type m_chars;           //! this contains the non-encoded 31-bit chars
   log_type   m_logtext;         //! logging text, utf8 encoded - updated in c_str()
};


#endif /* UNC_TEXT_H_INCLUDED */