Refectoring: Add is_[12]byte_message() helper functions

This commit is contained in:
kichikuou
2020-12-20 14:44:08 +09:00
parent 33a0595016
commit 067e1e23bd
8 changed files with 23 additions and 19 deletions
+8
View File
@@ -65,6 +65,14 @@ inline void strcpy_s(char* dst, size_t n, const char* src)
#endif // !WIN32
static inline bool is_1byte_message(uint8_t c) {
return c == ' ' || (0xa1 <= c && c <= 0xdd);
}
static inline bool is_2byte_message(uint8_t c) {
return (0x81 <= c && c <= 0x9f) || 0xe0 <= c;
}
// resource.cpp
SDL_RWops* open_resource(const char* name, const char* type);
+1 -1
View File
@@ -128,7 +128,7 @@ void FILEIO::Fgets(char *dest, int length)
if(p < length + 1) {
dest[p++] = c;
}
if((0x81 <= c && c <= 0x9f) || 0xe0 <= c) {
if(is_2byte_message(c)) {
if(p < length + 1) {
dest[p++] = Fgetc();
}
+1 -1
View File
@@ -40,7 +40,7 @@ void AGS::draw_text(const char* string)
while(string[p] != '\0') {
// 文字コード取得
uint16 code = (uint8)string[p++];
if((0x81 <= code && code <= 0x9f) || 0xe0 <= code) {
if(is_2byte_message(code)) {
code = (code << 8) | (uint8)string[p++];
}
if(draw_hankaku) {
+2 -4
View File
@@ -278,8 +278,7 @@ void NACT::execute()
cmd_z();
break;
default:
if(cmd == 0x20 || (0xa1 <= cmd && cmd <= 0xdd)) {
// message (1 byte)
if(is_1byte_message(cmd)) {
char string[3];
string[0] = cmd;
string[1] = '\0';
@@ -313,8 +312,7 @@ void NACT::execute()
string[2] = '\0';
}
output_console(string);
} else if((0x81 <= cmd && cmd <= 0x9f) || 0xe0 <= cmd) {
// message (2 bytes)
} else if(is_2byte_message(cmd)) {
char string[3];
string[0] = cmd;
string[1] = getd();
+2 -2
View File
@@ -204,9 +204,9 @@ void NACT_Sys1::cmd_branch()
} else if(cmd == 'Z') {
cali();
cali();
} else if(cmd == 0x20 || (0xa1 <= cmd && cmd <= 0xdd)) {
} else if(is_1byte_message(cmd)) {
// message (1 byte)
} else if((0x81 <= cmd && cmd <= 0x9f) || 0xe0 <= cmd) {
} else if(is_2byte_message(cmd)) {
// message (2 bytes)
getd();
} else {
+6 -7
View File
@@ -171,9 +171,9 @@ void NACT_Sys2::cmd_branch()
} else if(cmd == 'M') {
for(;;) {
uint8 val = getd();
if(val == 0x20 || (0xa1 <= val && val <= 0xdd)) {
if(is_1byte_message(val)) {
// message (1 byte)
} else if((0x81 <= val && val <= 0x9f) || 0xe0 <= val) {
} else if(is_2byte_message(val)) {
// message (2 bytes)
getd();
} else if(val == ':') {
@@ -255,9 +255,9 @@ void NACT_Sys2::cmd_branch()
} else if(cmd == 'Z') {
cali();
cali();
} else if(cmd == 0x20 || (0xa1 <= cmd && cmd <= 0xdd)) {
} else if(is_1byte_message(cmd)) {
// message (1 byte)
} else if((0x81 <= cmd && cmd <= 0x9f) || 0xe0 <= cmd) {
} else if(is_2byte_message(cmd)) {
// message (2 bytes)
getd();
} else {
@@ -1082,8 +1082,7 @@ void NACT_Sys2::cmd_m()
int d, p = 0;
while((d = getd()) != ':') {
if((0x81 <= d && d <= 0x9f) || 0xe0 <= d) {
// 2bytes
if(is_2byte_message(d)) {
string[p++] = d;
string[p++] = getd();
} else {
@@ -1474,7 +1473,7 @@ void NACT_Sys2::cmd_y()
int len = cmd - 220, p = 0, q = 0;
uint8 d;
while((d = (uint8)tvar[param - 1][p]) != '\0') {
if((0x81 <= d && d <= 0x9f) || 0xe0 <= d) {
if(is_2byte_message(d)) {
string[p] = tvar[param - 1][p];
p++;
}
+2 -3
View File
@@ -798,8 +798,7 @@ void NACT_Sys3::cmd_m()
int d, p = 0;
while((d = getd()) != ':') {
if((0x81 <= d && d <= 0x9f) || 0xe0 <= d) {
// 2bytes
if(is_2byte_message(d)) {
string[p++] = d;
string[p++] = getd();
} else {
@@ -1385,7 +1384,7 @@ void NACT_Sys3::cmd_y()
} else {
uint8 code = tvar[param - 1][s++];
string[d++] = code;
if((0x81 <= code && code <= 0x9f) || 0xe0 <= code) {
if(is_2byte_message(code)) {
string[d++] = tvar[param - 1][s++];
}
}
+1 -1
View File
@@ -69,7 +69,7 @@ INT_PTR CALLBACK TextDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPara
pnt = cnt = 0;
while(string[pnt] != '\0') {
unsigned char dat = string[pnt];
if((0x81 <= dat && dat <= 0x9f) || 0xe0 <= dat) {
if(is_2byte_message(dat)) {
pnt++;
}
pnt++;