mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-06 14:00:39 +00:00
Moves from using dStrCmp to the new String::compare static functions. Keeps things cleaner, consistent, and works with intellisense.
This commit is contained in:
parent
76c5e30869
commit
c999baf7ed
68 changed files with 168 additions and 144 deletions
|
|
@ -493,7 +493,7 @@ DefineEngineMethod( FileObject, writeObject, void, (const char * simName, const
|
|||
Con::printf("FileObject::writeObject - Invalid Object!");
|
||||
return;
|
||||
}
|
||||
if (!dStrcmp(objName,""))
|
||||
if (!String::compare(objName,""))
|
||||
objName = NULL;
|
||||
|
||||
object->writeObject( obj, (const U8*)objName );
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ StringTableEntry _StringTable::insert(const char* _val, const bool caseSens)
|
|||
U32 key = hashString(val);
|
||||
walk = &buckets[key % numBuckets];
|
||||
while((temp = *walk) != NULL) {
|
||||
if(caseSens && !dStrcmp(temp->val, val))
|
||||
if(caseSens && !String::compare(temp->val, val))
|
||||
return temp->val;
|
||||
else if(!caseSens && !dStricmp(temp->val, val))
|
||||
return temp->val;
|
||||
|
|
@ -175,7 +175,7 @@ StringTableEntry _StringTable::lookup(const char* val, const bool caseSens)
|
|||
U32 key = hashString(val);
|
||||
walk = &buckets[key % numBuckets];
|
||||
while((temp = *walk) != NULL) {
|
||||
if(caseSens && !dStrcmp(temp->val, val))
|
||||
if(caseSens && !String::compare(temp->val, val))
|
||||
return temp->val;
|
||||
else if(!caseSens && !dStricmp(temp->val, val))
|
||||
return temp->val;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
/// pointer mapped to it. As a pointer is an integer value (usually an unsigned int),
|
||||
/// so we can do several neat things:
|
||||
/// - StringTableEntrys can be compared directly for equality, instead of using
|
||||
/// the time-consuming dStrcmp() or dStricmp() function.
|
||||
/// the time-consuming String::compare() or dStricmp() function.
|
||||
/// - For things like object names, we can avoid storing multiple copies of the
|
||||
/// string containing the name. The StringTable ensures that we only ever store
|
||||
/// one copy.
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ char* dStrcpyl(char *dst, dsize_t dstSize, ...)
|
|||
}
|
||||
|
||||
|
||||
S32 dStrcmp( const UTF16 *str1, const UTF16 *str2)
|
||||
S32 dStrcmp(const UTF16 *str1, const UTF16 *str2)
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN)
|
||||
return wcscmp( reinterpret_cast<const wchar_t *>( str1 ), reinterpret_cast<const wchar_t *>( str2 ) );
|
||||
|
|
@ -546,7 +546,7 @@ bool dStrEqual(const char* str1, const char* str2)
|
|||
if (!str1 || !str2)
|
||||
return false;
|
||||
else
|
||||
return (dStrcmp(str1, str2) == 0);
|
||||
return (String::compare(str1, str2) == 0);
|
||||
}
|
||||
|
||||
/// Check if one string starts with another
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ namespace KeyCmp
|
|||
template<>
|
||||
inline bool equals<>( String::StringData* const& d1, String::StringData* const& d2 )
|
||||
{
|
||||
return ( dStrcmp( d1->utf8(), d2->utf8() ) == 0 );
|
||||
return ( String::compare( d1->utf8(), d2->utf8() ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1029,6 +1029,28 @@ S32 String::compare(const String &str, SizeType len, U32 mode) const
|
|||
return compare( str.c_str(), len, mode );
|
||||
}
|
||||
|
||||
S32 String::compare(const char *str1, const char *str2)
|
||||
{
|
||||
return strcmp(str1, str2);
|
||||
}
|
||||
|
||||
S32 String::compare(const UTF16 *str1, const UTF16 *str2)
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
return wcscmp(reinterpret_cast<const wchar_t *>(str1), reinterpret_cast<const wchar_t *>(str2));
|
||||
#else
|
||||
S32 ret;
|
||||
const UTF16 *a, *b;
|
||||
a = str1;
|
||||
b = str2;
|
||||
|
||||
while (((ret = *a - *b) == 0) && *a && *b)
|
||||
a++, b++;
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool String::equal(const String &str, U32 mode) const
|
||||
{
|
||||
if( !mode )
|
||||
|
|
|
|||
|
|
@ -103,6 +103,8 @@ public:
|
|||
*/
|
||||
S32 compare(const StringChar *str, SizeType len = 0, U32 mode = Case|Left) const;
|
||||
S32 compare(const String &str, SizeType len = 0, U32 mode = Case|Left) const; ///< @see compare(const StringChar *, SizeType, U32) const
|
||||
static S32 compare(const char *str1, const char *str2);
|
||||
static S32 compare(const UTF16 *str1, const UTF16 *str2);
|
||||
|
||||
/**
|
||||
Compare two strings for equality.
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ namespace KeyCmp
|
|||
template<>
|
||||
inline bool equals<>( const char * const &keya, const char * const &keyb )
|
||||
{
|
||||
return ( dStrcmp( keya, keyb ) == 0 );
|
||||
return ( String::compare( keya, keyb ) == 0 );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -103,8 +103,8 @@ TEST_FIX(Str, Test1)
|
|||
EXPECT_TRUE( !data.mData || dMemcmp( str.utf16(), data.mUTF16, str.length() * sizeof( UTF16 ) ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || dMemcmp( str16.utf8(), data.mData, str.length() ) == 0 );
|
||||
|
||||
EXPECT_TRUE( !data.mData || dStrcmp( str.utf8(), data.mData ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || dStrcmp( str.utf16(), data.mUTF16 ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || String::compare( str.utf8(), data.mData ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || String::compare( str.utf16(), data.mUTF16 ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue