|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2021 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: #pragma once ! 8: ! 9: #include "header.h" ! 10: ! 11: // SJIS 処理用 ! 12: class SJIS ! 13: { ! 14: public: ! 15: // ASCII なら true を返す ! 16: static bool IsASCII(uint8 c) ! 17: { ! 18: return c < 0x80; ! 19: } ! 20: ! 21: // 半角カナ なら true を返す ! 22: static bool IsKana(uint8 c) ! 23: { ! 24: // 半角カナの上位ニブルは a,b,c,d ! 25: return (1 << (c >> 4)) & 0b00111100'00000000; ! 26: } ! 27: ! 28: // 全角文字の 1 バイト目なら true を返す ! 29: static bool IsZenkaku(uint8 c) ! 30: { ! 31: // Shift_JIS の1文字目は上位ニブルが 8,9,e。 ! 32: // f は第2水準まででは使わないけど第3水準以降で使用されている。 ! 33: ! 34: // 8, 9, e, f ! 35: // 1000 1001 1110 1111 ! 36: // なので bit 8, 9, e, f を立てた値と and すればよい。 ! 37: // なお ubuntu amd64 gcc9.3 はビットテスト命令にコンパイルしてくれる。 ! 38: return (1 << (c >> 4)) & 0b11000011'00000000; ! 39: } ! 40: ! 41: // 半角文字なら true を返す ! 42: static bool IsHankaku(uint8 c) ! 43: { ! 44: return !IsZenkaku(c); ! 45: } ! 46: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.