Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 00e8621

Browse files
Merge refactor-syntax_unicode_sort
Conflicts: engine/src/util.cpp
1 parent 245e515 commit 00e8621

22 files changed

+469
-529
lines changed

engine/src/cmds.cpp

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,77 +2432,54 @@ Exec_stat MCSort::sort_container(MCExecPoint &p_exec_point, Chunk_term p_type, S
24322432
}
24332433
#endif /* MCSort::sort_container */
24342434

2435-
void MCSort::additem(MCExecPoint &ep, MCSortnode *&items, uint4 &nitems, Sort_type form, MCString &s, MCExpression *by)
2435+
void MCSort::additem(MCExecContext &ctxt, MCSortnode *items, uint4 &nitems, Sort_type form, MCValueRef p_value, MCExpression *by)
24362436
{
2437+
MCAutoValueRef t_value;
24372438
if (by != NULL)
24382439
{
24392440
MCerrorlock++;
2440-
ep.setsvalue(s);
2441-
MCeach->set(ep);
2442-
if (by->eval(ep) == ES_NORMAL)
2443-
s = ep.getsvalue();
2441+
ctxt.GetEP().setvalueref(p_value);
2442+
MCeach->set(ctxt.GetEP());
2443+
if (by->eval(ctxt.GetEP()) == ES_NORMAL)
2444+
t_value = ctxt.GetEP().getvalueref();
24442445
else
2445-
s = MCnullmcstring;
2446+
t_value = MCValueRetain(kMCEmptyString);
24462447
MCerrorlock--;
24472448
}
2449+
else
2450+
t_value = MCValueRetain(p_value);
2451+
24482452
switch (form)
24492453
{
24502454
case ST_DATETIME:
2451-
ep.setsvalue(s);
2452-
if (MCD_convert(ep, CF_UNDEFINED, CF_UNDEFINED, CF_SECONDS, CF_UNDEFINED))
24532455
{
2454-
if (!MCU_stor8(ep.getsvalue(), items[nitems].nvalue))
2455-
items[nitems].nvalue = -MAXREAL8;
2456+
MCAutoStringRef t_out;
2457+
if (MCD_convert(ctxt, *t_value, CF_UNDEFINED, CF_UNDEFINED, CF_SECONDS, CF_UNDEFINED, &t_out))
2458+
{
2459+
if (ctxt.ConvertToNumber(*t_out, items[nitems].nvalue))
2460+
break;
2461+
}
2462+
2463+
/* UNCHECKED */ MCNumberCreateWithReal(-MAXREAL8, items[nitems].nvalue);
2464+
break;
24562465
}
2457-
else
2458-
items[nitems].nvalue = -MAXREAL8;
2459-
break;
24602466
case ST_NUMERIC:
24612467
{
2462-
const char *sptr = s.getstring();
2463-
uint4 length = s.getlength();
2464-
2465-
// MW-2013-03-21: [[ Bug ]] Make sure we skip any whitespace before the
2466-
// number starts - making it consistent with string->number conversions
2467-
// elsewhere.
2468-
MCU_skip_spaces(sptr, length);
2469-
2470-
// REVIEW - at the moment the numeric prefix of the string is used to
2471-
// derive the sort key e.g. 1000abc would get processed as 1000.
2472-
while (length && (isdigit((uint1)*sptr) ||
2473-
*sptr == '.' || *sptr == '-' || *sptr == '+'))
2474-
{
2475-
sptr++;
2476-
length--;
2477-
}
2478-
s.setlength(s.getlength() - length);
2479-
if (!MCU_stor8(s, items[nitems].nvalue))
2480-
items[nitems].nvalue = -MAXREAL8;
2468+
if (!ctxt.ConvertToNumber(*t_value, items[nitems].nvalue))
2469+
/* UNCHECKED */ MCNumberCreateWithReal(-MAXREAL8, items[nitems].nvalue);
24812470
}
24822471
break;
24832472
default:
2484-
if (ep.getcasesensitive() && by == NULL)
2485-
items[nitems].svalue = (char *)s.getstring();
2473+
if (ctxt.GetCaseSensitive())
2474+
/* UNCHECKED */ ctxt.ConvertToString(*t_value, items[nitems].svalue);
24862475
else
2487-
if (ep.getcasesensitive())
2488-
items[nitems].svalue = s.clone();
2489-
else
2490-
{
2491-
#if defined(_MAC_DESKTOP) || defined(_IOS_MOBILE)
2492-
if (form == ST_INTERNATIONAL)
2493-
{
2494-
extern char *MCSystemLowercaseInternational(const MCString& s);
2495-
items[nitems].svalue = MCSystemLowercaseInternational(s);
2496-
}
2497-
else
2498-
#endif
2499-
2500-
{
2501-
items[nitems].svalue = new char[s.getlength() + 1];
2502-
MCU_lower(items[nitems].svalue, s);
2503-
items[nitems].svalue[s.getlength()] = '\0';
2504-
}
2505-
}
2476+
{
2477+
MCStringRef t_fixed, t_mutable;
2478+
/* UNCHECKED */ ctxt.ConvertToString(*t_value, t_fixed);
2479+
/* UNCHECKED */ MCStringMutableCopyAndRelease(t_fixed, t_mutable);
2480+
/* UNCHECKED */ MCStringLowercase(t_mutable);
2481+
/* UNCHECKED */ MCStringCopyAndRelease(t_fixed, items[nitems].svalue);
2482+
}
25062483
break;
25072484
}
25082485
nitems++;

engine/src/cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class MCSort : public MCStatement
398398
virtual Parse_stat parse(MCScriptPoint &);
399399
virtual Exec_stat exec(MCExecPoint &);
400400
static Exec_stat sort_container(MCExecPoint &p_exec_point, Chunk_term p_type, Sort_type p_direction, Sort_type p_form, MCExpression *p_by);
401-
static void additem(MCExecPoint &ep, MCSortnode *&items, uint4 &nitems, Sort_type form, MCString &s, MCExpression *by);
401+
static void additem(MCExecContext &ctxt, MCSortnode *items, uint4 &nitems, Sort_type form, MCValueRef p_value, MCExpression *by);
402402
virtual void compile(MCSyntaxFactoryRef);
403403
};
404404

0 commit comments

Comments
 (0)