mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
Fix first letter not capitalized in Polish
This commit is contained in:
@@ -678,6 +678,41 @@ std::string Helpers::toUpper(std::string const & s) {
|
||||
return lc;
|
||||
}
|
||||
|
||||
// capitalizes one UTF-8 character in char array
|
||||
// works with Latin1 (1 byte) and Polish (2 bytes) characters
|
||||
// TODO add special characters that occur in other supported languages
|
||||
void Helpers::CharToUpperUTF8(char * c) {
|
||||
switch (*c) {
|
||||
case 0xC3:
|
||||
if (*(c + 1) == 0xB3) //ó (0xC3,0xB3) -> Ó (0xC3,0x93)
|
||||
*(c + 1) = 0x93;
|
||||
break;
|
||||
case 0xC4:
|
||||
switch (*(c + 1)) {
|
||||
case 0x85: //ą (0xC4,0x85) -> Ą (0xC4,0x84)
|
||||
case 0x87: //ć (0xC4,0x87) -> Ć (0xC4,0x86)
|
||||
case 0x99: //ę (0xC4,0x99) -> Ę (0xC4,0x98)
|
||||
*(c + 1) = *(c + 1) - 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0xC5:
|
||||
switch (*(c + 1)) {
|
||||
case 0x82: //ł (0xC5,0x82) -> Ł (0xC5,0x81)
|
||||
case 0x84: //ń (0xC5,0x84) -> Ń (0xC5,0x83)
|
||||
case 0x9B: //ś (0xC5,0x9B) -> Ś (0xC5,0x9A)
|
||||
case 0xBA: //ź (0xC5,0xBA) -> Ź (0xC5,0xB9)
|
||||
case 0xBC: //ż (0xC5,0xBC) -> Ż (0xC5,0xBB)
|
||||
*(c + 1) = *(c + 1) - 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*c = toupper(*c); //works on Latin1 letters
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// replace char in char string
|
||||
void Helpers::replace_char(char * str, char find, char replace) {
|
||||
if (str == nullptr) {
|
||||
|
||||
@@ -55,6 +55,7 @@ class Helpers {
|
||||
static std::string toLower(std::string const & s);
|
||||
static std::string toUpper(std::string const & s);
|
||||
static std::string toLower(const char * s);
|
||||
static void CharToUpperUTF8(char * c);
|
||||
|
||||
static void replace_char(char * str, char find, char replace);
|
||||
|
||||
|
||||
@@ -907,7 +907,7 @@ void Mqtt::publish_ha_sensor_config(DeviceValue & dv, const std::string & model,
|
||||
|
||||
if (create_device_config) {
|
||||
auto cap_name = strdup(device_type_name);
|
||||
cap_name[0] = toupper(cap_name[0]); // capitalize
|
||||
Helpers::CharToUpperUTF8(cap_name); // capitalize first letter
|
||||
dev_json["name"] = std::string("EMS-ESP ") + cap_name;
|
||||
dev_json["mf"] = brand;
|
||||
dev_json["mdl"] = model;
|
||||
@@ -1132,7 +1132,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
// friendly name = <tag> <name>
|
||||
char ha_name[70];
|
||||
char * F_name = strdup(fullname);
|
||||
F_name[0] = toupper(F_name[0]); // capitalize first letter
|
||||
Helpers::CharToUpperUTF8(F_name); // capitalize first letter
|
||||
if (EMSdevice::tag_to_string(tag).empty()) {
|
||||
snprintf(ha_name, sizeof(ha_name), "%s", F_name); // no tag
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user