diff --git a/broadcast/common_module.js b/broadcast/common_module.js new file mode 100644 index 0000000..cacf16d --- /dev/null +++ b/broadcast/common_module.js @@ -0,0 +1,44 @@ +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)); + } +} + diff --git a/broadcast/talk.frm.php b/broadcast/talk.frm.php index 22f5af4..3e0e1cb 100644 --- a/broadcast/talk.frm.php +++ b/broadcast/talk.frm.php @@ -17,7 +17,7 @@
- +