- Timestamp:
- Feb 16, 2009, 4:26:24 PM (16 years ago)
- Location:
- trunk/ab5.0/ablib
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/TestCase/SimpleTestCase/EncodingTest.ab
r653 r682 1 1 Imports System.Text 2 2 Imports System.Text.Detail 3 /* 3 4 4 Namespace EncodingTest 5 5 … … 27 27 28 28 Dim utf8 = New UTF8Encoding 29 Dim e = utf8.GetEncoder 30 Dim d = utf8.GetDecoder 29 Dim e = utf8.GetEncoder() 30 Dim d = utf8.GetDecoder() 31 31 Dim b[256] As Byte 32 32 Dim u16[256] As WCHAR 33 e.GetBytes(chars, Len(chars) \ SizeOf (WCHAR), b, Len(b), False) 34 UnitTest("UTF8 Encode", memcmp(b, utf8bytes, Len(utf8bytes)) = 0) 35 d.GetChars(utf8bytes, Len(utf8bytes), u16, Len(u16) \ SizeOf (WCHAR), False) 36 UnitTest("UTF8 Decode", memcmp(u16, chars, Len(chars)) = 0) 33 Dim len As Long 34 35 len = utf8.GetBytesCount(chars, Len(chars) \ SizeOf(WCHAR)) 36 UnitTest("UTF-8 GetByteCount", len = Len(utf8bytes)) 37 utf8.GetBytes(chars, Len(chars) \ SizeOf (WCHAR), b, Len(b)) 38 UnitTest("UTF-8 Encode", memcmp(b, utf8bytes, Len(utf8bytes)) = 0) 39 40 len = utf8.GetCharsCount(utf8bytes, Len(utf8bytes)) 41 UnitTest("UTF-8 GetCharCount", len = Len(chars) \ SizeOf(WCHAR)) 42 utf8.GetChars(utf8bytes, Len(utf8bytes), u16, Len(u16) \ SizeOf (WCHAR)) 43 UnitTest("UTF-8 Decode", memcmp(u16, chars, Len(chars)) = 0) 37 44 End Sub 38 45 … … 40 47 41 48 EncodingTest.TestMain() 42 */ 49 -
trunk/ab5.0/ablib/src/Classes/System/Exception.ab
r602 r682 14 14 Const AB_E_PLATFORMNOTSUPPORTED = &h80041539 '80131539 15 15 Const AB_E_KEYNOTFOUND = &h80041577 '80131577 16 Const AB_E_ARITHMETIC = &h80040216 '80070216 17 Const AB_E_OVERFLOW = &h80041516 '80131516 16 18 17 19 End Namespace … … 38 40 MulticastNotSupportedException 39 41 NullReferenceException 40 OverflowException41 42 RankException 42 43 StackOverflowException … … 712 713 End Class 713 714 715 /*! 716 @brief 算術演算例外 717 @author Egtra 718 @date 2009/02/16 719 */ 720 Class ArithmeticException 721 Inherits SystemException 722 Public 723 /*! 724 @biref コンストラクタ 725 */ 726 Sub ArithmeticException() 727 SystemException("ArithmeticException", Nothing) 728 HResult = ActiveBasic.AB_E_ARITHMETIC 729 End Sub 730 /*! 731 @biref コンストラクタ 732 @param[in] message エラーメッセージ 733 */ 734 Sub ArithmeticException(message As String) 735 SystemException(message, Nothing) 736 HResult = ActiveBasic.AB_E_ARITHMETIC 737 End Sub 738 /*! 739 @biref コンストラクタ 740 @param[in] message エラーメッセージ 741 @param[in] innerException 内部例外 742 */ 743 Sub ArithmeticException(message As String, innerException As Exception) 744 SystemException(message, innerException) 745 HResult = ActiveBasic.AB_E_ARITHMETIC 746 End Sub 747 End Class 748 749 /*! 750 @brief オーバーフロー例外 751 @author Egtra 752 @date 2009/02/16 753 */ 754 Class OverflowException 755 Inherits ArithmeticException 756 Public 757 /*! 758 @biref コンストラクタ 759 */ 760 Sub OverflowException() 761 ArithmeticException("OverflowException", Nothing) 762 HResult = ActiveBasic.AB_E_OVERFLOW 763 End Sub 764 /*! 765 @biref コンストラクタ 766 @param[in] message エラーメッセージ 767 */ 768 Sub OverflowException(message As String) 769 ArithmeticException(message, Nothing) 770 HResult = ActiveBasic.AB_E_OVERFLOW 771 End Sub 772 /*! 773 @biref コンストラクタ 774 @param[in] message エラーメッセージ 775 @param[in] innerException 内部例外 776 */ 777 Sub OverflowException(message As String, innerException As Exception) 778 ArithmeticException(message, innerException) 779 HResult = ActiveBasic.AB_E_OVERFLOW 780 End Sub 781 End Class 714 782 715 783 End Namespace -
trunk/ab5.0/ablib/src/Classes/System/IO/MemoryStream.ab
r617 r682 339 339 End Function*/ 340 340 341 Function ToPointer() As VoidPtr 342 ToPointer = pointer 343 End Function 344 341 345 /*! 342 346 @brief ストリームの内容全体をまるごと別のストリームに書き込みます。 -
trunk/ab5.0/ablib/src/Classes/System/IO/Stream.ab
r609 r682 155 155 End Class 156 156 157 /*! 158 @brief 書き込みバイト数を記憶するヌルストリーム 159 Encoding関連で使用 160 @date 2009/02/16 161 @auther Egtra 162 */ 163 Class WriteCountingNullStream 164 Inherits NullStream 165 Public 166 Sub WriteCountingNullStream() 167 writeCount = 0 168 End Sub 169 170 Override Sub Write(buffer As *Byte, offset As Long, count As Long) 171 If count < 0 Then 172 Throw New ArgumentOutOfRangeException("count") 173 End If 174 writeCount += count 175 End Sub 176 177 Override Sub WriteByte(b As Byte) 178 writeCount++ 179 End Sub 180 181 /*! 182 @brief 書き込まれたバイト数を返す。 183 */ 184 Function WriteCount() As Long 185 WriteCount = writeCount 186 End Function 187 188 Private 189 writeCount As Long 190 End Class 191 157 192 End Namespace 158 193 -
trunk/ab5.0/ablib/src/Classes/System/IO/StreamWriter.ab
r676 r682 20 20 */ 21 21 Sub StreamWriter(path As String) 22 init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None) )22 init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None), Nothing) 23 23 End Sub 24 24 … … 28 28 */ 29 29 Sub StreamWriter(stream As Stream) 30 init(stream) 30 init(stream, Nothing) 31 End Sub 32 33 /* 34 @date 2009/02/16 35 @auther Egtra 36 */ 37 Sub StreamWriter(stream As Stream, encoding As Text.Encoding) 38 init(stream, encoding) 31 39 End Sub 32 40 … … 83 91 84 92 Private 85 Sub init(stream As Stream )93 Sub init(stream As Stream, e As Text.Encoding) 86 94 s = stream 87 95 buf = New Text.StringBuilder(4096) 88 '暫定。正式版ではUTF-8を標準とする。 89 encoder = New Text.Detail.WindowsCodePageEncoder(CP_ACP) 96 If ActiveBasic.IsNothing(e) Then 97 '暫定。正式版ではUTF-8を標準とする。 98 encoder = New Text.Detail.WindowsCodePageEncoder(CP_ACP) 99 Else 100 encoder = e.GetEncoder() 101 End If 90 102 End Sub 91 103 -
trunk/ab5.0/ablib/src/Classes/System/Text/Encoding.ab
r676 r682 74 74 @date 2007/12/08 75 75 */ 76 Abstract Function GetBytesCountCore(src As *WCHAR, srcCount As Long) As Long 76 Virtual Function GetBytesCountCore(src As *WCHAR, srcCount As Long) As Long 77 Dim s = New IO.Detail.WriteCountingNullStream 78 GetEncoder().Encode(src, srcCount, s, True) 79 GetBytesCountCore = s.WriteCount 80 If GetBytesCountCore < 0 Then 81 Throw New OverflowException 82 End If 83 End Function 77 84 Public 78 85 /*! … … 110 117 @date 2007/12/08 111 118 */ 112 Abstract Function GetBytesCore(src As *WCHAR, srcCount As Long, dst As *Byte, dstCount As Long) As Long 119 Virtual Function GetBytesCore(src As *WCHAR, srcCount As Long, dst As *Byte, dstCount As Long) As Long 120 Dim s = New IO.MemoryStream 121 GetEncoder().Encode(src, srcCount, s, True) 122 Dim size = s.Position() 123 If size > (dstCount As QWord) Then 124 Throw New ArgumentException("dstCount") 125 End If 126 GetBytesCore = size As Long 127 memcpy(dst, s.ToPointer(), size As SIZE_T) 128 End Function 113 129 Public 114 130 /*! … … 136 152 @date 2007/12/08 137 153 */ 138 Abstract Function GetCharsCountCore(src As *Byte, srcCount As Long) As Long 154 Virtual Function GetCharsCountCore(src As *Byte, srcCount As Long) As Long 155 Dim s = New IO.MemoryStream(src, srcCount) 156 Dim l = New Collections.Generic.List<WCHAR> 157 GetDecoder().Decode(l, s) 158 GetCharsCountCore = l.Count 159 End Function 139 160 Public 140 161 /*! … … 172 193 @date 2007/12/08 173 194 */ 174 Abstract Function GetCharsCore(src As *Byte, srcCount As Long, dst As *WCHAR, dstCount As Long) As Long 195 Virtual Function GetCharsCore(src As *Byte, srcCount As Long, dst As *WCHAR, dstCount As Long) As Long 196 Dim s = New IO.MemoryStream(src, srcCount) 197 Dim l = New Collections.Generic.List<WCHAR> 198 GetDecoder().Decode(l, s) 199 If l.Count > dstCount Then 200 Throw New ArgumentException("dstCount") 201 End If 202 Dim p As *WCHAR 203 p = l 204 memcpy(dst, p, (l.Count As SIZE_T) * 2) 205 End Function 175 206 Public 176 207 #ifdef UNICODE -
trunk/ab5.0/ablib/src/Classes/System/Text/UTF8Encoding.ab
r676 r682 111 111 dst.Add((&hDC00 Or (buffer And &h3FF)) As WCHAR) 112 112 Else 113 '最短形式でないもの、 4バイト形式で10FFFFを超えるコードポイントのもの113 '最短形式でないもの、または4バイト形式で10FFFFを超えるコードポイントのもの 114 114 dst.Add(&hfffd As WCHAR) 115 115 End If … … 196 196 End Function 197 197 */ 198 Protected199 Override Function GetBytesCountCore(src As *WCHAR, srcCount As Long) As Long200 End Function201 202 Override Function GetBytesCore(src As *WCHAR, srcCount As Long, dst As *Byte, dstCount As Long) As Long203 End Function204 205 Override Function GetCharsCountCore(src As *Byte, srcCount As Long) As Long206 End Function207 208 Override Function GetCharsCore(src As *Byte, srcCount As Long, dst As *WCHAR, dstCount As Long) As Long209 End Function210 198 211 199 Private
Note:
See TracChangeset
for help on using the changeset viewer.