source: trunk/Include/Classes/System/Text/DecoderFallback.ab@ 411

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

UTF8Encoding(仮)の追加

File size: 5.3 KB
Line 
1/*!
2@file Classes/System/IO/Fallback.ab
3@date 2007/12/09
4*/
5
6Namespace System
7Namespace Text
8
9/*!
10@brief 復号時、復号できないバイト並びに遭遇したときの処理を提供する
11@date 2007/12/09
12@auther Egtra
13*/
14Class DecoderFallback
15Public
16 /*!
17 @brief フォールバックを行う
18 @param[in] bytesUnknown 復号中の文字列
19 @param[in] len bytesUnknownの要素数
20 @param[in] index 問題の列の開始位置
21 @param[out] bufLen 戻り値の要素数
22 @return フォールバック文字列
23 */
24 Abstract Function Fallback(bytesUnknown As *Byte, len As Long, index As Long, ByRef bufLen As Long) As *WCHAR
25
26 /*!
27 @brief このDecoderFallbackの処理で生成される可能性のある最大の文字列の長さを返す。
28 */
29 Abstract Function MaxCharCount() As Long
30
31 /*!
32 @brief フォールバックとして、例外を投げるDecoderFallbackを返す。
33 @bug 未実装
34 */
35 Static Function ExceptionFallback() As DecoderFallback
36 End Function
37
38 /*!
39 @brief フォールバックとして、適当な文字に変換するDecoderFallbackを返す。
40 */
41 Static Function ReplacementFallback() As DecoderFallback
42 ReplacementFallback = replacementFallback
43 End Function
44
45Private
46 Static replacementFallback = New DecoderReplacementFallback
47End Class
48
49/*!
50@brief 復号時、復号できないバイト並びに遭遇したときの処理を提供する
51@date 2007/12/09
52@auther Egtra
53*/
54Class DecoderReplacementFallback
55 Inherits DecoderFallback
56Public
57 /*!
58 @brief 既定のフォールバック文字列でDecoderReplacementFallbackを構築する。
59 */
60 Sub DecoderReplacementFallback()
61 str = VarPtr(default)
62 len = 1
63 End Sub
64
65 /*!
66 @brief 指定された文字列でDecoderReplacementFallbackを構築する。
67 @param[in] replacement 代替文字列
68 @param[in] length replacementの長さ
69 */
70 Sub DecoderReplacementFallback(replacement As *WCHAR, length As Long)
71 If replacement = 0 Then
72 Throw New ArgumentNullException("replacement")
73 ElseIf length < 0 Then
74 Throw New ArgumentOutOfRangeException("length")
75 End If
76 str = replacement
77 len = length
78 End Sub
79#ifndef __STRING_IS_NOT_UNICODE
80 /*!
81 @brief 指定された文字列でDecoderReplacementFallbackを構築する。
82 @param[in] replacement 代替文字列
83 */
84 Sub DecoderReplacementFallback(replacement As String)
85 If ActiveBasic.IsNothing(replacement) Then
86 Throw New ArgumentNullException("replacement")
87 End If
88 With replacement
89 str = .StrPtr
90 len = .Length
91 End With
92 End Sub
93#endif
94 /*!
95 @brief フォールバックを行う。
96 */
97 Override Function Fallback(bytesUnknown As *Byte, bytesLen As Long, index As Long, ByRef bufLen As Long) As *WCHAR
98 bufLen = len
99 Dim bufSize = len * SizeOf (WCHAR)
100 Fallback = GC_malloc_atomic(bufSize)
101 memcpy(Fallback, str, bufSize)
102 End Function
103 /*!
104 @brief このDecoderFallbackの処理で生成される可能性のある最大の文字列の長さを返す。
105 */
106 Override Function MaxCharCount() As Long
107 MaxCharCount = len
108 End Function
109 /*!
110 @brief 代替文字列を返す
111 @return 代替文字列へのポインタ
112
113 長さはDefaultStringLengthで得られる
114 */
115 Function DefaultStringArray() As *WCHAR
116 DefaultStringArray = str
117 End Function
118
119 /*!
120 @brief 代替文字列の長さを返す
121 */
122 Function DefaultStringLength() As Long
123 DefaultStringLength = len
124 End Function
125
126#ifndef __STRING_IS_NOT_UNICODE
127 /*!
128 @brief 代替文字列を返す
129 @return 代替文字列
130 */
131 Function DefaultString() As String
132 DefaultString = New String(str, len)
133 End Function
134#endif
135
136Private
137 str As *WCHAR
138 len As Long
139
140 Static default = &h3f As WCHAR '? 疑問符
141End Class
142
143/*!
144@brief
145@date 2007/12/27
146@auther Egtra
147*/
148Class DecoderExceptionFallback
149 Inherits DecoderFallback
150Public
151 /*!
152 @brief
153 */
154 Sub DecoderExceptionFallback()
155 End Sub
156
157 /*!
158 @brief 指定された文字列でDecoderReplacementFallbackを構築する。
159 @param[in] replacement 代替文字列
160 @param[in] length replacementの長さ
161 */
162 Sub DecoderReplacementFallback(replacement As *WCHAR, length As Long)
163 If replacement = 0 Then
164 Throw New ArgumentNullException("replacement")
165 ElseIf length < 0 Then
166 Throw New ArgumentOutOfRangeException("length")
167 End If
168 End Sub
169#ifndef __STRING_IS_NOT_UNICODE
170 /*!
171 @brief 指定された文字列でDecoderReplacementFallbackを構築する。
172 @param[in] replacement 代替文字列
173 */
174 Sub DecoderReplacementFallback(replacement As String)
175 If ActiveBasic.IsNothing(replacement) Then
176 Throw New ArgumentNullException("replacement")
177 End If
178 With replacement
179 str = .StrPtr
180 len = .Length
181 End With
182 End Sub
183#endif
184 /*!
185 @brief フォールバックを行う。
186 @exception DecoderFallbackException
187 */
188 Override Function Fallback(bytesUnknown As *Byte, bytesLen As Long, index As Long, ByRef bufLen As Long) As *WCHAR
189 'Throw New DecoderFallbackException
190 End Function
191
192 /*!
193 @brief このDecoderFallbackの処理で生成される可能性のある最大の文字列の長さを返す。
194 @return 常に0
195 */
196 Override Function MaxCharCount() As Long
197 MaxCharCount = 0
198 End Function
199End Class
200
201/*!
202@brief DecoderExceptionFallbackでフォールバックが起こった時に投げられる例外
203@date 2007/12/27
204@auther Egtra
205*/
206Class DecoderFallbackException
207 Inherits ArgumentException
208Public
209 Sub DecoderFallbackException()
210
211 End Sub
212
213 Sub DecoderFallbackException(message As String)
214 End Sub
215
216 Sub DecoderFallbackException(message As String, innerException As Exception)
217 End Sub
218
219'bytesの大きさはどうしよう
220 Sub DecoderFallbackException(message As String, bytesUnknown As *Byte, index As Long)
221 End Sub
222
223
224End Class
225
226End Namespace 'Text
227End Namespace 'System
Note: See TracBrowser for help on using the repository browser.