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

[[ Simple Case ]] Add local parameter to toLower & toUpper #6783

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions engine/src/cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,18 @@ Parse_stat MCSort::parse(MCScriptPoint &sp)
case ST_DESCENDING:
direction = (Sort_type)te->which;
break;
case ST_WITH:
if (sp.next(type) != PS_NORMAL ||
sp.lookup(SP_SORT, te) != PS_NORMAL ||
te->which != ST_OPTIONS ||
sp.parseexp(False, True, &(&m_collateoptions)) != PS_NORMAL)
{
MCperror->add
(PE_SORT_BADEXPRESSION, sp);
return PS_ERROR;
}
format = (Sort_type)ST_INTERNATIONAL;
break;
}
}
else
Expand Down Expand Up @@ -1306,6 +1318,13 @@ void MCSort::exec_ctxt(MCExecContext& ctxt)
else
t_object . object = MCdefaultstackptr;

MCAutoArrayRef t_collateoptions;
if (m_collateoptions)
{
if (!ctxt . EvalExprAsArrayRef(*m_collateoptions, EE_SORT_BADOPTIONS, &t_collateoptions))
return;
}

if (chunktype == CT_CARD || chunktype == CT_MARKED)
{
if (t_object . object == nil ||
Expand All @@ -1315,7 +1334,7 @@ void MCSort::exec_ctxt(MCExecContext& ctxt)
return;
}

MCInterfaceExecSortCardsOfStack(ctxt, (MCStack *)t_object . object, direction == ST_ASCENDING, format, by, chunktype == CT_MARKED);
MCInterfaceExecSortCardsOfStack(ctxt, (MCStack *)t_object . object, direction == ST_ASCENDING, format, by, chunktype == CT_MARKED, *t_collateoptions);
}
else if (t_object . object == nil || t_object . object->gettype() == CT_BUTTON)
{
Expand All @@ -1326,7 +1345,7 @@ void MCSort::exec_ctxt(MCExecContext& ctxt)
else
t_sorted_target = MCValueRetain(*t_target);

MCInterfaceExecSortContainer(ctxt, t_sorted_target, chunktype, direction == ST_ASCENDING, format, by);
MCInterfaceExecSortContainer(ctxt, t_sorted_target, chunktype, direction == ST_ASCENDING, format, by, *t_collateoptions);
if (!ctxt . HasError())
of -> set(ctxt, PT_INTO, t_sorted_target);

Expand All @@ -1339,7 +1358,7 @@ void MCSort::exec_ctxt(MCExecContext& ctxt)
ctxt . LegacyThrow(EE_SORT_CANTSORT);
return;
}
MCInterfaceExecSortField(ctxt, t_object, chunktype, direction == ST_ASCENDING, format, by);
MCInterfaceExecSortField(ctxt, t_object, chunktype, direction == ST_ASCENDING, format, by, *t_collateoptions);
}
}

Expand Down
1 change: 1 addition & 0 deletions engine/src/cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ class MCSort : public MCStatement
Sort_type direction;
Sort_type format;
MCExpression *by;
MCAutoPointer<MCExpression> m_collateoptions;
public:
MCSort()
{
Expand Down
16 changes: 8 additions & 8 deletions engine/src/exec-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4129,7 +4129,7 @@ void MCInterfaceExecExportObjectToArray(MCExecContext& ctxt, MCObject *p_object,

////////////////////////////////////////////////////////////////////////////////

bool MCInterfaceExecSortContainer(MCExecContext &ctxt, MCStringRef p_data, int p_type, Sort_type p_direction, int p_form, MCExpression *p_by, MCStringRef &r_output)
bool MCInterfaceExecSortContainer(MCExecContext &ctxt, MCStringRef p_data, int p_type, Sort_type p_direction, int p_form, MCExpression *p_by, MCArrayRef p_collateoptions, MCStringRef &r_output)
{
if (MCStringIsEmpty(p_data))
{
Expand Down Expand Up @@ -4175,7 +4175,7 @@ bool MCInterfaceExecSortContainer(MCExecContext &ctxt, MCStringRef p_data, int p
// of an MCAutoStringRefArray.
MCAutoArray<MCStringRef> t_sorted;
MCStringsExecSort(ctxt, p_direction, (Sort_type)p_form,
*t_chunks, t_item_count, p_by,
*t_chunks, t_item_count, p_by, p_collateoptions,
t_sorted . PtrRef(), t_sorted . SizeRef());

// Build the output string
Expand Down Expand Up @@ -4204,27 +4204,27 @@ bool MCInterfaceExecSortContainer(MCExecContext &ctxt, MCStringRef p_data, int p
}


void MCInterfaceExecSortCardsOfStack(MCExecContext &ctxt, MCStack *p_target, bool p_ascending, int p_format, MCExpression *p_by, bool p_only_marked)
void MCInterfaceExecSortCardsOfStack(MCExecContext &ctxt, MCStack *p_target, bool p_ascending, int p_format, MCExpression *p_by, bool p_only_marked, MCArrayRef p_collateoptions)
{
if (p_target == nil)
p_target = MCdefaultstackptr;

if (!p_target->sort(ctxt, p_ascending ? ST_ASCENDING : ST_DESCENDING, (Sort_type)p_format, p_by, p_only_marked))
if (!p_target->sort(ctxt, p_ascending ? ST_ASCENDING : ST_DESCENDING, (Sort_type)p_format, p_by, p_only_marked, p_collateoptions))
ctxt . LegacyThrow(EE_SORT_CANTSORT);
}

void MCInterfaceExecSortField(MCExecContext &ctxt, MCObjectPtr p_target, int p_chunk_type, bool p_ascending, int p_format, MCExpression *p_by)
void MCInterfaceExecSortField(MCExecContext &ctxt, MCObjectPtr p_target, int p_chunk_type, bool p_ascending, int p_format, MCExpression *p_by, MCArrayRef p_collateoptions)
{
MCField *t_field =(MCField *)p_target . object;
if (t_field->sort(ctxt, p_target . part_id, (Chunk_term)p_chunk_type, p_ascending ? ST_ASCENDING : ST_DESCENDING, (Sort_type)p_format, p_by) != ES_NORMAL)
if (t_field->sort(ctxt, p_target . part_id, (Chunk_term)p_chunk_type, p_ascending ? ST_ASCENDING : ST_DESCENDING, (Sort_type)p_format, p_by, p_collateoptions) != ES_NORMAL)
ctxt . LegacyThrow(EE_SORT_CANTSORT);
}

void MCInterfaceExecSortContainer(MCExecContext &ctxt, MCStringRef& x_target, int p_chunk_type, bool p_ascending, int p_format, MCExpression *p_by)
void MCInterfaceExecSortContainer(MCExecContext &ctxt, MCStringRef& x_target, int p_chunk_type, bool p_ascending, int p_format, MCExpression *p_by, MCArrayRef p_collateoptions)
{
MCAutoStringRef t_sorted_string;

if (MCInterfaceExecSortContainer(ctxt, x_target, p_chunk_type, p_ascending ? ST_ASCENDING : ST_DESCENDING, p_format, p_by, &t_sorted_string))
if (MCInterfaceExecSortContainer(ctxt, x_target, p_chunk_type, p_ascending ? ST_ASCENDING : ST_DESCENDING, p_format, p_by, p_collateoptions, &t_sorted_string))
{
MCValueAssign(x_target, *t_sorted_string);
return;
Expand Down
Loading