I'm playing a Chinese MUD in which both Chinese and English may exist in one line.
Each Chinese word occupies 2 characters while English word occupies only 1 character.
Which means I can not predict the exact position of a separator when the length of a line exceeds the specified wrap width as fixed position may divide a Chinese word into two half.
I have an idea in my mind to resolve such problem:
1. Capturing all lines from MUD server.
2. Directly print lines within wrap width.
3. For lines out of limit, using string.byte() to count all characters and get the position of the separator avoiding dividing Chinese word.
4. Loop print separated lines
It should be able to resolve the auto-wrap problem. But I'm worrying about the performance of such method as it may cost huge of additional computing resource and may impact on the speed of the whole MUD.
Does anyone has similar experience and any better method to resolving the problem?
Each Chinese word occupies 2 characters while English word occupies only 1 character.
Which means I can not predict the exact position of a separator when the length of a line exceeds the specified wrap width as fixed position may divide a Chinese word into two half.
I have an idea in my mind to resolve such problem:
1. Capturing all lines from MUD server.
2. Directly print lines within wrap width.
3. For lines out of limit, using string.byte() to count all characters and get the position of the separator avoiding dividing Chinese word.
4. Loop print separated lines
It should be able to resolve the auto-wrap problem. But I'm worrying about the performance of such method as it may cost huge of additional computing resource and may impact on the speed of the whole MUD.
Does anyone has similar experience and any better method to resolving the problem?