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

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2021 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
1.1.1.3   root        7: //
                      8: // Shift_JIS 関係
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
                     13: #include "header.h"
                     14: 
                     15: class SJIS
                     16: {
                     17:  public:
                     18:        // ASCII なら true を返す
                     19:        static bool IsASCII(uint8 c)
                     20:        {
                     21:                return c < 0x80;
                     22:        }
                     23: 
                     24:        // 半角カナ なら true を返す
                     25:        static bool IsKana(uint8 c)
                     26:        {
                     27:                // 半角カナの上位ニブルは a,b,c,d
1.1.1.4 ! root       28:                return (1U << (c >> 4)) & 0b00111100'00000000;
1.1       root       29:        }
                     30: 
                     31:        // 全角文字の 1 バイト目なら true を返す
                     32:        static bool IsZenkaku(uint8 c)
                     33:        {
                     34:                // Shift_JIS の1文字目は上位ニブルが 8,9,e。
1.1.1.2   root       35:                // f は第三水準以降で使用されているが第二水準まででは使われておらず
                     36:                // CGROM にデータも用意されてないので、ここでは半角外字領域とする。
1.1       root       37: 
1.1.1.2   root       38:                // bit 8, 9, e を立てた値と and すればよい。
1.1       root       39:                // なお ubuntu amd64 gcc9.3 はビットテスト命令にコンパイルしてくれる。
1.1.1.4 ! root       40:                return (1U << (c >> 4)) & 0b01000011'00000000;
1.1       root       41:        }
                     42: 
                     43:        // 半角文字なら true を返す
                     44:        static bool IsHankaku(uint8 c)
                     45:        {
                     46:                return !IsZenkaku(c);
                     47:        }
                     48: };

unix.superglobalmegacorp.com

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