添付ファイルの情報



[添付ファイル一覧] [全ページの添付ファイル一覧]

fileget_charblock_list2.cpp
格納ファイル名:attach/446576656C6F702F39_6765745F63686172626C6F636B5F6C697374322E637070
ページ:Develop/9
格納ファイル名:attach/446576656C6F702F39_6765745F63686172626C6F636B5F6C697374322E637070
MD5ハッシュ値:6ae393308a7569a58a214f7977ad1a59
サイズ:4.2KB (4268 bytes)
Content-type:application/octet-stream
登録日時:2008/11/03 13:18:33
アクセス数:427
MD5ハッシュ値:6ae393308a7569a58a214f7977ad1a59
fileget_charblock_list2.cpp
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
	Unicode で使用されるコードブロックの取得
 
	[Requirements]
	実行ファイルと同じ場所に以下のファイルをダウンロードして保存しておく。
	http://www.unicode.org/Public/UNIDATA/Blocks.txt
*/
/*
	Copyright (C) 2007, rastiv
 
	This software is provided 'as-is', without any express or implied
	warranty. In no event will the authors be held liable for any damages
	arising from the use of this software.
 
	Permission is granted to anyone to use this software for any purpose,
	including commercial applications, and to alter it and redistribute it
	freely, subject to the following restrictions:
 
		1. The origin of this software must not be misrepresented;
		   you must not claim that you wrote the original software.
		   If you use this software in a product, an acknowledgment
		   in the product documentation would be appreciated but is
		   not required.
 
		2. Altered source versions must be plainly marked as such,
		   and must not be misrepresented as being the original software.
 
		3. This notice may not be removed or altered from any source
		   distribution.
*/
 
 
 
#include <stdio.h>
 
/*
	Blocks.txt のエントリーを処理
*/
#define MAX_LINEBUF 2000
class CBlockEntry
{
    char m_aLineBuf[MAX_LINEBUF];
 
public:
 
    bool get_entry( FILE * );
    void get_blockrange( int *, int * );
};
 
bool CBlockEntry::get_entry( FILE *fin )
{
    do{
        if( NULL == fgets(m_aLineBuf, MAX_LINEBUF, fin) ){
            return false;  // ファイルの終端に達した(または ERROR)
        }
    }while( m_aLineBuf[0] == '#' || m_aLineBuf[0] == '\n' );
    // '#' で始まるコメント行と空行を飛ばす
 
    return true;
}
 
/*
 
*/
void CBlockEntry::get_blockrange( int *pv1, int *pv2 )
{
    /*
		エントリー文字列から得られるコードブロックの範囲:
		Perl 風に書くと
 
		my $line =~ m/^([0-9a-f]+)\.\.([0-9a-f]+);[^\n]+$/
		# $1 から $2 まで
 
	*/
 
    int i;
    const char *pr, *pr_end;
    char awork1[10]; // ブロック開始コードポイント格納用バッファ
    char awork2[10]; // ブロック終了コードポイント格納用バッファ
    char *pwork;
 
    pr = m_aLineBuf;
    pr_end = m_aLineBuf + MAX_LINEBUF;
 
    pwork = awork1;    // pwork にブロック開始コードポイント格納用バッファをセット
    i = 0;
    while( pr < pr_end ){
        if( *pr != '.' && *pr != ';' ){
            // '.' または ';' が来るまでpworkに文字列を格納
            pwork[i] = *pr;
            i++;
            pr++;
            continue;
        }
        if( pwork == awork1 ){    // ブロック開始コードポイントを awork1 に取得した
            pwork[i] = '\0';
            pwork = awork2;    // pwork にブロック終了コードポイント格納用バッファをセット
            i = 0;
            pr += 2; // ".." をスキップ
        }else{
            pwork[i] = '\0';
            break;
        }
    }
 
    // pv1 と pv2 に、それぞれ、ブロック開始コードポイントとブロック終了コードポイントを記録
    sscanf( awork1, "%x", pv1 );
    sscanf( awork2, "%x", pv2 );
}
 
 
 
/*
	エントリーから得られたコードブロックリストの整理
*/
#define MAX_ENTRYCOUNT 500
class CBlockList
{
    int m_pBlkStartEndPair[MAX_ENTRYCOUNT][2];
    int m_nCount;
 
public:
 
    CBlockList() : m_nCount(0) {}
 
    bool get_list(void);
    void print_list(void);
};
 
bool CBlockList::get_list(void)
{
    int i, nret;
    FILE *pfin;
    CBlockEntry centry;
 
    pfin = fopen( "Blocks.txt", "r" );
    if( pfin == NULL ){
        return false;
    }
 
    nret = centry.get_entry( pfin );
    for( i = 0; i < MAX_ENTRYCOUNT && nret != 0; i++ ){
        centry.get_blockrange( &m_pBlkStartEndPair[i][0], &m_pBlkStartEndPair[i][1] );
        nret = centry.get_entry( pfin );
    }
    m_nCount = i;
 
    fclose( pfin );
    return true;
}
 
 
void CBlockList::print_list( void )
{
    int i;
    int nstart, nend, ntemp;
 
    if( m_nCount < 1 ){
        return;
    }
 
    nstart = m_pBlkStartEndPair[0][0];
    ntemp = m_pBlkStartEndPair[0][1];
    for( i = 1; i < m_nCount; i++ ){
        if( ntemp + 1 < m_pBlkStartEndPair[i][0] ){
            nend = ntemp;
            printf( "%x, %x\n", nstart, nend );
            nstart = m_pBlkStartEndPair[i][0];
            ntemp = m_pBlkStartEndPair[i][1];
        }else{
            ntemp = m_pBlkStartEndPair[i][1];
        }
    }
    printf( "%x, %x\n", nstart, ntemp );  // 最終ブロックを出力
 
    return;
}
 
 
 
 
 
/*
	主処理
*/
int main()
{
    CBlockList clist;
 
    if( clist.get_list() ){
        clist.print_list();
    }else{
        fprintf( stderr, "input error.\n" );
    }
 
    // Pause の変わり
    for(;;){
        ;
    }
 
    return 0;
}




    


    ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS