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

Commit bfad444

Browse files
committed
[[ Cleanup ]] Add MCNameIsEqualTo function
This patch adds an MCNameIsEqualTo function which allows the type of comparison to be specified as a third argument.
1 parent 956e17e commit bfad444

File tree

5 files changed

+62
-59
lines changed

5 files changed

+62
-59
lines changed

engine/src/dskmac.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5580,7 +5580,7 @@ static void MCS_startprocess_launch(MCNameRef name, MCStringRef docname, Open_mo
55805580
if (MCStringGetLength(docname))
55815581
{
55825582
for (i = 0 ; i < MCnprocesses ; i++)
5583-
if (MCNameIsEqualTo(name, MCprocesses[i].name, kMCCompareExact))
5583+
if (MCNameIsEqualTo(name, MCprocesses[i].name, kMCStringOptionCompareExact))
55845584
break;
55855585
if (i == MCnprocesses)
55865586
{

engine/src/mcio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool IO_findstream(Streamnode *p_nodes, uindex_t p_node_count, MCNameRef p_name,
5353
{
5454
while (p_node_count-- > 0)
5555
{
56-
if (MCNameIsEqualTo(p_name, p_nodes[p_node_count].name, kMCCompareExact))
56+
if (MCNameIsEqualTo(p_name, p_nodes[p_node_count].name, kMCStringOptionCompareExact))
5757
{
5858
r_index = p_node_count;
5959
return true;

libfoundation/include/foundation.h

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,55 +2030,6 @@ MC_DLLEXPORT extern MCNumberRef kMCMinusOne;
20302030
#define DBL_INT_MAX (1LL << DBL_MANT_DIG) /* the maximum integer faithfully representable by a double */
20312031
#define DBL_INT_MIN (-DBL_INT_MAX) /* the minimum integer faithfully representable by a double */
20322032

2033-
2034-
////////////////////////////////////////////////////////////////////////////////
2035-
//
2036-
// NAME DEFINITIONS
2037-
//
2038-
2039-
// Like MCSTR but for NameRefs
2040-
MC_DLLEXPORT MCNameRef MCNAME(const char *);
2041-
2042-
// Create a name using the given string.
2043-
MC_DLLEXPORT bool MCNameCreate(MCStringRef string, MCNameRef& r_name);
2044-
// Create a name using chars.
2045-
MC_DLLEXPORT bool MCNameCreateWithChars(const unichar_t *chars, uindex_t count, MCNameRef& r_name);
2046-
// Create a name using native chars.
2047-
MC_DLLEXPORT bool MCNameCreateWithNativeChars(const char_t *chars, uindex_t count, MCNameRef& r_name);
2048-
2049-
// Create a name using the given string, releasing the original.
2050-
MC_DLLEXPORT bool MCNameCreateAndRelease(MCStringRef string, MCNameRef& r_name);
2051-
2052-
// Looks for an existing name matching the given string.
2053-
MC_DLLEXPORT MCNameRef MCNameLookupCaseless(MCStringRef string);
2054-
2055-
// Returns a unsigned integer which can be used to order a table for a binary
2056-
// search.
2057-
MC_DLLEXPORT uintptr_t MCNameGetCaselessSearchKey(MCNameRef name);
2058-
2059-
// Returns the string content of the name.
2060-
MC_DLLEXPORT MCStringRef MCNameGetString(MCNameRef name);
2061-
2062-
// Returns true if the given name is the empty name.
2063-
MC_DLLEXPORT bool MCNameIsEmpty(MCNameRef name);
2064-
2065-
// Returns true if the names are equal (caselessly). Note that MCNameIsEqualTo
2066-
// is *not* the same as MCValueIsEqualTo as it is a comparison up to case (of
2067-
// the name's string) rather than exact.
2068-
MC_DLLEXPORT bool MCNameIsEqualToCaseless(MCNameRef left, MCNameRef right);
2069-
2070-
}
2071-
2072-
bool MCNameIsEqualTo(MCNameRef self, MCNameRef p_other_name, bool p_case_sensitive, bool p_form_sensitive);
2073-
2074-
extern "C" {
2075-
2076-
// The empty name object;
2077-
MC_DLLEXPORT extern MCNameRef kMCEmptyName;
2078-
2079-
MC_DLLEXPORT extern MCNameRef kMCTrueName;
2080-
MC_DLLEXPORT extern MCNameRef kMCFalseName;
2081-
20822033
////////////////////////////////////////////////////////////////////////////////
20832034
//
20842035
// STRING DEFINITIONS
@@ -2767,6 +2718,49 @@ MCStringNormalizeLineEndings(MCStringRef p_input,
27672718
MCStringRef& r_output,
27682719
MCStringLineEndingStyle* r_original_style);
27692720

2721+
////////////////////////////////////////////////////////////////////////////////
2722+
//
2723+
// NAME DEFINITIONS
2724+
//
2725+
2726+
// Like MCSTR but for NameRefs
2727+
MC_DLLEXPORT MCNameRef MCNAME(const char *);
2728+
2729+
// Create a name using the given string.
2730+
MC_DLLEXPORT bool MCNameCreate(MCStringRef string, MCNameRef& r_name);
2731+
// Create a name using chars.
2732+
MC_DLLEXPORT bool MCNameCreateWithChars(const unichar_t *chars, uindex_t count, MCNameRef& r_name);
2733+
// Create a name using native chars.
2734+
MC_DLLEXPORT bool MCNameCreateWithNativeChars(const char_t *chars, uindex_t count, MCNameRef& r_name);
2735+
2736+
// Create a name using the given string, releasing the original.
2737+
MC_DLLEXPORT bool MCNameCreateAndRelease(MCStringRef string, MCNameRef& r_name);
2738+
2739+
// Looks for an existing name matching the given string.
2740+
MC_DLLEXPORT MCNameRef MCNameLookupCaseless(MCStringRef string);
2741+
2742+
// Returns a unsigned integer which can be used to order a table for a binary
2743+
// search.
2744+
MC_DLLEXPORT uintptr_t MCNameGetCaselessSearchKey(MCNameRef name);
2745+
2746+
// Returns the string content of the name.
2747+
MC_DLLEXPORT MCStringRef MCNameGetString(MCNameRef name);
2748+
2749+
// Returns true if the given name is the empty name.
2750+
MC_DLLEXPORT bool MCNameIsEmpty(MCNameRef name);
2751+
2752+
// Returns true if the names are equal under the options specified by options.
2753+
MC_DLLEXPORT bool MCNameIsEqualTo(MCNameRef left, MCNameRef right, MCStringOptions p_options);
2754+
2755+
// Returns true if the names are equal caselessly.
2756+
MC_DLLEXPORT bool MCNameIsEqualToCaseless(MCNameRef left, MCNameRef right);
2757+
2758+
// The empty name object;
2759+
MC_DLLEXPORT extern MCNameRef kMCEmptyName;
2760+
2761+
MC_DLLEXPORT extern MCNameRef kMCTrueName;
2762+
MC_DLLEXPORT extern MCNameRef kMCFalseName;
2763+
27702764
////////////////////////////////////////////////////////////////////////////////
27712765
//
27722766
// DATA DEFINITIONS

libfoundation/src/foundation-array.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,16 @@ static bool __MCArrayFindKeyValueSlot(__MCArray *self, bool p_case_sensitive, MC
999999
}
10001000
else
10011001
{
1002-
if (MCNameIsEqualTo(t_entry -> key, p_key, p_case_sensitive, MCArrayIsFormSensitive(self)))
1002+
MCStringOptions t_options = 0;
1003+
if (p_case_sensitive)
1004+
{
1005+
t_options |= kMCStringOptionFoldBit;
1006+
}
1007+
if (MCArrayIsFormSensitive(self))
1008+
{
1009+
t_options |= kMCStringOptionNormalizeBit;
1010+
}
1011+
if (MCNameIsEqualTo(t_entry -> key, p_key, t_options))
10031012
{
10041013
r_slot = t_probe;
10051014
return true;

libfoundation/src/foundation-name.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,22 @@ bool MCNameIsEqualToCaseless(MCNameRef self, MCNameRef p_other_name)
269269
self -> key == p_other_name -> key;
270270
}
271271

272-
bool MCNameIsEqualTo(MCNameRef self, MCNameRef p_other_name, bool p_case_sensitive, bool p_form_sensitive)
272+
MC_DLLEXPORT_DEF
273+
bool MCNameIsEqualTo(MCNameRef self, MCNameRef p_other_name, MCStringOptions p_options)
273274
{
274275
__MCAssertIsName(self);
275276
__MCAssertIsName(p_other_name);
276277

277278
if (self == p_other_name)
278279
return true;
279280

280-
if (p_case_sensitive && p_form_sensitive)
281+
if (p_options == kMCStringOptionCompareExact)
281282
return false;
282-
else if (!p_case_sensitive && !p_form_sensitive)
283+
284+
if (p_options == kMCStringOptionCompareCaseless)
283285
return self -> key == p_other_name -> key;
284-
else if (p_case_sensitive)
285-
return MCStringIsEqualTo(self -> string, p_other_name -> string, kMCStringOptionCompareNonliteral);
286-
else
287-
return MCStringIsEqualTo(self -> string, p_other_name -> string, kMCStringOptionCompareFolded);
286+
287+
return MCStringIsEqualTo(self -> string, p_other_name -> string, p_options);
288288
}
289289

290290
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)