Isle
Loading...
Searching...
No Matches
mxstring.cpp
Go to the documentation of this file.
1#include "mxstring.h"
2
3#include "decomp.h"
4
5#include <stdlib.h>
6#include <string.h>
7
9
10// FUNCTION: LEGO1 0x100ae200
11// FUNCTION: BETA10 0x1012c110
13{
14 // Set string to one char in length and set that char to null terminator
15 this->m_data = new char[1];
16 this->m_data[0] = 0;
17 this->m_length = 0;
18}
19
20// FUNCTION: LEGO1 0x100ae2a0
21// FUNCTION: BETA10 0x1012c1a1
23{
24 this->m_length = p_str.m_length;
25 this->m_data = new char[this->m_length + 1];
26 strcpy(this->m_data, p_str.m_data);
27}
28
29// FUNCTION: LEGO1 0x100ae350
30// FUNCTION: BETA10 0x1012c24f
31MxString::MxString(const char* p_str)
32{
33 if (p_str) {
34 this->m_length = strlen(p_str);
35 this->m_data = new char[this->m_length + 1];
36 strcpy(this->m_data, p_str);
37 }
38 else {
39 this->m_data = new char[1];
40 this->m_data[0] = 0;
41 this->m_length = 0;
42 }
43}
44
45// FUNCTION: BETA10 0x1012c330
46MxString::MxString(const char* p_str, MxU16 p_maxlen)
47{
48 if (p_str) {
49 if (strlen(p_str) <= p_maxlen) {
50 this->m_length = strlen(p_str);
51 }
52 else {
53 this->m_length = p_maxlen;
54 }
55
56 // Basically strncpy
57 this->m_data = new char[this->m_length + 1];
58 memcpy(this->m_data, p_str, this->m_length);
59 this->m_data[this->m_length] = '\0';
60 }
61 else {
62 this->m_data = new char[1];
63 this->m_data[0] = 0;
64 this->m_length = 0;
65 }
66}
67
68// FUNCTION: LEGO1 0x100ae420
69// FUNCTION: BETA10 0x1012c45b
71{
72 delete[] this->m_data;
73}
74
75// FUNCTION: BETA10 0x1012c4de
77{
78 char* start = this->m_data;
79 char* end = this->m_data + this->m_length - 1;
80
81 while (start < end) {
82 CharSwap(start, end);
83 start++;
84 end--;
85 }
86}
87
88// FUNCTION: LEGO1 0x100ae490
89// FUNCTION: BETA10 0x1012c537
91{
92 strupr(this->m_data);
93}
94
95// FUNCTION: LEGO1 0x100ae4a0
96// FUNCTION: BETA10 0x1012c55c
98{
99 strlwr(this->m_data);
100}
101
102// FUNCTION: LEGO1 0x100ae4b0
103// FUNCTION: BETA10 0x1012c581
105{
106 if (this->m_data != p_str.m_data) {
107 delete[] this->m_data;
108 this->m_length = p_str.m_length;
109 this->m_data = new char[this->m_length + 1];
110 strcpy(this->m_data, p_str.m_data);
111 }
112
113 return *this;
114}
115
116// FUNCTION: LEGO1 0x100ae510
117// FUNCTION: BETA10 0x1012c606
118const MxString& MxString::operator=(const char* p_str)
119{
120 if (this->m_data != p_str) {
121 delete[] this->m_data;
122 this->m_length = strlen(p_str);
123 this->m_data = new char[this->m_length + 1];
124 strcpy(this->m_data, p_str);
125 }
126
127 return *this;
128}
129
130// FUNCTION: BETA10 0x1012c68a
132{
133 MxString tmp;
134 delete[] tmp.m_data;
135
136 tmp.m_length = p_str.m_length + this->m_length;
137 tmp.m_data = new char[tmp.m_length + 1];
138
139 strcpy(tmp.m_data, this->m_data);
140 strcpy(tmp.m_data + this->m_length, p_str.m_data);
141
142 return MxString(tmp);
143}
144
145// Return type is intentionally just MxString, not MxString&.
146// This forces MSVC to add $ReturnUdt$ to the stack for 100% match.
147// FUNCTION: LEGO1 0x100ae580
148// FUNCTION: BETA10 0x1012c78d
149MxString MxString::operator+(const char* p_str) const
150{
151 // MxString constructor allocates 1 byte for m_data, so free that first
152 MxString tmp;
153 delete[] tmp.m_data;
154
155 tmp.m_length = strlen(p_str) + this->m_length;
156 tmp.m_data = new char[tmp.m_length + 1];
157
158 strcpy(tmp.m_data, this->m_data);
159 strcpy(tmp.m_data + this->m_length, p_str);
160
161 return MxString(tmp);
162}
163
164// FUNCTION: LEGO1 0x100ae690
165// FUNCTION: BETA10 0x1012c92f
167{
168 int newlen = this->m_length + strlen(p_str);
169
170 char* tmp = new char[newlen + 1];
171 strcpy(tmp, this->m_data);
172 strcpy(tmp + this->m_length, p_str);
173
174 delete[] this->m_data;
175 this->m_data = tmp;
176 this->m_length = newlen;
177
178 return *this;
179}
180
181// FUNCTION: BETA10 0x1012ca10
182void MxString::CharSwap(char* p_a, char* p_b)
183{
184 char t = *p_a;
185 *p_a = *p_b;
186 *p_b = t;
187}
Mindscape custom string class for managing dynamic C-strings within the game engine.
Definition: mxstring.h:14
static void CharSwap(char *p_a, char *p_b)
Utility to swap the values of two characters.
Definition: mxstring.cpp:182
void ToLowerCase()
Converts the string contents to lowercase in-place.
Definition: mxstring.cpp:97
MxString()
Default constructor which creates an empty string.
Definition: mxstring.cpp:12
void Reverse()
Reverses the contents of the string in-place.
Definition: mxstring.cpp:76
MxString operator+(const MxString &p_str) const
Concatenation operator for two MxString instances.
Definition: mxstring.cpp:131
~MxString() override
Destructor.
Definition: mxstring.cpp:70
void ToUpperCase()
Converts the string contents to uppercase in-place.
Definition: mxstring.cpp:90
MxString & operator=(const MxString &p_str)
Assignment operator from another MxString.
Definition: mxstring.cpp:104
MxString & operator+=(const char *p_str)
Append a C-string to this MxString.
Definition: mxstring.cpp:166
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
unsigned short MxU16
[AI]
Definition: mxtypes.h:20