Add a new function to measure the length by text.
ClosedPublic

Authored by xuetianweng on Nov 13 2017, 7:12 PM.

Details

Summary

CJK language contains more information per character. When people try to
write code to cap the user input by length, ususally it makes more sense
to loose limit for CJK strings. In real life, twitter now also employs
similar algorithm to make tweet length 280 in latin or 140 in CJK characters.

Test Plan

unit test.

Diff Detail

Repository
R244 KCoreAddons
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
xuetianweng created this revision.Nov 13 2017, 7:12 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptNov 13 2017, 7:12 PM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
hein accepted this revision.Nov 13 2017, 7:18 PM

I'm very happy to see this. I opened a thread about this on k-c-d (I think) last year, but I didn't follow through with actual code. We have various search fields in KDE that do something like "only search on length > 3", and they fail miserably with CJK input. KRunner is one such example.

The algorithm seems decent for now. It can always be refined later, once we have a central API for this.

This revision is now accepted and ready to land.Nov 13 2017, 7:18 PM
This revision was automatically updated to reflect the committed changes.