Changeset 6


Ignore:
Timestamp:
09/19/10 12:07:50 (20 months ago)
Author:
murachi
Message:

#4 への対応:

  • コメントを充実させた。
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sample/guessutf8.cpp

    r2 r6  
     1/** 
     2    @file   guessutf8.cpp 
     3    @brief  libiconv ‚ð—p‚¢‚½•¶ŽšƒZƒbƒgŽ©“®”Fޝˆ—‚̃Tƒ“ƒvƒ‹ (“à•”ƒR[ƒh UCS4 ”Å) 
     4    @author T.MURACHI (Toshiyuki Murayama) / (C)2010 Harapeko Inc. 
     5*/ 
     6 
    17#include <string> 
    28#include <map> 
     
    915using namespace std; 
    1016 
     17/// •¶Žš‚ðˆµ‚¤“à•”ƒR[ƒhŒ^ 
    1118typedef uint32_t ucs4_t; 
    1219typedef basic_string<ucs4_t, char_traits<ucs4_t>, allocator<ucs4_t> > ucs4string; 
    1320 
     21/** 
     22    @brief  ƒfƒR[ƒhŽž—áŠOƒNƒ‰ƒX 
     23*/ 
    1424class UcsDecoderException : public exception 
    1525{ 
     
    2434}; 
    2535 
     36/** 
     37    @brief  ƒGƒ“ƒR[ƒhŽž—áŠOƒNƒ‰ƒX 
     38*/ 
    2639class UcsEncoderException : public exception 
    2740{ 
     
    3649}; 
    3750 
     51/** 
     52    @brief ƒfƒR[ƒ_ƒNƒ‰ƒX 
     53     
     54    ƒtƒ@ƒCƒ‹‚©‚ç“ǂݍž‚ñ‚¾•¶Žš—ñƒf[ƒ^‚ðA“à•”ƒR[ƒh‚Ì•¶Žš—ñ‚ɕϊ·‚·‚éB 
     55    •ÏŠ·Žž‚ɁAŒ³‚Ì•¶Žš—ñƒf[ƒ^‚Ì•¶ŽšƒZƒbƒg‚ðŽ©“®”Fޝ‚·‚éB 
     56*/ 
    3857class UcsDecoder 
    3958{ 
     
    4261    size_t src_size; 
    4362     
     63    // ƒfƒtƒHƒ‹ƒgƒRƒ“ƒXƒgƒ‰ƒNƒ^AƒRƒs[ƒRƒ“ƒXƒgƒ‰ƒNƒ^A‘ã“ü‰‰ŽZŽq‚ÍŽg—p‹ÖŽ~ 
    4464    UcsDecoder(); 
    4565    UcsDecoder(const UcsDecoder &); 
    4666    UcsDecoder &operator =(const UcsDecoder &); 
    4767     
     68    /// •¶ŽšƒR[ƒhƒZƒbƒg‚ÌƒŠƒXƒg 
    4869    static char const* const ENCODE_LIST[]; 
     70     
    4971     
    5072    typedef map<string, int> IllSeqCountMap; 
     
    5375     
    5476public: 
     77    /** 
     78        @brief ƒRƒ“ƒXƒgƒ‰ƒNƒ^ 
     79        @param bytes    (I) ƒtƒ@ƒCƒ‹‚©‚ç“ǂݍž‚ñ‚¾•¶Žš—ñƒf[ƒ^ 
     80         
     81        ˆø”‚É“n‚³‚ꂽ•¶Žš—ñƒf[ƒ^‚Ì•¶ŽšƒZƒbƒg‚ð‰ðÍ‚µA UCS4 ‚Ì“à•”ƒR[ƒh‚𐶐¬‚·‚éB 
     82        UCS4 ƒeƒLƒXƒg‚É‚Í get() ƒƒ\ƒbƒh‚ɂăAƒNƒZƒX‚Å‚«‚éB 
     83    */ 
    5584    UcsDecoder(char const* bytes) 
    5685    { 
     
    6897    } 
    6998     
     99    /** 
     100        @brief “à•”ƒR[ƒhƒeƒLƒXƒg‚ðŽæ“¾‚·‚é 
     101        @return “à•”ƒR[ƒh‚ɕϊ·‚³‚ꂽƒeƒLƒXƒg‚Ì•¶Žš—ñƒIƒuƒWƒFƒNƒgB 
     102    */ 
    70103    ucs4string const& get() const { return result; } 
    71104     
     
    76109 
    77110private: 
     111    // •¶ŽšƒZƒbƒg‚ð‰ðÍ‚·‚éB 
    78112    string guessEncodeType() const 
    79113    { 
     
    145179    } 
    146180     
     181    // Œ³ƒf[ƒ^‚Ì•¶ŽšƒZƒbƒg‚ðŽw’肵‚āA UCS4 “à•”ƒR[ƒhƒeƒLƒXƒg‚ɕϊ·‚·‚éB 
    147182    void decodeToUcs4(const string &encode_type) 
    148183    { 
     
    213248}; 
    214249 
     250/** 
     251    @brief ƒGƒ“ƒR[ƒ_ƒNƒ‰ƒX 
     252     
     253    “à•”ƒR[ƒh‚Ì•¶Žš—ñ‚ðAUTF-8 Œ`Ž®‚Ì•¶Žš—ñƒf[ƒ^‚ɕϊ·‚·‚éB 
     254*/ 
    215255class UcsEncoder 
    216256{ 
     
    218258    vector<char> result_bytes; 
    219259     
     260    // ƒfƒtƒHƒ‹ƒgƒRƒ“ƒXƒgƒ‰ƒNƒ^AƒRƒs[ƒRƒ“ƒXƒgƒ‰ƒNƒ^A‘ã“ü‰‰ŽZŽq‚ÍŽg—p‹ÖŽ~ 
    220261    UcsEncoder(); 
    221262    UcsEncoder(const UcsEncoder &); 
     
    223264     
    224265public: 
     266    /** 
     267        @brief ƒRƒ“ƒXƒgƒ‰ƒNƒ^ 
     268        @param src  (I) UCS4 “à•”ƒR[ƒh•¶Žš—ñ 
     269         
     270        ˆø”‚É“n‚³‚ꂽ UCS4 “à•”ƒR[ƒh•¶Žš—ñ‚ðAUTF-8 Œ`Ž®‚Ì•¶Žš—ñƒf[ƒ^‚ɕϊ·‚·‚éB 
     271    */ 
    225272    UcsEncoder(const ucs4string &src) : ucs_text(src), result_bytes(src.size() + 1, '\0') 
    226273    { 
    227274        encodeFromUcs4(); 
    228275    } 
     276    /** 
     277        @brief UTF-8 Œ`Ž®‚Ì•¶Žš—ñƒf[ƒ^‚ðŽæ“¾‚·‚é 
     278        @return UTF-8 Œ`Ž®‚Ì•¶Žš—ñƒf[ƒ^‚ւ̃|ƒCƒ“ƒ^ 
     279    */ 
    229280    char const* get() const { return &result_bytes[0]; } 
    230281     
    231282private: 
     283    // UCS4 “à•”ƒR[ƒh•¶Žš—ñ‚ð UTF-8 Œ`Ž®‚ɕϊ·‚·‚é 
    232284    void encodeFromUcs4() 
    233285    { 
Note: See TracChangeset for help on using the changeset viewer.