From ea6803971879f9c35fd2695d3817b54b87fb6269 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 5 Dec 2010 22:25:49 +0000 Subject: [PATCH] (svn r21416) -Codechange: limit vehicle name by amount of characters, not bytes --- src/ai/api/ai_vehicle.cpp | 2 +- src/vehicle_cmd.cpp | 2 +- src/vehicle_gui.cpp | 2 +- src/vehicle_type.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp index bb4f756af8..d7d066c7b6 100644 --- a/src/ai/api/ai_vehicle.cpp +++ b/src/ai/api/ai_vehicle.cpp @@ -208,7 +208,7 @@ { EnforcePrecondition(false, IsValidVehicle(vehicle_id)); EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_VEHICLE_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_VEHICLE_NAME_CHARS, AIError::ERR_PRECONDITION_STRING_TOO_LONG); return AIObject::DoCommand(0, vehicle_id, 0, CMD_RENAME_VEHICLE, name); } diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 4d29ac4957..efb6d3b92e 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -882,7 +882,7 @@ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uin bool reset = StrEmpty(text); if (!reset) { - if (strlen(text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR; + if (Utf8StringLength(text) >= MAX_LENGTH_VEHICLE_NAME_CHARS) return CMD_ERROR; if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 34eb67d4b9..8032b24b31 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1810,7 +1810,7 @@ struct VehicleDetailsWindow : Window { const Vehicle *v = Vehicle::Get(this->window_number); SetDParam(0, v->index); ShowQueryString(STR_VEHICLE_NAME, STR_QUERY_RENAME_TRAIN_CAPTION + v->type, - MAX_LENGTH_VEHICLE_NAME_BYTES, MAX_LENGTH_VEHICLE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT); + MAX_LENGTH_VEHICLE_NAME_CHARS, MAX_LENGTH_VEHICLE_NAME_PIXELS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; } diff --git a/src/vehicle_type.h b/src/vehicle_type.h index 3f393435f6..4c4f468cdc 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -64,7 +64,7 @@ enum DepotCommand { DEPOT_COMMAND_MASK = 0xFU << 28, }; -static const uint MAX_LENGTH_VEHICLE_NAME_BYTES = 31; ///< The maximum length of a vehicle name in bytes including '\0' +static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 31; ///< The maximum length of a vehicle name in characters including '\0' static const uint MAX_LENGTH_VEHICLE_NAME_PIXELS = 150; ///< The maximum length of a vehicle name in pixels /** Vehicle acceleration models. */