# HG changeset patch # User rubidium # Date 2010-12-05 22:25:08 # Node ID c10913372b8127bb23e6c4d8708da60bab9fe8a7 # Parent bbf8280610d09dc733938b4f5d119e12aa049dc6 (svn r21413) -Codechange: limit sign name by amount of characters, not bytes diff --git a/src/ai/api/ai_sign.cpp b/src/ai/api/ai_sign.cpp --- 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 --- a/src/signs_cmd.cpp +++ b/src/signs_cmd.cpp @@ -40,7 +40,7 @@ CommandCost CmdPlaceSign(TileIndex tile, 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 /* 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 --- 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 : QueryStringBaseW 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 : QueryStringBaseW /* 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 : QueryStringBaseWindo *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 --- 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 */