mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Combined tolower/toupper in previous commit to "string_to_case"
This commit is contained in:
@@ -323,10 +323,10 @@
|
|||||||
#define string_compare(str1, str2) sfall_func2("string_compare", str1, str2)
|
#define string_compare(str1, str2) sfall_func2("string_compare", str1, str2)
|
||||||
#define string_compare_locale(str1, str2, codePage) sfall_func3("string_compare", str1, str2, codePage)
|
#define string_compare_locale(str1, str2, codePage) sfall_func3("string_compare", str1, str2, codePage)
|
||||||
#define string_format(format, a1, a2) sfall_func3("string_format", format, a1, a2)
|
#define string_format(format, a1, a2) sfall_func3("string_format", format, a1, a2)
|
||||||
|
#define string_tolower(text) sfall_func2("string_to_case", text, 0)
|
||||||
|
#define string_toupper(text) sfall_func2("string_to_case", text, 1)
|
||||||
#define tile_by_position(x, y) sfall_func2("tile_by_position", x, y)
|
#define tile_by_position(x, y) sfall_func2("tile_by_position", x, y)
|
||||||
#define tile_refresh_display sfall_func0("tile_refresh_display")
|
#define tile_refresh_display sfall_func0("tile_refresh_display")
|
||||||
#define tolower(text) sfall_func1("tolower", text)
|
|
||||||
#define toupper(text) sfall_func1("toupper", text)
|
|
||||||
#define unjam_lock(obj) sfall_func1("unjam_lock", obj)
|
#define unjam_lock(obj) sfall_func1("unjam_lock", obj)
|
||||||
#define unset_unique_id(obj) sfall_func2("set_unique_id", obj, -1)
|
#define unset_unique_id(obj) sfall_func2("set_unique_id", obj, -1)
|
||||||
#define unwield_slot(critter, slot) sfall_func2("unwield_slot", critter, slot)
|
#define unwield_slot(critter, slot) sfall_func2("unwield_slot", critter, slot)
|
||||||
|
|||||||
@@ -697,13 +697,9 @@ optional argument:
|
|||||||
- returns the tile number at the x, y position relative to the top-left corner of the screen
|
- returns the tile number at the x, y position relative to the top-left corner of the screen
|
||||||
- if the position is outside of the range of tiles, it will return -1
|
- if the position is outside of the range of tiles, it will return -1
|
||||||
|
|
||||||
> string sfall_func1("tolower", string text)
|
> string sfall_func2("string_to_case", string text, int toCase)
|
||||||
- converts all uppercase letters in the given string to lowercase
|
- converts all letters in the given string to the specified case
|
||||||
- returns -1 on argument error
|
- toCase: 0 - lowercase, 1 - uppercase
|
||||||
|
|
||||||
> string sfall_func1("toupper", string text)
|
|
||||||
- converts all lowercase letters in the given string to uppercase
|
|
||||||
- returns -1 on argument error
|
|
||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
------ MORE INFO -------
|
------ MORE INFO -------
|
||||||
|
|||||||
@@ -134,10 +134,9 @@ static const SfallMetarule metarules[] = {
|
|||||||
{"spatial_radius", sf_spatial_radius, 1, 1, 0, {ARG_OBJECT}},
|
{"spatial_radius", sf_spatial_radius, 1, 1, 0, {ARG_OBJECT}},
|
||||||
{"string_compare", sf_string_compare, 2, 3, 0, {ARG_STRING, ARG_STRING, ARG_INT}},
|
{"string_compare", sf_string_compare, 2, 3, 0, {ARG_STRING, ARG_STRING, ARG_INT}},
|
||||||
{"string_format", sf_string_format, 2, 5, 0, {ARG_STRING, ARG_ANY, ARG_ANY, ARG_ANY, ARG_ANY}},
|
{"string_format", sf_string_format, 2, 5, 0, {ARG_STRING, ARG_ANY, ARG_ANY, ARG_ANY, ARG_ANY}},
|
||||||
|
{"string_to_case", sf_string_to_case, 2, 2, -1, {ARG_STRING, ARG_INT}},
|
||||||
{"tile_by_position", sf_tile_by_position, 2, 2, -1, {ARG_INT, ARG_INT}},
|
{"tile_by_position", sf_tile_by_position, 2, 2, -1, {ARG_INT, ARG_INT}},
|
||||||
{"tile_refresh_display", sf_tile_refresh_display, 0, 0},
|
{"tile_refresh_display", sf_tile_refresh_display, 0, 0},
|
||||||
{"tolower", sf_tolower, 1, 1, -1, {ARG_STRING}},
|
|
||||||
{"toupper", sf_toupper, 1, 1, -1, {ARG_STRING}},
|
|
||||||
{"unjam_lock", sf_unjam_lock, 1, 1, -1, {ARG_OBJECT}},
|
{"unjam_lock", sf_unjam_lock, 1, 1, -1, {ARG_OBJECT}},
|
||||||
{"unwield_slot", sf_unwield_slot, 2, 2, -1, {ARG_OBJECT, ARG_INT}},
|
{"unwield_slot", sf_unwield_slot, 2, 2, -1, {ARG_OBJECT, ARG_INT}},
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|||||||
@@ -466,29 +466,16 @@ void sf_get_text_width(OpcodeContext& ctx) {
|
|||||||
ctx.setReturn(fo::GetTextWidth(ctx.arg(0).strValue()));
|
ctx.setReturn(fo::GetTextWidth(ctx.arg(0).strValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* cstrdup(const char* str) {
|
static std::string strToCase;
|
||||||
size_t len = strlen(str);
|
|
||||||
const size_t bufMaxLen = ScriptExtender::TextBufferSize() - 1;
|
|
||||||
if (len > bufMaxLen) len = bufMaxLen;
|
|
||||||
|
|
||||||
if (len) memcpy(ScriptExtender::gTextBuffer, str, len);
|
void sf_string_to_case(OpcodeContext& ctx) {
|
||||||
ScriptExtender::gTextBuffer[len] = '\0';
|
strToCase = ctx.arg(0).strValue();
|
||||||
|
if (ctx.arg(1).rawValue())
|
||||||
|
std::transform(strToCase.begin(), strToCase.end(), strToCase.begin(), ::toupper);
|
||||||
|
else
|
||||||
|
std::transform(strToCase.begin(), strToCase.end(), strToCase.begin(), ::tolower);
|
||||||
|
|
||||||
return ScriptExtender::gTextBuffer;
|
ctx.setReturn(strToCase.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
void sf_tolower(OpcodeContext& ctx) {
|
|
||||||
auto str = std::string(ctx.arg(0).strValue());
|
|
||||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
|
||||||
|
|
||||||
ctx.setReturn(cstrdup(str.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void sf_toupper(OpcodeContext& ctx) {
|
|
||||||
auto str = std::string(ctx.arg(0).strValue());
|
|
||||||
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
|
|
||||||
|
|
||||||
ctx.setReturn(cstrdup(str.c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,7 @@ void sf_get_string_pointer(OpcodeContext&);
|
|||||||
|
|
||||||
void sf_get_text_width(OpcodeContext&);
|
void sf_get_text_width(OpcodeContext&);
|
||||||
|
|
||||||
void sf_tolower(OpcodeContext&);
|
void sf_string_to_case(OpcodeContext&);
|
||||||
|
|
||||||
void sf_toupper(OpcodeContext&);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user