From c30b4562149df55ff196e60204235be028fd5cd0 Mon Sep 17 00:00:00 2001 From: Piotr Majkrzak Date: Thu, 23 Feb 2023 15:48:50 +0100 Subject: [PATCH 1/3] Add read/write GBK encoding methods --- lib/codeplug.cc | 21 +++++++++++++++++++++ lib/codeplug.hh | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/lib/codeplug.cc b/lib/codeplug.cc index be94c0c1..1c568eb2 100644 --- a/lib/codeplug.cc +++ b/lib/codeplug.cc @@ -1,6 +1,7 @@ #include "codeplug.hh" #include "config.hh" #include +#include #include "logger.hh" #include "roamingchannel.hh" @@ -579,6 +580,26 @@ Codeplug::Element::writeUnicode(unsigned offset, const QString &txt, unsigned ma } } +QString +Codeplug::Element::readGBK(unsigned offset, unsigned maxlen, uint8_t eos) const { + QByteArray txt; + uint8_t *ptr = (uint8_t *)(_data+offset); + for (unsigned i=0; (itoUnicode(txt); +} +void +Codeplug::Element::writeGBK(unsigned offset, const QString &txt, unsigned maxlen, uint8_t eos) { + QByteArray enc = QTextCodec::codecForName("GBK")->fromUnicode(txt); + uint8_t *ptr = (uint8_t *)(_data+offset); + for (unsigned i=0; i Date: Thu, 23 Feb 2023 16:22:59 +0100 Subject: [PATCH 2/3] Update the way GBK strings are counted --- lib/codeplug.cc | 6 +++--- lib/codeplug.hh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/codeplug.cc b/lib/codeplug.cc index 1c568eb2..52463bc7 100644 --- a/lib/codeplug.cc +++ b/lib/codeplug.cc @@ -584,16 +584,16 @@ QString Codeplug::Element::readGBK(unsigned offset, unsigned maxlen, uint8_t eos) const { QByteArray txt; uint8_t *ptr = (uint8_t *)(_data+offset); - for (unsigned i=0; (itoUnicode(txt); } void Codeplug::Element::writeGBK(unsigned offset, const QString &txt, unsigned maxlen, uint8_t eos) { - QByteArray enc = QTextCodec::codecForName("GBK")->fromUnicode(txt); + QByteArray enc = QTextCodec::codecForName("GBK")->fromUnicode(txt.left(maxlen)); uint8_t *ptr = (uint8_t *)(_data+offset); - for (unsigned i=0; i Date: Thu, 23 Feb 2023 16:32:22 +0100 Subject: [PATCH 3/3] Encode/decode channel name using GBK --- lib/anytone_codeplug.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/anytone_codeplug.cc b/lib/anytone_codeplug.cc index 46a8f164..64364b1f 100644 --- a/lib/anytone_codeplug.cc +++ b/lib/anytone_codeplug.cc @@ -565,11 +565,11 @@ AnytoneCodeplug::ChannelElement::clearEncryptionKeyIndex() { QString AnytoneCodeplug::ChannelElement::name() const { - return readASCII(0x0023, 16, 0x00); + return readGBK(0x0023, 16, 0x00); } void AnytoneCodeplug::ChannelElement::setName(const QString &name) { - writeASCII(0x0023, name, 16, 0x00); + writeGBK(0x0023, name, 16, 0x00); }