Qt常用類(2)——QChar類


QChar
QCharクラスは、Qtにおいて1文字を表すクラスであり、QtCore共有ライブラリに実装される.QCharクラス内部は1文字を2バイトのUnicode符号化で表す.
        
こうぞう
QCharクラスには、次のようなさまざまなプロトタイプのコンストラクション関数が用意されています.
        
QChar();                   //        , '\0'
QChar(char ch);         //      ch  
QChar(uchar ch);        //         ch  
QChar(ushort code);   //          code  ,code Unicode  
QChar(short code);     //       code  ,code Unicode  
QChar(uint code);      //         code  ,code Unicode  
QChar(int code);       //      code  ,code Unicode  

実際にQCharクラスのオブジェクトを直接構築するのではなく,これらのコンストラクション関数をタイプ変換として用い,コンパイラに必要なQCharクラスのオブジェクトを自動的に構築させる.すなわち,QCharクラスをパラメータとして必要とするすべての場所で,様々な整数タイプを安全に使用できる.
        
と判断
QCharクラスには、次のような文字のタイプを判断できるメンバー関数が多数用意されています.
bool isDigit() const;            //           ('0' - '9')
bool isLetter() const;          //        
bool isNumber() const;        //        ,     、    
bool isLetterOrNumber();    //           
bool isLower() const;           //          
bool isUpper() const;           //          
bool isNull() const;              //         '\0'
bool isPrint() const;            //           
bool isSpace() const;         //         ,     

へんかん
QCharクラスには、次のようなメンバー関数があります.
char toAscii() const;           //      ASCII 
QChar toLower() const;    //        
QChar toUpper() const;    //        
ushort unicode() const;    //   Unicode  

これらの関数はオブジェクト自体を変えず、変換の結果は戻り値で反映されることに注意してください.
     
比較
Qtには、次のようなQCharクラスに関連する比較オペレータが定義されています.
bool operator != (QChar c1, QChar c2);    //    c1       c2
bool operator < (QChar c1, QChar c2);     //     c1      c2
bool operator <= (QChar c1, QChar c2);   //    c1        c2
bool operator == (QChar c1, QChar c2);   //    c1
    c2
bool operator > (QChar c1, QChar c2);    //    c1      c2
bool operator >= (QChar c1, QChar c2);   //     c1
       c2