Skip to content

Commit d4cf071

Browse files
committed
xrCore/string_concatenations_inline: use size_t for length(xr_string)
Also LPCSTR, const char* -> pcstr LPSTR, char* -> pstr
1 parent d43de2e commit d4cf071

File tree

3 files changed

+56
-59
lines changed

3 files changed

+56
-59
lines changed

src/xrCore/string_concatenations.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ namespace detail
99
{
1010
namespace strconcat_error
1111
{
12-
void process(u32 const index, u32 const count, LPCSTR* strings)
12+
void process(u32 const index, u32 const count, pcstr* strings)
1313
{
1414
u32 const max_string_size = 1024;
15-
LPSTR temp = (LPSTR)_alloca((count * (max_string_size + 4) + 1) * sizeof(**strings));
16-
LPSTR k = temp;
15+
pstr temp = (pstr)_alloca((count * (max_string_size + 4) + 1) * sizeof(**strings));
16+
pstr k = temp;
1717
*k++ = '[';
1818
for (u32 i = 0; i < count; ++i)
1919
{
20-
for (LPCSTR j = strings[i], e = j + max_string_size; *j && j < e; ++k, ++j)
20+
for (pcstr j = strings[i], e = j + max_string_size; *j && j < e; ++k, ++j)
2121
*k = *j;
2222

2323
*k++ = ']';
@@ -36,7 +36,7 @@ void process(u32 const index, u32 const count, LPCSTR* strings)
3636
}
3737

3838
template <u32 count>
39-
static inline void process(LPSTR& i, LPCSTR e, u32 const index, LPCSTR (&strings)[count])
39+
static inline void process(pstr& i, pcstr e, u32 const index, pcstr (&strings)[count])
4040
{
4141
VERIFY(i <= e);
4242
VERIFY(index < count);
@@ -113,17 +113,17 @@ void string_tupples::error_process() const
113113
using namespace xray::core::detail;
114114

115115
// dest = S1+S2
116-
LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2)
116+
pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2)
117117
{
118118
VERIFY(dest);
119119
VERIFY(S1);
120120
VERIFY(S2);
121121

122-
LPCSTR strings[] = {S1, S2};
122+
pcstr strings[] = {S1, S2};
123123

124-
LPSTR i = dest;
125-
LPCSTR e = dest + dest_sz;
126-
LPCSTR j;
124+
pstr i = dest;
125+
pcstr e = dest + dest_sz;
126+
pcstr j;
127127
for (j = S1; *j && i < e; ++i, ++j)
128128
*i = *j;
129129

@@ -140,18 +140,18 @@ LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2)
140140
}
141141

142142
// dest = S1+S2+S3
143-
LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3)
143+
pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3)
144144
{
145145
VERIFY(dest);
146146
VERIFY(S1);
147147
VERIFY(S2);
148148
VERIFY(S3);
149149

150-
LPCSTR strings[] = {S1, S2, S3};
150+
pcstr strings[] = {S1, S2, S3};
151151

152-
LPSTR i = dest;
153-
LPCSTR e = dest + dest_sz;
154-
LPCSTR j;
152+
pstr i = dest;
153+
pcstr e = dest + dest_sz;
154+
pcstr j;
155155
for (j = S1; *j && i < e; ++i, ++j)
156156
*i = *j;
157157

@@ -173,19 +173,19 @@ LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const c
173173
}
174174

175175
// dest = S1+S2+S3+S4
176-
LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4)
176+
pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4)
177177
{
178178
VERIFY(dest);
179179
VERIFY(S1);
180180
VERIFY(S2);
181181
VERIFY(S3);
182182
VERIFY(S4);
183183

184-
LPCSTR strings[] = {S1, S2, S3, S4};
184+
pcstr strings[] = {S1, S2, S3, S4};
185185

186-
LPSTR i = dest;
187-
LPCSTR e = dest + dest_sz;
188-
LPCSTR j;
186+
pstr i = dest;
187+
pcstr e = dest + dest_sz;
188+
pcstr j;
189189
for (j = S1; *j && i < e; ++i, ++j)
190190
*i = *j;
191191

@@ -212,7 +212,7 @@ LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const c
212212
}
213213

214214
// dest = S1+S2+S3+S4+S5
215-
LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4, const char* S5)
215+
pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4, pcstr S5)
216216
{
217217
VERIFY(dest);
218218
VERIFY(S1);
@@ -221,11 +221,11 @@ LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const c
221221
VERIFY(S4);
222222
VERIFY(S5);
223223

224-
LPCSTR strings[] = {S1, S2, S3, S4, S5};
224+
pcstr strings[] = {S1, S2, S3, S4, S5};
225225

226-
LPSTR i = dest;
227-
LPCSTR e = dest + dest_sz;
228-
LPCSTR j;
226+
pstr i = dest;
227+
pcstr e = dest + dest_sz;
228+
pcstr j;
229229
for (j = S1; *j && i < e; ++i, ++j)
230230
*i = *j;
231231

@@ -257,8 +257,8 @@ LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const c
257257
}
258258

259259
// dest = S1+S2+S3+S4+S5+S6
260-
LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4, const char* S5,
261-
const char* S6)
260+
pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4, pcstr S5,
261+
pcstr S6)
262262
{
263263
VERIFY(dest);
264264
VERIFY(S1);
@@ -268,11 +268,11 @@ LPSTR strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const c
268268
VERIFY(S5);
269269
VERIFY(S6);
270270

271-
LPCSTR strings[] = {S1, S2, S3, S4, S5, S6};
271+
pcstr strings[] = {S1, S2, S3, S4, S5, S6};
272272

273-
LPSTR i = dest;
274-
LPCSTR e = dest + dest_sz;
275-
LPCSTR j;
273+
pstr i = dest;
274+
pcstr e = dest + dest_sz;
275+
pcstr j;
276276
for (j = S1; *j && i < e; ++i, ++j)
277277
*i = *j;
278278

src/xrCore/string_concatenations.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@
33

44
#ifndef _EDITOR
55

6-
LPSTR XRCORE_API strconcat(int dest_sz, char* dest, const char* S1, const char* S2);
7-
LPSTR XRCORE_API strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3);
8-
LPSTR XRCORE_API strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4);
9-
LPSTR XRCORE_API strconcat(
10-
int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4, const char* S5);
11-
LPSTR XRCORE_API strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4,
12-
const char* S5, const char* S6);
6+
pstr XRCORE_API strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2);
7+
pstr XRCORE_API strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3);
8+
pstr XRCORE_API strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4);
9+
pstr XRCORE_API strconcat(
10+
int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4, pcstr S5);
11+
pstr XRCORE_API strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4,
12+
pcstr S5, pcstr S6);
1313

1414
#else // _EDITOR
1515
// obsolete: should be deleted as soon borland work correctly with new strconcats
16-
IC char* strconcat(int dest_sz, char* dest, const char* S1, const char* S2)
16+
IC pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2)
1717
{
1818
return xr_strcat(xr_strcpy(dest, dest_sz, S1), dest_sz, S2);
1919
}
2020

2121
// dest = S1+S2+S3
22-
IC char* strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3)
22+
IC pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3)
2323
{
2424
return xr_strcat(xr_strcat(xr_strcpy(dest, dest_sz, S1), dest_sz, S2), dest_sz, S3);
2525
}
2626

2727
// dest = S1+S2+S3+S4
28-
IC char* strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4)
28+
IC pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4)
2929
{
3030
return xr_strcat(xr_strcat(xr_strcat(xr_strcpy(dest, dest_sz, S1), dest_sz, S2), dest_sz, S3), dest_sz, S4);
3131
}
3232

3333
// dest = S1+S2+S3+S4+S5
34-
IC char* strconcat(
35-
int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4, const char* S5)
34+
IC pstr strconcat(
35+
int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4, pcstr S5)
3636
{
3737
return xr_strcat(
3838
xr_strcat(xr_strcat(xr_strcat(xr_strcpy(dest, dest_sz, S1), dest_sz, S2), dest_sz, S3), dest_sz, S4), dest_sz,
3939
S5);
4040
}
4141

4242
// dest = S1+S2+S3+S4+S5+S6
43-
IC char* strconcat(int dest_sz, char* dest, const char* S1, const char* S2, const char* S3, const char* S4,
44-
const char* S5, const char* S6)
43+
IC pstr strconcat(int dest_sz, pstr dest, pcstr S1, pcstr S2, pcstr S3, pcstr S4,
44+
pcstr S5, pcstr S6)
4545
{
4646
return xr_strcat(
4747
xr_strcat(xr_strcat(xr_strcat(xr_strcat(xr_strcpy(dest, dest_sz, S1), dest_sz, S2), dest_sz, S3), dest_sz, S4),
@@ -64,7 +64,7 @@ IC char* strconcat(int dest_sz, char* dest, const char* S1, const char* S2, cons
6464
xray::core::detail::string_tupples STRCONCAT_tupples_unique_identifier(__VA_ARGS__); \
6565
u32 STRCONCAT_buffer_size = STRCONCAT_tupples_unique_identifier.size(); \
6666
xray::core::detail::check_stack_overflow(STRCONCAT_buffer_size); \
67-
(dest) = (LPSTR)_alloca(STRCONCAT_buffer_size); \
67+
(dest) = (pstr)_alloca(STRCONCAT_buffer_size); \
6868
STRCONCAT_tupples_unique_identifier.concat(dest); \
6969
} while (0)
7070

@@ -74,7 +74,7 @@ IC char* strconcat(int dest_sz, char* dest, const char* S1, const char* S2, cons
7474
do \
7575
{ \
7676
xray::core::detail::string_tupples STRCONCAT_tupples_unique_identifier(__VA_ARGS__); \
77-
(dest) = (LPSTR)_alloca(STRCONCAT_tupples_unique_identifier.size()); \
77+
(dest) = (pstr)_alloca(STRCONCAT_tupples_unique_identifier.size()); \
7878
STRCONCAT_tupples_unique_identifier.concat(dest); \
7979
} while (0)
8080

src/xrCore/string_concatenations_inline.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ class XRCORE_API string_tupples
8080
return ((result + 1) * sizeof(*m_strings[0].first));
8181
}
8282

83-
inline void concat(LPCSTR const result) const
83+
inline void concat(pcstr const result) const
8484
{
8585
VERIFY(m_count > 0);
8686

87-
LPSTR i = const_cast<LPSTR>(result);
87+
pstr i = const_cast<pstr>(result);
8888
memcpy(i, m_strings[0].first, m_strings[0].second * sizeof(*m_strings[0].first));
8989
i += m_strings[0].second;
9090

@@ -104,31 +104,28 @@ class XRCORE_API string_tupples
104104
max_item_count = 6,
105105
};
106106

107-
private:
108107
template <u32 index>
109108
struct helper
110109
{
111-
static inline u32 length(LPCSTR string) { return (string ? (unsigned int)xr_strlen(string) : 0); }
112-
static inline LPCSTR string(LPCSTR string) { return (string); }
110+
static inline u32 length(pcstr string) { return (string ? (unsigned int)xr_strlen(string) : 0); }
111+
static inline pcstr string(pcstr string) { return (string); }
113112
static inline u32 length(shared_str const& string) { return (string.size()); }
114-
static inline LPCSTR string(shared_str const& string) { return (string.c_str()); }
115-
static inline u32 length(xr_string const& string) { return (string.size()); }
116-
static inline LPCSTR string(xr_string const& string) { return (string.c_str()); }
113+
static inline pcstr string(shared_str const& string) { return (string.c_str()); }
114+
static inline size_t length(xr_string const& string) { return (string.size()); }
115+
static inline pcstr string(xr_string const& string) { return (string.c_str()); }
117116
template <typename T>
118117
static inline void add_string(string_tupples& self, T p)
119118
{
120119
static_assert(index < max_item_count, "Error invalid string index specified.");
121120

122-
LPCSTR cstr = string(p);
121+
pcstr cstr = string(p);
123122
VERIFY(cstr);
124123
self.m_strings[index] = std::make_pair(cstr, length(p));
125124
}
126125
}; // struct helper
127126

128-
private:
129-
typedef std::pair<LPCSTR, u32> StringPair;
127+
using StringPair = std::pair<pcstr, u32>;
130128

131-
private:
132129
StringPair m_strings[max_item_count];
133130
u32 m_count;
134131
};

0 commit comments

Comments
 (0)