Annotation of nono/lib/sjis.h, revision 1.1.1.2

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。
1.1.1.2 ! root       32:                // f は第三水準以降で使用されているが第二水準まででは使われておらず
        !            33:                // CGROM にデータも用意されてないので、ここでは半角外字領域とする。
1.1       root       34: 
1.1.1.2 ! root       35:                // bit 8, 9, e を立てた値と and すればよい。
1.1       root       36:                // なお ubuntu amd64 gcc9.3 はビットテスト命令にコンパイルしてくれる。
1.1.1.2 ! root       37:                return (1 << (c >> 4)) & 0b01000011'00000000;
1.1       root       38:        }
                     39: 
                     40:        // 半角文字なら true を返す
                     41:        static bool IsHankaku(uint8 c)
                     42:        {
                     43:                return !IsZenkaku(c);
                     44:        }
                     45: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.