adafruit / Adafruit_CircuitPython_MiniMQTT

MQTT Client Library for CircuitPython
Other
80 stars 49 forks source link

Fix Issue #90: Remaining length issues #91

Closed Eason010212 closed 2 years ago

Eason010212 commented 3 years ago

https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/90#issue-981092769 I override the default len() method. Now, when calculating the length of a string, it will return the length of the UTF-8 encoded bytes instead of the number of characters. This change will not affect the calculation of English string length. However, when dealing with certain languages, it helps a lot. For example, "中文" in UTF-8 encoded bytes is "\xe4\xb8\xad\xe6\x96\x87". Previously, len("中文") is 2 (incorrect). After override, len("中文") is 6 (len(b'\xe4\xb8\xad\xe6\x96\x87'), correct). Because there are too many uses of len(str) in the code, I carried out this override to fix them at a time. After confirming that the issue I raised is valid, maybe you can have a more professional and elegant way to fix it. Thank you very much.

Eason010212 commented 2 years ago

收到。宋义深