1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Minor additions and fixes to the string library.

This commit is contained in:
Sandu Liviu Catalin 2016-02-21 10:30:47 +02:00
parent 1f62e1f88b
commit 3d77dfc508
2 changed files with 50 additions and 3 deletions

View File

@ -249,11 +249,50 @@ CSStr StrToLowercase(CSStr str)
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
CSStr StrToUppercase(CSStr str)
{
Uint32 size = 0;
// See if we actually have something to search for
if(!str || (size = strlen(str)) <= 0)
{
return _SC("");
}
// Obtain a temporary buffer
Buffer b(size);
// Resulted string size
Uint32 n = 0;
// Currently processed character
SQChar c = 0;
// Process characters
while ((c = *(str++)) != 0)
{
// Convert it and move to the next one
b.At< SQChar >(n++) = toupper(c);
}
// End the resulted string
b.At< SQChar >(n) = 0;
// Return the string
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
static CSStr FromArray(Array & arr)
{
Buffer b((arr.Length()+1) * sizeof(SQChar));
arr.GetArray< SQChar >(b.Get< SQChar >(), b.Size< SQChar >());
// Determine array size
const Int32 length = (Int32)arr.Length();
// Obtain a temporary buffer
Buffer b(length * sizeof(Int32));
// Get array elements as integers
arr.GetArray< Int32 >(b.Get< Int32 >(), length);
// Overwrite integers with characters
for (Int32 n = 0; n < length; ++n)
{
b.At< SQChar >(n) = (SQChar)b.At< Int32 >(n);
}
// Terminate the resulted string
b.At< SQChar >(length) = 0;
// Return the string
return b.Get< SQChar >();
}
@ -278,7 +317,10 @@ void Register_String(HSQUIRRELVM vm)
.Overload< CSStr (*)(CSStr, SQChar, Uint32, Uint32) >(_SC("Left"), &LeftStr)
.Overload< CSStr (*)(CSStr, SQChar, Uint32) >(_SC("Right"), &RightStr)
.Overload< CSStr (*)(CSStr, SQChar, Uint32, Uint32) >(_SC("Right"), &RightStr)
.Func(_SC("Center"), &CenterStr);
.Func(_SC("Center"), &CenterStr)
.Func(_SC("JustAlphaNum"), &StrJustAlphaNum)
.Func(_SC("Lowercase"), &StrToLowercase)
.Func(_SC("Uppercase"), &StrToUppercase);
RootTable(vm).Bind(_SC("SqStr"), strns);
RootTable(vm).SquirrelFunc(_SC("printf"), &StdPrintF);

View File

@ -26,6 +26,11 @@ CSStr StrJustAlphaNum(CSStr str);
*/
CSStr StrToLowercase(CSStr str);
/* ------------------------------------------------------------------------------------------------
* Convert the specified string to uppercase.
*/
CSStr StrToUppercase(CSStr str);
} // Namespace:: SqMod
#endif // _LIBRARY_STRING_HPP_