diff options
author | rubidium <rubidium@openttd.org> | 2010-12-05 22:25:08 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-05 22:25:08 +0000 |
commit | 6e69b943d685c3b485d415d4fce53af28f0eba85 (patch) | |
tree | 4fdd482d8d916951c9b34edceb4127f7bf6871ed | |
parent | cf61c2f11fbffe20749382feb8fe03d238a2888d (diff) | |
download | openttd-6e69b943d685c3b485d415d4fce53af28f0eba85.tar.xz |
(svn r21413) -Codechange: limit sign name by amount of characters, not bytes
-rw-r--r-- | src/ai/api/ai_sign.cpp | 4 | ||||
-rw-r--r-- | src/signs_cmd.cpp | 4 | ||||
-rw-r--r-- | src/signs_gui.cpp | 14 | ||||
-rw-r--r-- | src/signs_type.h | 2 |
4 files changed, 12 insertions, 12 deletions
diff --git a/src/ai/api/ai_sign.cpp b/src/ai/api/ai_sign.cpp index ce36b1848..df16af0b7 100644 --- a/src/ai/api/ai_sign.cpp +++ b/src/ai/api/ai_sign.cpp @@ -30,7 +30,7 @@ { EnforcePrecondition(false, IsValidSign(sign_id)); EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_SIGN_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_SIGN_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name); } @@ -66,7 +66,7 @@ { EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text)); - EnforcePreconditionCustomError(false, ::strlen(text) < MAX_LENGTH_SIGN_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); if (!AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &AIInstance::DoCommandReturnSignID)) return INVALID_SIGN; diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp index 23af91460..1b0a8cca2 100644 --- a/src/signs_cmd.cpp +++ b/src/signs_cmd.cpp @@ -40,7 +40,7 @@ CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS); /* Check sign text length if any */ - if (!StrEmpty(text) && strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR; + if (!StrEmpty(text) && Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR; /* When we execute, really make the sign */ if (flags & DC_EXEC) { @@ -80,7 +80,7 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 /* Rename the signs when empty, otherwise remove it */ if (!StrEmpty(text)) { - if (strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR; + if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR; if (flags & DC_EXEC) { /* Delete the old name */ diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 70bb897db..7cdc1151c 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -50,8 +50,8 @@ struct SignList { static const Sign *last_sign; GUISignList signs; - char filter_string[MAX_LENGTH_SIGN_NAME_BYTES]; ///< The match string to be used when the GUIList is (re)-sorted. - static bool match_case; ///< Should case sensitive matching be used? + char filter_string[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; ///< The match string to be used when the GUIList is (re)-sorted. + static bool match_case; ///< Should case sensitive matching be used? /** * Creates a SignList with filtering disabled by default. @@ -109,7 +109,7 @@ struct SignList { static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info) { /* Get sign string */ - char buf1[MAX_LENGTH_SIGN_NAME_BYTES]; + char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; SetDParam(0, (*a)->index); GetString(buf1, STR_SIGN_NAME, lastof(buf1)); @@ -146,7 +146,7 @@ struct SignListWindow : QueryStringBaseWindow, SignList { int text_offset; ///< Offset of the sign text relative to the left edge of the SLW_LIST widget. Scrollbar *vscroll; - SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES) + SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS) { this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(SLW_SCROLLBAR); @@ -155,7 +155,7 @@ struct SignListWindow : QueryStringBaseWindow, SignList { /* Initialize the text edit widget */ this->afilter = CS_ALPHANUMERAL; - InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_BYTES, MAX_LENGTH_SIGN_NAME_PIXELS); // Allow MAX_LENGTH_SIGN_NAME_BYTES characters (including \0) + InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS, MAX_LENGTH_SIGN_NAME_PIXELS); ClearFilterTextWidget(); /* Initialize the filtering variables */ @@ -462,7 +462,7 @@ enum QueryEditSignWidgets { struct SignWindow : QueryStringBaseWindow, SignList { SignID cur_sign; - SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_BYTES) + SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS) { this->caption = STR_EDIT_SIGN_CAPTION; this->afilter = CS_ALPHANUMERAL; @@ -488,7 +488,7 @@ struct SignWindow : QueryStringBaseWindow, SignList { *last_of = '\0'; this->cur_sign = si->index; - InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, MAX_LENGTH_SIGN_NAME_PIXELS); + InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars, MAX_LENGTH_SIGN_NAME_PIXELS); this->SetWidgetDirty(QUERY_EDIT_SIGN_WIDGET_TEXT); this->SetFocusedWidget(QUERY_EDIT_SIGN_WIDGET_TEXT); diff --git a/src/signs_type.h b/src/signs_type.h index a54808705..0e9780268 100644 --- a/src/signs_type.h +++ b/src/signs_type.h @@ -17,7 +17,7 @@ struct Sign; static const SignID INVALID_SIGN = 0xFFFF; -static const uint MAX_LENGTH_SIGN_NAME_BYTES = 31; ///< The maximum length of a sign name in bytes including '\0' +static const uint MAX_LENGTH_SIGN_NAME_CHARS = 31; ///< The maximum length of a sign name in characters including '\0' static const uint MAX_LENGTH_SIGN_NAME_PIXELS = 255; ///< The maximum length of a sign name in pixels #endif /* SIGNS_TYPE_H */ |