mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
Fix ShString.ExchangeString
And add a test.
This commit is contained in:
@@ -45,26 +45,8 @@ static void ExchangeString(void) {
|
||||
int target = getCaliValue();
|
||||
int pat = getCaliValue();
|
||||
int patr = getCaliValue();
|
||||
const char *start = v_str(target -1);
|
||||
const char *next;
|
||||
char dst[STRVAR_LEN] = "";
|
||||
|
||||
v_strReplaceAll(target - 1, pat - 1, patr - 1);
|
||||
DEBUG_COMMAND("ShString.ExchangeString: %d,%d,%d:\n", target, pat, patr);
|
||||
|
||||
if (v_strlen(target -1) == 0 || v_strlen(pat -1) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while(TRUE) {
|
||||
next = strstr(start, v_str(pat -1));
|
||||
if (next == NULL) break;
|
||||
strncat(dst, start, (size_t)(next - start));
|
||||
strncat(dst, v_str(patr -1), sizeof(dst) - strlen(dst));
|
||||
start = next + v_strlen(pat -1);
|
||||
}
|
||||
|
||||
strncat(dst, start, sizeof(dst) - strlen(dst));
|
||||
v_strcpy(target -1, dst);
|
||||
}
|
||||
|
||||
static void SetNum16String(void) { /* 1 */
|
||||
|
||||
@@ -266,6 +266,34 @@ int v_strGetCharType(int no, int pos) {
|
||||
return CHECKSJIS1BYTE(*p) ? 2 : 1;
|
||||
}
|
||||
|
||||
void v_strReplaceAll(int no, int pattern, int replacement) {
|
||||
const char *pat = v_str(pattern);
|
||||
if (!*pat)
|
||||
return;
|
||||
const char *repl = v_str(replacement);
|
||||
|
||||
if (no < 0 || no >= strvar_cnt) {
|
||||
WARNING("string index out of range: %d", no);
|
||||
return;
|
||||
}
|
||||
if (!strVar[no])
|
||||
return;
|
||||
char *src = strVar[no];
|
||||
strVar[no] = NULL;
|
||||
|
||||
char *start = src, *found;;
|
||||
while ((found = strstr(start, pat))) {
|
||||
char bak = *found;
|
||||
*found = '\0';
|
||||
v_strcat(no, start);
|
||||
*found = bak;
|
||||
v_strcat(no, repl);
|
||||
start = found + strlen(pat);
|
||||
}
|
||||
v_strcat(no, start);
|
||||
free(src);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void debug_showvariable() {
|
||||
|
||||
@@ -68,5 +68,6 @@ extern void v_strFromVars(int no, const int *vars);
|
||||
extern int v_strToVars(int no, int *vars);
|
||||
extern const char *v_str(int no);
|
||||
extern int v_strGetCharType(int no, int pos);
|
||||
extern void v_strReplaceAll(int no, int pattern, int replacement);
|
||||
|
||||
#endif /* !__VARIABLE__ */
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
void ExchangeString(IString arg1, IString arg2, IString arg3)
|
||||
void SetNum16String(pword arg1, IString arg2)
|
||||
void SetNum16HalfString(pword arg1, IString arg2)
|
||||
void SetNum32String(pword arg1, IString arg2)
|
||||
void SetNum32HalfString(pword arg1, IString arg2)
|
||||
void GetArrayString(pword arg1, int arg2, IString arg3)
|
||||
void SetWindowTitle(IString arg1, ISys3xSystem arg2)
|
||||
Binary file not shown.
@@ -96,6 +96,7 @@ const word str4 = 13:
|
||||
|
||||
\test_MG7:
|
||||
\test_strFuncs:
|
||||
\test_ShString:
|
||||
|
||||
%0:
|
||||
|
||||
@@ -153,6 +154,15 @@ const word str4 = 13:
|
||||
|
||||
\0:
|
||||
|
||||
*test_ShString:
|
||||
MS str1,"あああああ":
|
||||
MS str2,"ああ":
|
||||
MS str3,"いいい":
|
||||
ShString.ExchangeString str1,str2,str3:
|
||||
MS str4,"いいいいいいあ":
|
||||
~AssertStrEquals str1,str4,__LINE__:
|
||||
\0:
|
||||
|
||||
**MPtoString dst,src,len:
|
||||
MG 100,0:
|
||||
MG 1,dst:
|
||||
|
||||
@@ -3,3 +3,6 @@ test.adv
|
||||
util.adv
|
||||
array.adv
|
||||
strvar.adv
|
||||
|
||||
#DLLHeader
|
||||
ShString.HEL
|
||||
|
||||
Binary file not shown.
+3
-1
@@ -1,3 +1,5 @@
|
||||
ald_basename = test
|
||||
sys_ver = 3.8
|
||||
sys_ver = 3.9
|
||||
hed = test.hed
|
||||
disable_ain_variable = 1
|
||||
disable_ain_message = 1
|
||||
|
||||
Reference in New Issue
Block a user