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.
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.