ニジカもんすたぁ!! トップ・ページ https://nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common_module.js 693 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. export default class
  2. CommonModule
  3. {
  4. static
  5. isWide (chr)
  6. {
  7. return chr.match (/[^\x01-\x7f]/) !== null;
  8. }
  9. static
  10. lenByFull (str)
  11. {
  12. return str.split ('').map (c => this.isWide (c) ? 1 : .5)
  13. .reduce ((a, c) => a + c);
  14. }
  15. static
  16. indexByFToC (str, index)
  17. {
  18. let i = 0;
  19. let work = '';
  20. for (let c of str)
  21. {
  22. work += c;
  23. if (this.lenByFull (work) > index)
  24. break;
  25. i += 1;
  26. }
  27. return i;
  28. }
  29. static
  30. midByFull (str, start, length)
  31. {
  32. const trimmedLeft = str.slice (this.indexByFToC (str, start));
  33. return trimmedLeft.slice (0, this.indexByFToC (trimmedLeft, length));
  34. }
  35. }