Skip to content

Commit bcb7eee

Browse files
committed
Fix 'toString' operations for Array and Enums
1 parent e96d747 commit bcb7eee

File tree

2 files changed

+61
-66
lines changed

2 files changed

+61
-66
lines changed

src/Array.cpp

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ void ArrayBase::EnsureSize(int inSize) const
3636
{
3737
mBase = (char *)hx::GCRealloc(mBase, bytes );
3838
// atomic data not cleared by gc lib ...
39-
#ifndef GC_CLEARS_ALL
40-
#ifndef GC_CLEARS_OBJECTS
39+
#ifndef GC_CLEARS_ALL
40+
#ifndef GC_CLEARS_OBJECTS
4141
if (AllocAtomic())
42-
#endif
43-
memset(mBase + obytes, 0, bytes-obytes);
44-
#endif
42+
#endif
43+
memset(mBase + obytes, 0, bytes-obytes);
44+
#endif
4545
}
4646
else if (AllocAtomic())
4747
{
4848
mBase = (char *)hx::NewGCPrivate(0,bytes);
4949
// atomic data not cleared ...
50-
#ifndef GC_CLEARS_ALL
51-
memset(mBase,0,bytes);
52-
#endif
50+
#ifndef GC_CLEARS_ALL
51+
memset(mBase,0,bytes);
52+
#endif
5353
}
5454
else
55-
{
55+
{
5656
mBase = (char *)hx::NewGCBytes(0,bytes);
57-
#ifndef GC_CLEARS_OBJECTS
58-
memset(mBase,0,bytes);
59-
#endif
60-
}
57+
#ifndef GC_CLEARS_OBJECTS
58+
memset(mBase,0,bytes);
59+
#endif
60+
}
6161
}
6262
length = s;
6363
}
@@ -69,22 +69,13 @@ void ArrayBase::EnsureSize(int inSize) const
6969
String ArrayBase::__ToString() const { return "Array"; }
7070
String ArrayBase::toString()
7171
{
72-
// Byte-array
73-
if (GetElementSize()==1)
72+
// Byte-array (not bool!)
73+
if (IsByteArray())
7474
{
7575
return String( (const char *) mBase, length);
7676
}
7777

78-
int n = __length();
79-
String result(L"[",1);
80-
for(int i=0;i<n;i++)
81-
{
82-
result+=(String)__GetItem(i);
83-
if (i+1<n)
84-
result+=String(L", ",1);
85-
}
86-
result+=String(L"]",1);
87-
return result;
78+
return HX_STR(L"[") + join(HX_STR(L", ")) + HX_STR(L"]");
8879
}
8980

9081
void ArrayBase::__SetSize(int inSize)
@@ -122,14 +113,14 @@ void ArrayBase::Splice(ArrayBase *outResult,int inPos,int inLen)
122113
outResult->__SetSize(0);
123114
return;
124115
}
125-
else if (inPos<0)
126-
{
127-
inPos += length;
128-
if (inPos<0)
129-
inPos =0;
130-
}
131-
if (inLen<0)
132-
return;
116+
else if (inPos<0)
117+
{
118+
inPos += length;
119+
if (inPos<0)
120+
inPos =0;
121+
}
122+
if (inLen<0)
123+
return;
133124
if (inPos+inLen>length)
134125
inLen = length - inPos;
135126

@@ -143,15 +134,15 @@ void ArrayBase::Splice(ArrayBase *outResult,int inPos,int inLen)
143134
void ArrayBase::Slice(ArrayBase *outResult,int inPos,int inEnd)
144135
{
145136
if (inPos<0)
146-
{
147-
inPos += length;
148-
if (inPos<0)
149-
inPos =0;
150-
}
137+
{
138+
inPos += length;
139+
if (inPos<0)
140+
inPos =0;
141+
}
151142
if (inEnd<0)
152-
inEnd += length;
153-
if (inEnd>length)
154-
inEnd = length;
143+
inEnd += length;
144+
if (inEnd>length)
145+
inEnd = length;
155146
int n = inEnd - inPos;
156147
if (n<=0)
157148
outResult->__SetSize(0);
@@ -222,10 +213,10 @@ struct ArrayBase_##func : public hx::Object \
222213
ArrayBase_##func(ArrayBase *inThis) : mThis(inThis) { } \
223214
String toString() const{ return L###func ; } \
224215
String __ToString() const{ return L###func ; } \
225-
int __GetType() const { return vtFunction; } \
226-
void *__GetHandle() const { return mThis; } \
227-
int __ArgCount() const { return ARG_C; } \
228-
void __Mark() { MarkMember(mThis); } \
216+
int __GetType() const { return vtFunction; } \
217+
void *__GetHandle() const { return mThis; } \
218+
int __ArgCount() const { return ARG_C; } \
219+
void __Mark() { MarkMember(mThis); } \
229220
Dynamic __Run(const Array<Dynamic> &inArgs) \
230221
{ \
231222
return mThis->__##func(array_list); return Dynamic(); \
@@ -282,23 +273,23 @@ Dynamic ArrayBase::__Field(const String &inString)
282273

283274

284275
static String sArrayFields[] = {
285-
HX_STRING(L"length",6),
286-
HX_STRING(L"concat",6),
287-
HX_STRING(L"insert",6),
288-
HX_STRING(L"iterator",8),
289-
HX_STRING(L"join",4),
290-
HX_STRING(L"copy",4),
291-
HX_STRING(L"pop",3),
292-
HX_STRING(L"push",4),
293-
HX_STRING(L"remove",6),
294-
HX_STRING(L"reverse",7),
295-
HX_STRING(L"shift",5),
296-
HX_STRING(L"slice",5),
297-
HX_STRING(L"splice",6),
298-
HX_STRING(L"sort",4),
299-
HX_STRING(L"toString",8),
300-
HX_STRING(L"unshift",7),
301-
String(null())
276+
HX_STRING(L"length",6),
277+
HX_STRING(L"concat",6),
278+
HX_STRING(L"insert",6),
279+
HX_STRING(L"iterator",8),
280+
HX_STRING(L"join",4),
281+
HX_STRING(L"copy",4),
282+
HX_STRING(L"pop",3),
283+
HX_STRING(L"push",4),
284+
HX_STRING(L"remove",6),
285+
HX_STRING(L"reverse",7),
286+
HX_STRING(L"shift",5),
287+
HX_STRING(L"slice",5),
288+
HX_STRING(L"splice",6),
289+
HX_STRING(L"sort",4),
290+
HX_STRING(L"toString",8),
291+
HX_STRING(L"unshift",7),
292+
String(null())
302293
};
303294

304295

@@ -309,13 +300,13 @@ Class ArrayBase::__mClass;
309300
Dynamic ArrayCreateEmpty() { return new Array<Dynamic>(0,0); }
310301
Dynamic ArrayCreateArgs(DynamicArray inArgs)
311302
{
312-
return inArgs->__copy();
303+
return inArgs->__copy();
313304
}
314305

315306
void ArrayBase::__boot()
316307
{
317308
Static(__mClass) = RegisterClass(HX_STRING(L"Array",5),TCanCast<ArrayBase>,sNone,sArrayFields,
318-
ArrayCreateEmpty,ArrayCreateArgs,0,0);
309+
ArrayCreateEmpty,ArrayCreateArgs,0,0);
319310
}
320311

321312

@@ -336,7 +327,7 @@ Dynamic ArrayIterator::__Field(const String &inString)
336327

337328
void ArrayIterator::__Mark()
338329
{
339-
MarkMember(mArray);
330+
MarkMember(mArray);
340331
}
341332

342333

src/Enum.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ void EnumBase_obj::__Mark()
3232
MarkMember(mArgs);
3333
}
3434

35-
String EnumBase_obj::toString() { return tag; }
35+
String EnumBase_obj::toString() {
36+
if (mArgs==null() || mArgs->length==0)
37+
return tag;
38+
return tag + HX_STR(L"(") + mArgs->join(HX_STR(L",")) + HX_STR(L")");
39+
}
3640

3741
}
3842

0 commit comments

Comments
 (0)