diff options
author | rubidium <rubidium@openttd.org> | 2010-12-05 22:23:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-05 22:23:50 +0000 |
commit | 9a1805064654d5f0e348f8a7b990532bfb66921a (patch) | |
tree | c4f696f86b410ab76a0c9eb224d4cd9b7bf82fd4 | |
parent | 66c7f00b607666df05849e66f6911dac9b426bd4 (diff) | |
download | openttd-9a1805064654d5f0e348f8a7b990532bfb66921a.tar.xz |
(svn r21408) -Codechange: limit president name by amount of characters, not bytes
-rw-r--r-- | src/company_cmd.cpp | 8 | ||||
-rw-r--r-- | src/company_gui.cpp | 2 | ||||
-rw-r--r-- | src/company_type.h | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index e5eeea939..d44f4c4ab 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -468,16 +468,16 @@ restart:; /* Reserve space for extra unicode character. We need to do this to be able * to detect too long president name. */ - char buffer[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH]; + char buffer[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH]; SetDParam(0, c->index); GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer)); - if (strlen(buffer) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) continue; + if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue; Company *cc; FOR_ALL_COMPANIES(cc) { if (c != cc) { /* Reserve extra space so even overlength president names can be compared. */ - char buffer2[MAX_LENGTH_PRESIDENT_NAME_BYTES + MAX_CHAR_LENGTH]; + char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH]; SetDParam(0, cc->index); GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2)); if (strcmp(buffer2, buffer) == 0) goto restart; @@ -1094,7 +1094,7 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u bool reset = StrEmpty(text); if (!reset) { - if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR; + if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR; if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); } diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 56d6e94a9..d5176abf6 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1946,7 +1946,7 @@ struct CompanyWindow : Window case CW_WIDGET_PRESIDENT_NAME: this->query_widget = CW_WIDGET_PRESIDENT_NAME; SetDParam(0, this->window_number); - ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_BYTES, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); + ShowQueryString(STR_PRESIDENT_NAME, STR_COMPANY_VIEW_PRESIDENT_S_NAME_QUERY_CAPTION, MAX_LENGTH_PRESIDENT_NAME_CHARS, MAX_LENGTH_PRESIDENT_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; case CW_WIDGET_COMPANY_NAME: diff --git a/src/company_type.h b/src/company_type.h index 77d73ed1f..7e308b6f7 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -37,7 +37,7 @@ enum Owner { }; DECLARE_POSTFIX_INCREMENT(Owner) -static const uint MAX_LENGTH_PRESIDENT_NAME_BYTES = 31; ///< The maximum length of a president name in bytes including '\0' +static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS = 31; ///< The maximum length of a president name in characters including '\0' static const uint MAX_LENGTH_PRESIDENT_NAME_PIXELS = 94; ///< The maximum length of a president name in pixels static const uint MAX_LENGTH_COMPANY_NAME_BYTES = 31; ///< The maximum length of a company name in bytes including '\0' static const uint MAX_LENGTH_COMPANY_NAME_PIXELS = 150; ///< The maximum length of a company name in pixels |