|
1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- export default class
- CommonModule
- {
- static
- isWide (chr)
- {
- return chr.match (/[^\x01-\x7f]/) !== null;
- }
-
- static
- lenByFull (str)
- {
- return str.split ('').map (c => this.isWide (c) ? 1 : .5)
- .reduce ((a, c) => a + c);
- }
-
- static
- indexByFToC (str, index)
- {
- let i = 0;
- let work = '';
-
- for (let c of str)
- {
- work += c;
-
- if (this.lenByFull (work) > index)
- break;
-
- i += 1;
- }
-
- return i;
- }
-
- static
- midByFull (str, start, length)
- {
- const trimmedLeft = str.slice (this.indexByFToC (str, start));
-
- return trimmedLeft.slice (0, this.indexByFToC (trimmedLeft, length));
- }
- }
-
|