source: trunk/Include/Classes/System/Text/Encoding.ab@ 452

Last change on this file since 452 was 411, checked in by イグトランス (egtra), 17 years ago

UTF8Encoding(仮)の追加

File size: 25.8 KB
Line 
1#define __STRING_IS_NOT_UNICODE 'なぜか認識されないので
2
3/*!
4@file Classes/System/Text/Encoding.ab
5@brief Encodingクラスとそれに関係するクラスなどの宣言・定義
6*/
7
8Namespace System
9Namespace Text
10
11/*!
12@brief 各種の文字符号化(エンコーディング)を行うためのクラス
13@date 2007/12/07
14@auther Egtra
15
16なお、このクラスで、文字列の長さやバッファの大きさを指定するときには、
171 chars = 2バイト(UTF-16符号単位)、1 bytes = 1バイトの単位で指定する。
18
19*/
20Class Encoding
21 Implements ICloneable
22Public
23 /*!
24 @brief 簡易的複製を作成する。
25 */
26 Abstract Function Clone() As Object
27
28' Override Function Equals(y As Object) As Boolean
29' End Function
30
31' Override Function GetHashCode() As Long
32' End Function
33
34Public
35 Sub Encoding()
36 decoderFallback = New DecoderReplacementFallback
37 End Sub
38
39 /*!
40 @brief 符号化して得られる文字列の長さを計算する。
41 @param[in] s 対象文字列
42 @param[in] n sの長さ
43 @return 符号化して得られる文字列の長さ
44 @date 2007/12/08
45 */
46 Function GetBytesCount(s As *WCHAR, n As Long) As Long
47 If s = 0 Then
48 Throw New ArgumentNullException("Encoding.GetBytesCount: An argument is null value.", "s")
49 ElseIf n < 0 Then
50 Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "n")
51 End If
52 Return GetBytesCountCore(s, n)
53 End Function
54#ifndef __STRING_IS_NOT_UNICODE
55 /*!
56 @brief 符号化して得られる文字列の長さを計算する。
57 @param[in] s 対象文字列
58 @return 符号化して得られる文字列の長さ
59 @date 2007/12/08
60 */
61 Function GetBytesCount(s As String) As Long
62 If ActiveBasic.IsNothing(s) Then
63 Throw New ArgumentNullException("Encoding.GetBytesCount: An argument is null value.", "s")
64 End If
65 Return GetBytesCountCore(StrPtr(s), s.Length)
66 End Function
67#endif
68 /*!
69 @brief 符号化して得られる文字列の長さを計算する。
70 @param[in] s 対象文字列
71 @param[in] index 開始位置
72 @param[in] count 符号化する文字の数
73 @return 符号化して得られる文字列の長さ
74 @date 2007/12/08
75 */
76 Function GetBytesCount(s As *WCHAR, index As Long, count As Long) As Long
77 If s = 0 Then
78 Throw New ArgumentNullException("Encoding.GetBytesCount: An argument is null value.", "s")
79 ElseIf index < 0 Then
80 Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "index")
81 ElseIf count < 0 Then
82 Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "count")
83 End If
84 Return GetBytesCountCore(VarPtr(s[index]), count)
85 End Function
86Protected
87 /*!
88 @brief GetBytesCountの実装を行う。
89 @param[in] s 対象文字列
90 @param[in] n sの長さ
91 @return 符号化して得られる文字列の長さ
92 @date 2007/12/08
93 */
94 Abstract Function GetBytesCountCore(s As *WCHAR, n As Long) As Long
95Public
96 /*!
97 @brief 符号化する。
98 @param[in] chars 入力
99 @param[in] charCount charsの長さ
100 @param[out] bytes 出力
101 @param[in] byteCount bytesのバッファの大きさ
102 @return bytesに書き込まれたバイト数
103 @date 2007/12/08
104 */
105 Function GetBytes(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long) As Long
106 If chars = 0 Then
107 Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "chars")
108 ElseIf bytes = 0 Then
109 Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "bytes")
110 ElseIf charCount < 0 Then
111 Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "charCount")
112 ElseIf byteCount < 0 Then
113 Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "byteCount")
114 End If
115
116 Return GetBytesCore(chars, charCount, bytes, byteCount)
117 End Function
118 /*!
119 @brief 符号化する。
120 @param[in] chars 入力
121 @param[in] index charsの開始位置
122 @param[in] count 符号化する文字の数
123 @param[out] bytes 出力
124 @param[in] byteCount bytesのバッファの大きさ
125 @return bytesに書き込まれたバイト数
126 @date 2007/12/08
127 */
128 Function GetBytes(chars As *WCHAR, index As Long, count As Long, bytes As *Byte, byteCount As Long) As Long
129 If chars = 0 Then
130 Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "chars")
131 ElseIf bytes = 0 Then
132 Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "bytes")
133 ElseIf index < 0 Then
134 Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "index")
135 ElseIf count < 0 Then
136 Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "count")
137 ElseIf byteCount < 0 Then
138 Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "byteCount")
139 End If
140
141 Return GetBytesCore(VarPtr(chars[index]), count, bytes, byteCount)
142 End Function
143#ifndef __STRING_IS_NOT_UNICODE
144 /*!
145 @brief 符号化する。
146 @param[in] s 入力
147 @param[in] index sの開始位置
148 @param[in] count 符号化する文字の数
149 @param[out] bytes 出力
150 @param[in] byteCount bytesのバッファの大きさ
151 @return bytesに書き込まれたバイト数
152 @date 2007/12/08
153 */
154 Function GetBytes(s As String, index As Long, count As Long, bytes As *Byte, byteCount As Long) As Long
155 If chars = 0 Then
156 Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "chars")
157 ElseIf bytes = 0 Then
158 Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "bytes")
159 ElseIf index < 0 Or index >= s.Length Then
160 Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "index")
161 ElseIf count < 0 Or index + count >= s.Length Then
162 Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "count")
163 ElseIf byteCount < 0 Then
164 Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "byteCount")
165 End If
166 Dim p = StrPtr(s)
167 Return GetBytesCore(VarPtr(p[index]), count, bytes, byteCount)
168 End Function
169#endif
170Protected
171 /*!
172 @brief GetBytesの処理を行う。
173 @param[in] chars 入力
174 @param[in] charCount charsの長さ
175 @param[out] bytes 出力
176 @param[in] byteCount bytesのバッファの大きさ
177 @return bytesに書き込まれたバイト数
178 @exception ArgumentException バッファの大きさが足りない
179 @exception EncoderFallbackException フォールバックが発生した
180 @date 2007/12/08
181 */
182 Abstract Function GetBytesCore(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long) As Long
183
184Public
185 /*!
186 @brief 復号して得られる文字列の長さを計算する。
187 @param[in] s 対象文字列
188 @param[in] n sの長さ
189 @return 復号して得られる文字列の長さ
190 @date 2007/12/08
191 */
192 Function GetCharsCount(s As *Byte, n As Long) As Long
193 If s = 0 Then
194 Throw New ArgumentNullException("Encoding.GetCharsCount: An argument is null value.", "s")
195 ElseIf n < 0 Then
196 Throw New ArgumentOutOfRangeException("Encoding.GetCharsCount: An argument is out of range value.", "n")
197 End If
198 Return GetCharsCountCore(s, n)
199 End Function
200 /*!
201 @brief 復号して得られる文字列の長さを計算する。
202 @param[in] s 対象文字列
203 @param[in] index 開始位置
204 @param[in] count 符号化する文字の数
205 @return 符号化して得られる文字列の長さ
206 @date 2007/12/08
207 */
208 Function GetCharsCount(s As *Byte, index As Long, count As Long) As Long
209 If s = 0 Then
210 Throw New ArgumentNullException("Encoding.GetCharsCount: An argument is null value.", "s")
211 ElseIf index < 0 Then
212 Throw New ArgumentOutOfRangeException("Encoding.GetCharsCount: An argument is out of range value.", "index")
213 ElseIf count < 0 Then
214 Throw New ArgumentOutOfRangeException("Encoding.GetCharsCount: An argument is out of range value.", "count")
215 End If
216 Return GetCharsCountCore(VarPtr(s[index]), count)
217 End Function
218Protected
219 /*!
220 @brief GetCharsCountの処理を行う。
221 @param[in] s 対象文字列
222 @param[in] n sの長さ
223 @return 符号化して得られる文字列の長さ
224 @date 2007/12/08
225 */
226 Abstract Function GetCharsCountCore(s As *Byte, n As Long) As Long
227 /*!
228 */
229Public
230 /*!
231 @brief 復号する。
232 @param[in] bytes 入力
233 @param[in] byteCount charsの長さ
234 @param[out] chars 出力
235 @param[in] charCount bytesのバッファの大きさ
236 @return bytesに書き込まれたバイト数
237 @date 2007/12/08
238 */
239 Function GetChars(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long) As Long
240 If chars = 0 Then
241 Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "chars")
242 ElseIf bytes = 0 Then
243 Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "bytes")
244 ElseIf charCount < 0 Then
245 Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "charCount")
246 ElseIf byteCount < 0 Then
247 Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "byteCount")
248 End If
249
250 Return GetCharsCore(bytes, byteCount, chars, charCount)
251 End Function
252 /*!
253 @brief 復号する。
254 @param[in] bytes 入力
255 @param[in] index charsの開始位置
256 @param[in] count 符号化する文字の数
257 @param[out] chars 出力
258 @param[in] charCount bytesのバッファの大きさ
259 @return bytesに書き込まれたバイト数
260 @date 2007/12/08
261 */
262 Function GetChars(bytes As *Byte, index As Long, count As Long, chars As *WCHAR, charCount As Long) As Long
263 If chars = 0 Then
264 Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "chars")
265 ElseIf bytes = 0 Then
266 Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "bytes")
267 ElseIf index < 0 Then
268 Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "index")
269 ElseIf count < 0 Then
270 Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "count")
271 ElseIf charCount < 0 Then
272 Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "byteCount")
273 End If
274
275 Return GetCharsCore(VarPtr(bytes[index]), count, chars, charCount)
276 End Function
277Protected
278 /*!
279 @brief GetCharsの処理を行う。
280 @param[in] bytes 入力
281 @param[in] byteCount charsの長さ
282 @param[out] chars 出力
283 @param[in] charCount bytesのバッファの大きさ
284 @return bytesに書き込まれたバイト数
285 @exception ArgumentException バッファの大きさが足りない
286 @exception EncoderFallbackException フォールバックが発生した
287 @date 2007/12/08
288 */
289 Abstract Function GetCharsCore(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long) As Long
290Public
291#ifndef __STRING_IS_NOT_UNICODE
292 /*!
293 @brief 復号し、Stringで結果を返す。
294 @param[in] bytes 入力
295 @param[in] byteCount charsの長さ
296 @return 変換結果の文字列
297 @date 2007/12/08
298 */
299 Function GetString(bytes As *Byte, byteCount As Long) As String
300 If bytes = 0 Then
301 Throw New ArgumentNullException("Encoding.GetString: An argument is null value.", "bytes")
302 ElseIf byteCount < 0 Then
303 Throw New ArgumentOutOfRangeException("Encoding.GetString: An argument is out of range value.", "byteCount")
304 End If
305 Return getStringCore(bytes, byteCount)
306 End Function
307 /*!
308 @brief 復号し、Stringで結果を返す。
309 @param[in] bytes 入力
310 @param[in] index charsの開始位置
311 @param[in] count 符号化する文字の数
312 @return 変換結果の文字列
313 @date 2007/12/08
314 */
315 Function GetString(bytes As *Byte, index As Long, count As Long) As String
316 If bytes = 0 Then
317 Throw New ArgumentNullException("Encoding.GetString: An argument is null value.", "bytes")
318 ElseIf index < 0 Then
319 Throw New ArgumentOutOfRangeException("Encoding.GetString: An argument is out of range value.", "index")
320 ElseIf count < 0 Then
321 Throw New ArgumentOutOfRangeException("Encoding.GetString: An argument is out of range value.", "count")
322 End If
323 Return getStringCore(VarPtr(bytes[index]), count)
324 End Function
325Private
326
327 Function getStringCore(bytes As *Byte, byteCount As Long) As String
328 Dim sb = New StringBuilder
329 Dim bufSize = GetMaxCharCount(byteCount)
330 sb.Length = bufSize
331 Dim len = GetCharsCore(bytes, byteCount, StrPtr(sb), bufSize)
332 sb.Length = len
333 getStringCore = sb.ToString
334 End Function
335#endif
336
337Public
338 /*!
339 @brief 符号器を取得する。
340 */
341 Abstract Function GetDecoder() As Decoder
342
343 /*!
344 @brief 復号器を取得する。
345 */
346 Abstract Function GetEncoder() As Encoder
347
348 /*!
349 @brief ある長さの文字列を符号化して得られるバイト列の最大の長さを返す。
350 */
351 Abstract Function GetMaxByteCount(charCount As Long) As Long
352
353 /*!
354 @brief ある長さのバイト列を復号して得られる文字列の最大の長さを返す。
355 */
356 Abstract Function GetMaxCharCount(charCount As Long) As Long
357
358 /*!
359 @brief 符号化された文字列の先頭につける識別文字列の取得
360 ようするにUTFのBOM
361 */
362 Virtual Function GetPreamble() As *Byte
363 Return 0
364 End Function
365
366 /*!
367 @brief GetPreambleの配列の要素数
368 */
369 Virtual Function GetPreambleLength() As Long
370 Return 0
371 End Function
372
373 /*!
374 @brief 正規化されるかどうか。
375 */
376 Abstract Function IsAlwaysNormalized() As Boolean
377
378 /*!
379 @brief 指定された方式で正規化されるかどうか。
380 */
381 Abstract Function IsAlwaysNormalized(form As NormalizationForm) As Boolean
382
383 Abstract Function BodyName() As String
384 Abstract Function HeaderName() As String
385
386 /*!
387 @brief コードページの取得。
388 */
389' Abstract Function CodePage() As Long
390 /*!
391 @brief 最も厳密に対応するWindowsコードページの取得。
392 */
393' Abstract Function WindowsCodePage() As Long
394
395 Function DecoderFallback() As DecoderFallback
396 Return decoderFallback
397 End Function
398
399 Sub DecoderFallback(f As DecoderFallback)
400 If ActiveBasic.IsNothing(f) Then
401 Throw New ArgumentNullException("f")
402 End If
403 decoderFallback = f
404 End Sub
405
406 Function EncoderFallback() As EncoderFallback
407 Return encoderFallback
408 End Function
409
410 Sub EncoderFallback(f As EncoderFallback)
411 If ActiveBasic.IsNothing(f) Then
412 Throw New ArgumentNullException("f")
413 End If
414 encoderFallback = f
415 End Sub
416
417Private
418 decoderFallback As DecoderFallback
419 encoderFallback As EncoderFallback
420Public
421 /*!
422 @brief この符号化形式の名前の取得。
423 */
424 Abstract Function EncodingName() As String
425
426 /*!
427 @brief この符号化形式のIANA登録名の取得。
428 */
429 Abstract Function WebName() As String
430
431' Abstract Function IsBrowserDisplay() As Boolean
432' Abstract Function IsBrowserSave() As Boolean
433' Abstract Function IsMailNewsDisplay() As Boolean
434' Abstract Function IsMailNewsSave() As Boolean
435
436' Abstract Function IsReadOnly() Boolean
437
438 /*!
439 @brief この符号化形式が、1バイト文字だけを使う(複数バイト文字を使わない)かどうか。
440 */
441 Abstract Function IsSingleByte() As Boolean
442
443 'GetPreamble
444
445 /*!
446 @brief ある符号化文字列から別の符号化文字列へ変換する。
447 @param[in] srcEncoding 入力の符号化方式
448 @param[in] dstEncoding 出力の符号化方式
449 @param[in] bytes 入力文字列
450 @param[in] size バイト単位での文字列の長さ
451 @return 出力文字列
452 @exception ArgumentNullException srcEncoding, dstEncoding, bytesの少なくとも1つ以上がNothing/NULLのとき。
453 @exception ArgumentOutOfRangeException sizeが明らかに範囲外(負の値など)のとき。
454 @exception DecoderFallbackException
455 @exception EncoderFallbackException
456 */
457 Static Function Convert(srcEncoding As Encoding, dstEncoding As Encoding, bytes As *Byte, size As Long) As *Byte
458 End Function
459
460 Static Function Convert(srcEncoding As Encoding, dstEncoding As Encoding, bytes As *Byte, index As Long, count As Long) As *Byte
461 End Function
462
463 /*!
464 @brief 指定したコードページ用のEncodingインスタンスの取得。
465 */
466 Static Function GetEncoding(codepage As Long) As Encoding
467 End Function
468' Static Function GetEncoding(codepage As Long, encoderFallback As EncoderFallback, decoderFallback As DecoderFallback) As Encoding
469' End Function
470 /*!
471 @brief 指定した符号化形式名用のEncodingインスタンスの取得。
472 */
473 Static Function GetEncoding(name As String) As Encoding
474 End Function
475' Static Function GetEncoding(name As String, encoderFallback As EncoderFallback, decoderFallback As DecoderFallback) As Encoding
476' End Function
477
478 /*!
479 @brief システム既定のANSIコードページ用のEncodingインスタンスの取得。
480 */
481 Static Function Default() As Encoding
482 End Function
483 /*!
484 @brief UTF-7用のEncodingインスタンスの取得。
485 */
486 Static Function UTF7() As Encoding
487 End Function
488 /*!
489 @brief UTF-8用のEncodingインスタンスの取得。
490 */
491 Static Function UTF8() As Encoding
492 End Function
493 /*!
494 @brief UTF-16LE用のEncodingインスタンスの取得。
495 */
496 Static Function UTF16() As Encoding
497 End Function
498 /*!
499 @brief UTF-16BE用のEncodingインスタンスの取得。
500 */
501 Static Function UTF16BE() As Encoding
502 End Function
503 /*!
504 @brief UTF-32LE用のEncodingインスタンスの取得。
505 */
506 Static Function UTF32() As Encoding
507 End Function
508End Class
509
510/*!
511@brief 復号を行うクラス
512@date 2007/12/19
513@auther Egtra
514*/
515Class Decoder
516Public
517 /*!
518 @brief 変換する
519 @param[in] bytes 入力
520 @param[in] byteIndex 入力開始位置
521 @param[in] byteCount 入力要素数
522 @param[out] chars 出力
523 @param[in] charIndex 出力開始位置
524 @param[in] charCount 出力要素数
525 @param[in] flush 終了後に内部状態を初期化するかどうか
526 @param[out] charsUsed 使用された入力の要素数
527 @param[out] bytesUsed 出力の内、実際に書き込まれた要素数
528 @param[out] completed 入力の全ての文字が変換に使われたかどうか
529 */
530 Sub Convert(bytes As *Byte, byteIndex As Long, byteCount As Long,
531 chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean,
532 ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
533
534 If bytes = 0 Then
535 Throw New ArgumentNullException("bytes")
536 ElseIf byteIndex < 0 Then
537 Throw New ArgumentOutOfRangeException("byteIndex")
538 ElseIf byteCount < 0 Then
539 Throw New ArgumentOutOfRangeException("byteCount")
540 ElseIf chars = 0 Then
541 Throw New ArgumentNullException("chars")
542 ElseIf charIndex < 0 Then
543 Throw New ArgumentOutOfRangeException("charIndex")
544 ElseIf charCount < 0 Then
545 Throw New ArgumentOutOfRangeException("charCount")
546 End If
547 ConvertCore(VarPtr(bytes[byteIndex]), byteCount, VarPtr(chars[charIndex]), charCount, flush, bytesUsed, charsUsed, completed)
548 End Sub
549
550 /*!
551 @overload Sub Convert(bytes As *Byte, byteIndex As Long, byteCount As Long,
552 chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean,
553 ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
554 */
555 Sub Convert(bytes As *Byte, byteCount As Long,
556 chars As *WCHAR, charCount As Long, flush As Boolean,
557 ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
558
559 If bytes = 0 Then
560 Throw New ArgumentNullException("bytes")
561 ElseIf byteCount < 0 Then
562 Throw New ArgumentOutOfRangeException("byteCount")
563 ElseIf chars = 0 Then
564 Throw New ArgumentNullException("chars")
565 ElseIf charCount < 0 Then
566 Throw New ArgumentOutOfRangeException("charCount")
567 End If
568 ConvertCore(bytes, byteCount, chars, charCount, flush, bytesUsed, charsUsed, completed)
569 End Sub
570
571 /*!
572 @brief 変換する
573 @param[in] bytes 入力
574 @param[in] byteIndex 入力開始位置
575 @param[in] byteCount 入力要素数
576 @param[out] chars 出力
577 @param[in] charIndex 出力開始位置
578 @param[in] charCount 出力要素数
579 @param[in] flush 終了後に内部状態を初期化するかどうか
580 @return 出力の内、実際に書き込まれた要素数
581 */
582 Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean) As Long
583 Dim bytesUsed As Long
584 Dim completed As Boolean
585 Convert(bytes, byteIndex, byteCount, chars, charIndex, charCount, flush, bytesUsed, GetChars, completed)
586 End Function
587
588 /*!
589 @overload Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean) As Long
590 */
591 Function GetChars(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long, flush As Boolean) As Long
592 Dim bytesUsed As Long
593 Dim completed As Boolean
594 Convert(bytes, byteCount, chars, charCount, flush, bytesUsed, GetChars, completed)
595 End Function
596
597 /*!
598 @overload Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean) As Long
599 */
600 Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long) As Long
601 GetChars = GetChars(bytes, byteIndex, byteCount, chars, charIndex, charCount, False)
602 End Function
603
604 /*!
605 @brief フォールバックの取得
606 */
607 Function Fallback() As DecoderFallback
608 Return fallback
609 End Function
610
611 /*!
612 @brief フォールバックの設定
613 */
614 Sub Fallback(newFallback As DecoderFallback)
615 If ActiveBasic.IsNothing(newFallback) Then
616 Throw New ArgumentNullException("newFallback")
617 End If
618 fallback = newFallback
619 End Sub
620Protected
621 /*!
622 @brief 実際に変換するメソッド
623 @param[in] bytes 入力
624 @param[in] byteCount 入力要素数
625 @param[out] chars 出力
626 @param[in] charCount 出力要素数
627 @param[in] flush 終了後に内部状態を初期化するかどうか
628 @param[out] charsUsed 使用された入力の要素数
629 @param[out] bytesUsed 出力の内、実際に書き込まれた要素数
630 @param[out] completed 入力の全ての文字が変換に使われたかどうか
631 */
632 Abstract Sub ConvertCore(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long, flush As Boolean,
633 ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
634
635Private
636 fallback As DecoderFallback
637End Class
638
639/*!
640@brief 符号化を行うクラス
641@date 2007/12/19
642@auther Egtra
643*/
644Class Encoder
645Public
646 /*!
647 @brief 変換する
648 @param[in] chars 入力
649 @param[in] charIndex 入力開始位置
650 @param[in] charCount 入力要素数
651 @param[out] bytes 出力
652 @param[in] byteIndex 出力開始位置
653 @param[in] byteCount 出力要素数
654 @param[in] flush 終了後に内部状態を初期化するかどうか
655 @param[out] charsUsed 使用された入力の要素数
656 @param[out] bytesUsed 出力の内、実際に書き込まれた要素数
657 @param[out] completed 入力の全ての文字が変換に使われたかどうか
658 */
659 Sub Convert(chars As *WCHAR, charIndex As Long, charCount As Long,
660 bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean,
661 ByRef charsUsed As Long, ByRef bytesUsed As Long, ByRef completed As Boolean)
662
663 If chars = 0 Then
664 Throw New ArgumentNullException("chars")
665 ElseIf charIndex < 0 Then
666 Throw New ArgumentOutOfRangeException("charIndex")
667 ElseIf charCount < 0 Then
668 Throw New ArgumentOutOfRangeException("charCount")
669 ElseIf bytes = 0 Then
670 Throw New ArgumentNullException("bytes")
671 ElseIf byteIndex < 0 Then
672 Throw New ArgumentOutOfRangeException("byteIndex")
673 ElseIf byteCount < 0 Then
674 Throw New ArgumentOutOfRangeException("byteCount")
675 End If
676 ConvertCore(VarPtr(chars[charIndex]), charCount, VarPtr(bytes[byteIndex]), byteCount, flush, charsUsed, bytesUsed, completed)
677 End Sub
678
679 /*!
680 @overload Sub Convert(chars As *WCHAR, charIndex As Long, charCount As Long,
681 bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean,
682 ByRef charsUsed As Long, ByRef bytesUsed As Long, ByRef completed As Boolean)
683 */
684 Sub Convert(chars As *WCHAR, charCount As Long,
685 bytes As *Byte, byteCount As Long, flush As Boolean,
686 ByRef charsUsed As Long, ByRef bytesUsed As Long, ByRef completed As Boolean)
687
688 If chars = 0 Then
689 Throw New ArgumentNullException("chars")
690 ElseIf charCount < 0 Then
691 Throw New ArgumentOutOfRangeException("charCount")
692 ElseIf bytes = 0 Then
693 Throw New ArgumentNullException("bytes")
694 ElseIf byteCount < 0 Then
695 Throw New ArgumentOutOfRangeException("byteCount")
696 End If
697 ConvertCore(chars, charCount, bytes, byteCount, flush, charsUsed, bytesUsed, completed)
698 End Sub
699
700 /*!
701 @brief 変換する
702 @param[in] chars 入力
703 @param[in] charIndex 入力開始位置
704 @param[in] charCount 入力要素数
705 @param[out] bytes 出力
706 @param[in] byteIndex 出力開始位置
707 @param[in] byteCount 出力要素数
708 @param[in] flush 終了後に内部状態を初期化するかどうか
709 @return bytesUsed 出力の内、実際に書き込まれた要素数
710 */
711 Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean) As Long
712 Dim charsUsed As Long
713 Dim completed As Boolean
714 Convert(chars, charIndex, charCount, bytes, byteIndex, byteCount, flush, charsUsed, GetBytes, completed)
715 End Function
716
717 /*!
718 @overload Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean) As Long
719 */
720 Function GetBytes(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long, flush As Boolean) As Long
721 Dim charsUsed As Long
722 Dim completed As Boolean
723 Convert(chars, charCount, bytes, byteCount, flush, charsUsed, GetBytes, completed)
724 End Function
725
726 /*!
727 @overload Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean) As Long
728 */
729 Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long) As Long
730 GetBytes = GetBytes(chars, charIndex, charCount, bytes, byteIndex, byteCount, False)
731 End Function
732
733 /*!
734 @brief フォールバックの取得
735 */
736 Function Fallback() As EncoderFallback
737 Return fallback
738 End Function
739
740 /*!
741 @brief フォールバックの設定
742 */
743 Sub Fallback(newFallback As EncoderFallback)
744 If ActiveBasic.IsNothing(newFallback) Then
745 Throw New ArgumentNullException("newFallback")
746 End If
747 fallback = newFallback
748 End Sub
749Protected
750 /*!
751 @brief 実際に変換するメソッド
752 @param[in] chars 入力
753 @param[in] charCount 入力要素数
754 @param[out] bytes 出力
755 @param[in] byteCount 出力要素数
756 @param[in] flush 終了後に内部状態を初期化するかどうか
757 @param[out] bytesUsed 使用された入力の要素数
758 @param[out] charsUsed 出力の内、実際に書き込まれた要素数
759 @param[out] completed 入力の全ての文字が変換に使われたかどうか
760 */
761 Abstract Sub ConvertCore(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long, flush As Boolean,
762 ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
763
764Private
765 fallback As EncoderFallback
766End Class
767
768Enum NormalizationForm
769 FormC
770 FormD
771 FormKC
772 FormKD
773End Enum
774
775Class EncoderFallback
776End Class
777
778End Namespace 'Text
779End Namespace 'System
Note: See TracBrowser for help on using the repository browser.