Changeset 468
- Timestamp:
- Mar 9, 2008, 12:00:01 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
r457 r468 1 'Classes/ActiveBasic/Strings/SPrintF.ab 1 /*! 2 @file Include/Classes/ActiveBasic/Strings/SPrintF.ab 3 @brief SPrintfとその補助ルーチンが含まれるファイル。 4 5 SPrintfで数値変換が行われるとき、呼出の階層は、 6 SPrintf→FormatInteger, FormatFloat→FormatIntegerEx, FormatFloatExとなる。 7 8 また、次のような変換ルーチンが存在する。 9 @li FormatFloatE 10 @li FormatFloatF 11 @li FormatFloatG 12 @li FormatFloatA 13 @li FormatIntegerD 14 @li FormatIntegerU 15 @li FormatIntegerO 16 @li FormatIntegerX 17 @li FormatCharacter 18 @li FormatString 19 */ 2 20 3 21 Namespace ActiveBasic … … 92 110 LeftSide = &h8 93 111 /*! 代替表記、#。 94 <ul> 95 <li>[OoXx]では、値が0でない場合、先頭に0、0xを付ける。</ul> 96 <li>[AaEeFfGg]では、精度0でも小数点を付ける。</ul> 97 <li>[Gg]では、それに加え、小数部末尾の0の省略を行わないようにする。</ul> 98 </ul> 112 @li [OoXx]では、値が0でない場合、先頭に0、0xを付ける。</ul> 113 @li [AaEeFfGg]では、精度0でも小数点を付ける。</ul> 114 @li [Gg]では、それに加え、小数部末尾の0の省略を行わないようにする。</ul> 99 115 */ 100 116 Alt = &h10 … … 121 137 @param[in] flags 書式フラグ。 122 138 @return xの文字列表現 123 139 */ 140 Function FormatFloatE(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String 141 FormatFloatE = FormatFloatEx(AddressOf(FormatFloatE_Convert), x, precision, field, flags) 142 End Function 143 144 /* 145 @brief 浮動小数点数をprintfの%e, %E(指数形式、十進法)相当の変換で文字列化する関数。 146 @author Egtra 147 @date 2008/03/08 148 @param[in,out] sb 書式化した文字列を追加するバッファ。 149 @param[in] x 文字列化する浮動小数点数値。 150 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。 151 @param[in] field フィールド幅。 152 @param[in] flags 書式フラグ。 153 */ 154 Sub FormatFloatE(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 155 FormatFloatEx(sb, AddressOf(FormatFloatE_Convert), x, precision, field, flags) 156 End Sub 157 158 /*! 159 @brief 浮動小数点数をprintfの%e, %E(指数形式、十進法)相当の変換で文字列化する関数。 160 @author Egtra 161 @date 2008/03/07 162 @param[in,out] sb 書式化した文字列を追加するバッファ。 163 @param[in] x 文字列化する浮動小数点数値。 164 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして15となる。 165 @param[in] field フィールド幅。 166 @param[in,out] flags 書式フラグ。 124 167 @todo 他の実装での末尾桁の扱いを調べる(このコードでは何もしていないので切捨となっている)。 125 168 */ 126 Function FormatFloatE(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String 169 Sub FormatFloatE_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 127 170 If precision = DWORD_MAX Then 128 precision = 6 129 End If 130 171 precision = 15 172 End If 131 173 Dim e As Long, negative As Boolean 132 174 Dim s = FloatToChars(x, e, negative) 133 Dim sb = FormatFloatE_Base(s, negative, precision, flags)175 FormatFloatE_Base(sb, s, negative, precision, flags) 134 176 FormatFloatE_Exponent(sb, e, flags) 135 AdjustFieldWidth(sb, field, flags) 136 FormatFloatE = sb.ToString() 137 End Function 177 End Sub 138 178 139 179 /** … … 142 182 @date 2007/10/27 143 183 */ 144 Function FormatFloatE_Base(s As String, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) As System.Text.StringBuilder 145 FormatFloatE_Base = New System.Text.StringBuilder 146 With FormatFloatE_Base 147 AppendSign(FormatFloatE_Base, negative, flags) 148 184 Sub FormatFloatE_Base(sb As System.Text.StringBuilder, s As String, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) 185 With sb 186 AppendSign(sb, negative, flags) 149 187 .Append(s[0]) 150 151 188 If (flags And Alt) Or precision > 0 Then 152 189 .Append(".") … … 156 193 Else 'sで用意された桁が指定された精度より少ないとき 157 194 .Append(s, 1, outputLen) 158 .Append(&h30 As StrChar, precision - outputLen) '足りない桁は0埋め195 .Append(&h30 As Char, precision - outputLen) '足りない桁は0埋め 159 196 End If 160 197 End If 161 198 End With 162 End Function199 End Sub 163 200 164 201 /** … … 167 204 @date 2007/10/27 168 205 */ 169 Sub FormatFloatE_Exponent( bufAs System.Text.StringBuilder, e As Long, flags As FormatFlags)170 With buf206 Sub FormatFloatE_Exponent(sb As System.Text.StringBuilder, e As Long, flags As FormatFlags) 207 With sb 171 208 If flags And Cap Then 172 209 .Append("E") … … 174 211 .Append("e") 175 212 End If 176 .Append(FormatIntegerD(e, 2, 0, Sign Or Zero))213 FormatIntegerD(sb, e, 2, 0, Sign Or Zero) 177 214 End With 178 215 End Sub … … 183 220 @date 2007/10/23 184 221 @param[in] x 文字列化する浮動小数点数値。 185 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値 6となる。222 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値15となる。 186 223 @param[in] field フィールド幅。 187 224 @param[in] flags 書式フラグ。 … … 189 226 */ 190 227 Function FormatFloatF(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String 228 FormatFloatF = FormatFloatEx(AddressOf(FormatFloatF_Convert), x, precision, field, flags) 229 End Function 230 231 /* 232 @brief 浮動小数点数をprintfの%f(小数形式、十進法)相当の変換で文字列化する関数。 233 @author Egtra 234 @date 2008/03/08 235 @param[in,out] sb 書式化した文字列を追加するバッファ。 236 @param[in] x 文字列化する浮動小数点数値。 237 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。 238 @param[in] field フィールド幅。 239 @param[in] flags 書式フラグ。 240 */ 241 Sub FormatFloatF(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 242 FormatFloatEx(sb, AddressOf(FormatFloatF_Convert), x, precision, field, flags) 243 End Sub 244 245 /*! 246 @brief 浮動小数点数をprintfの%f(小数形式、十進法)相当の変換で文字列化する関数。 247 @author Egtra 248 @date 2008/03/07 249 @param[in,out] sb 書式化した文字列を追加するバッファ。 250 @param[in] x 文字列化する浮動小数点数値。 251 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値15となる。 252 @param[in] field フィールド幅。 253 @param[in,out] flags 書式フラグ。 254 */ 255 Sub FormatFloatF_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 191 256 If precision = DWORD_MAX Then 192 precision = 6 193 End If 194 257 precision = 15 258 End If 195 259 Dim e As Long, negative As Boolean 196 260 Dim s = FloatToChars(x, e, negative) 197 Dim sb = FormatFloatF_Core(s, e, negative, precision, flags) 198 AdjustFieldWidth(sb, field, flags) 199 FormatFloatF = sb.ToString() 200 End Function 261 FormatFloatF_Core(sb, s, e, negative, precision, flags) 262 End Sub 201 263 202 264 /** … … 204 266 @date 2007/10/27 205 267 */ 206 Function FormatFloatF_Core(s As String, e As Long, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) As System.Text.StringBuilder 207 FormatFloatF_Core = New System.Text.StringBuilder(128) 208 With FormatFloatF_Core 209 AppendSign(FormatFloatF_Core, negative, flags) 268 Sub FormatFloatF_Core(sb As System.Text.StringBuilder, s As String, e As Long, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) 269 With sb 270 AppendSign(sb, negative, flags) 210 271 211 272 Dim intPartLen = e + 1 … … 214 275 '有効桁が全て整数部に収まる場合 215 276 .Append(s) 216 .Append(&h30 As StrChar, intPartLen - 17)277 .Append(&h30 As Char, intPartLen - 17) 217 278 outputDigit = 17 218 279 ElseIf intPartLen > 0 Then … … 222 283 Else 223 284 '有効桁が全く整数部にかからない場合 224 .Append(&h30 As StrChar)285 .Append(&h30 As Char) 225 286 End If 226 287 … … 234 295 '1.23e-4 = 0.000123のように指数が負のため小数点以下に0が続く場合 235 296 zeroDigit = System.Math.Min(-intPartLen As DWord, precision) 236 .Append(&h30 As StrChar, zeroDigit As Long)297 .Append(&h30 As Char, zeroDigit As Long) 237 298 End If 238 299 .Append(s, outputDigit, (precision - zeroDigit) As Long) 239 300 Else 240 301 .Append(s, outputDigit, lastDigit) 241 .Append(&h30 As StrChar, (precision - lastDigit) As Long) '残りの桁は0埋め302 .Append(&h30 As Char, (precision - lastDigit) As Long) '残りの桁は0埋め 242 303 End If 243 304 End If 244 305 End With 245 End Function306 End Sub 246 307 247 308 /*! … … 250 311 @date 2007/10/23 251 312 @param[in] x 文字列化する浮動小数点数値。 252 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXまたは0のとき、指定なしとして既定値 6となる。313 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXまたは0のとき、指定なしとして既定値15となる。 253 314 @param[in] field フィールド幅。 254 315 @param[in] flags 書式フラグ。 … … 257 318 */ 258 319 Function FormatFloatG(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String 320 FormatFloatG = FormatFloatEx(AddressOf(FormatFloatG_Convert), x, precision, field, flags) 321 End Function 322 323 /* 324 @brief 浮動小数点数をprintfの%g, %G(小数・指数、十進法)相当の変換で文字列化する関数。 325 @author Egtra 326 @date 2008/03/08 327 @param[in,out] sb 書式化した文字列を追加するバッファ。 328 @param[in] x 文字列化する浮動小数点数値。 329 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。 330 @param[in] field フィールド幅。 331 @param[in] flags 書式フラグ。 332 */ 333 Sub FormatFloatG(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 334 FormatFloatEx(sb, AddressOf(FormatFloatG_Convert), x, precision, field, flags) 335 End Sub 336 337 /*! 338 @brief 浮動小数点数をprintfの%g, %G(小数・指数、十進法)相当の変換で文字列化する関数。 339 @author Egtra 340 @date 2007/10/23 341 @param[in,out] sb 書式化した文字列を追加するバッファ。 342 @param[in] x 文字列化する浮動小数点数値。 343 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXまたは0のとき、指定なしとして既定値15となる。 344 @param[in] field フィールド幅。 345 @param[in,out] flags 書式フラグ。 346 @todo 下位桁の扱いの調査。 347 */ 348 Sub FormatFloatG_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 259 349 'GではE/Fと違い整数部も有効桁数に数えるのでその分を引いておく。 260 350 If precision = DWORD_MAX Or precision = 0 Then 261 precision = 5351 precision = 14 262 352 Else 263 353 precision-- 264 354 End If 265 355 Dim lastLength = sb.Length 266 356 Dim e As Long, negative As Boolean 267 357 Dim s = FloatToChars(x, e, negative) 268 269 Dim sb = Nothing As System.Text.StringBuilder270 271 358 If -5 < e And e < precision Then 272 sb = FormatFloatF_Core(s, e, negative, -e + precision, flags)273 FormatFloatG_RemoveLowDigit(sb, flags)359 FormatFloatF_Core(sb, s, e, negative, -e + precision, flags) 360 FormatFloatG_RemoveLowDigit(sb, lastLength, flags) 274 361 Else 275 sb = FormatFloatE_Base(s, negative, precision, flags)276 FormatFloatG_RemoveLowDigit(sb, flags)362 FormatFloatE_Base(sb, s, negative, precision, flags) 363 FormatFloatG_RemoveLowDigit(sb, lastLength, flags) 277 364 FormatFloatE_Exponent(sb, e, flags) 278 365 End If 279 280 AdjustFieldWidth(sb, field, flags) 281 FormatFloatG = sb.ToString() 282 End Function 366 End Sub 283 367 284 368 /*! … … 290 374 flagsでAltが立っているとき、この関数は何もしない。 291 375 */ 292 Sub FormatFloatG_RemoveLowDigit(sb As System.Text.StringBuilder, flags As FormatFlags)376 Sub FormatFloatG_RemoveLowDigit(sb As System.Text.StringBuilder, start As Long, flags As FormatFlags) 293 377 Imports ActiveBasic.Strings 294 378 295 379 Dim count = sb.Length 296 380 If (flags And Alt) = 0 Then 297 Dim point = ChrFind(StrPtr(sb), count As SIZE_T, Asc(".")) 381 Dim p = StrPtr(sb) 382 Dim point = ChrFind(VarPtr(p[start]), (count - start) As SIZE_T, Asc(".")) 298 383 If point = -1 Then 299 384 Debug … … 327 412 */ 328 413 Function FormatFloatA(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String 414 FormatFloatA = FormatFloatEx(AddressOf(FormatFloatA_Convert), x, precision, field, flags) 415 End Function 416 417 /* 418 @brief 浮動小数点数をprintfの%a, %A(指数形式、十六進法)相当の変換で文字列化する関数。 419 @author Egtra 420 @date 2008/03/08 421 @param[in,out] sb 書式化した文字列を追加するバッファ。 422 @param[in] x 文字列化する浮動小数点数値。 423 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。 424 @param[in] field フィールド幅。 425 @param[in] flags 書式フラグ。 426 */ 427 Sub FormatFloatA(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 428 FormatFloatEx(sb, AddressOf(FormatFloatA_Convert), x, precision, field, flags) 429 End Sub 430 431 /*! 432 @brief 浮動小数点数をprintfの%a, %A(指数形式、十六進法)相当の変換で文字列化する関数。 433 @author Egtra 434 @date 2008/03/07 435 @param[in,out] sb 書式化した文字列を追加するバッファ。 436 @param[in] x 文字列化する浮動小数点数値。 437 @param[in] precision 精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値13となる。 438 @param[in] field フィールド幅。 439 @param[in,out] flags 書式フラグ。 440 441 C99では、末尾の0を取り除いても良いとあるので、 442 このルーチンでは取り除くことにしている。 443 */ 444 Sub FormatFloatA_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags) 329 445 If precision = DWORD_MAX Then 330 446 precision = 13 331 447 End If 332 448 Dim lastLength = sb.Length 333 449 Dim pqw = VarPtr(x) As *QWord 334 450 335 Dim sb = New System.Text.StringBuilder336 451 With sb 337 452 Dim sign = (GetQWord(pqw) And &H8000000000000000) As Boolean … … 362 477 If precision > 0 Or (flags And Alt) Then 363 478 .Append(".") 364 Dim base = FormatIntegerLX(GetQWord(pqw) And &h000fffffffffffff, 13, 0, flags And Cap) 365 Dim diff = precision - 13 As Long 366 If diff <= 0 Then 367 .Append(Left$(base, precision)) 479 Dim fraction = GetQWord(pqw) And &h000fffffffffffff 480 If precision < 13 Then 481 Dim dropped = 13 - precision 482 fraction >>= dropped * 4 483 FormatIntegerLX(sb, fraction, precision, 0, flags And Cap) 368 484 Else 369 .Append(base).Append(&h30, diff) 485 FormatIntegerLX(sb, fraction, 13, 0, flags And Cap) 486 .Append(&h30, precision - 13) 370 487 End If 371 488 End If 372 373 FormatFloatG_RemoveLowDigit(sb, flags) 374 489 FormatFloatG_RemoveLowDigit(sb, lastLength, flags) 375 490 .Append("P") 376 .Append(FormatIntegerD(exp, 1, 0, Sign)) 377 378 FormatFloatA = .ToString() 491 FormatIntegerD(sb, exp, 1, 0, Sign) 492 AdjustAlphabet(sb, flags, lastLength) 379 493 End With 380 381 If (flags And Cap) = 0 Then 382 FormatFloatA = FormatFloatA.ToLower() 383 End If 384 End Function 494 End Sub 385 495 386 496 /*! … … 408 518 409 519 /*! 410 @brief DWordの最大値4294967295の文字数 - 1。FormatIntegerU内で使用。411 @author Egtra412 @date 2007/09/18413 */414 Const MaxSizeU = 9415 416 /*!417 520 @brief 符号無し整数をprintfの%u(十進法表現)相当の変換で文字列化する関数。 418 521 @author Egtra … … 429 532 430 533 /*! 534 @brief 符号無し整数をprintfの%u(十進法表現)相当の変換で文字列化する関数。 535 @author Egtra 536 @date 2008/03/07 537 @param[in,out] sb 書式化した文字列を追加するバッファ。 538 @param[in] x 文字列化する整数値。 539 @param[in] d 精度、最小限表示される桁数。DWORD_MAXのとき、指定なしとして、既定値1となる。 540 @param[in] field フィールド幅。 541 @param[in] flags 書式フラグ。 542 */ 543 Sub FormatIntegerU(sb As System.Text.StringBuilder, x As DWord, d As DWord, field As DWord, flags As FormatFlags) 544 FormatIntegerEx(sb, TraitsIntegerU[0], x As QWord, d, field, flags And (Not (Sign Or Blank))) 545 End Sub 546 547 /*! 431 548 @brief FormatIntegerUのQWord版 432 549 @author Egtra … … 436 553 Return FormatIntegerEx(TraitsIntegerU[1], x, d, field, flags And (Not (Sign Or Blank))) 437 554 End Function 555 556 /*! 557 @brief FormatIntegerUのQWord版 558 @author Egtra 559 @date 2008/03/07 560 @param[in,out] sb 書式化した文字列を追加するバッファ。 561 @param[in] x 文字列化する整数値。 562 @param[in] d 精度、最小限表示される桁数。DWORD_MAXのとき、指定なしとして、既定値1となる。 563 @param[in] field フィールド幅。 564 @param[in] flags 書式フラグ。 565 */ 566 Sub FormatIntegerLU(sb As System.Text.StringBuilder, x As QWord, d As DWord, field As DWord, flags As FormatFlags) 567 FormatIntegerEx(sb, TraitsIntegerU[0], x, d, field, flags And (Not (Sign Or Blank))) 568 End Sub 438 569 439 570 /*! … … 452 583 453 584 /*! 585 @brief 符号有り整数をprintfの%d(十進法表現)相当の変換で文字列化する関数。 586 @author Egtra 587 @date 2008/03/07 588 @param[in,out] sb 書式化した文字列を追加するバッファ。 589 @param[in] x 文字列化する整数値。 590 @param[in] d 精度、最小限表示される桁数。DWORD_MAXのとき、指定なしとして、既定値1となる。 591 @param[in] field フィールド幅。 592 @param[in] flags 書式フラグ。 593 */ 594 Sub FormatIntegerD(sb As System.Text.StringBuilder, x As Long, d As DWord, field As DWord, flags As FormatFlags) 595 FormatIntegerEx(sb, TraitsIntegerD[0], (x As Int64) As QWord, d, field, flags) 596 End Sub 597 598 /*! 454 599 @brief FormatIntegerDのInt64版 455 600 @author Egtra … … 459 604 Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, d, field, flags) 460 605 End Function 606 607 /*! 608 @brief FormatIntegerDのInt64版 609 @author Egtra 610 @date 2007/10/26 611 */ 612 Sub FormatIntegerLD(sb As System.Text.StringBuilder, x As Int64, d As DWord, field As DWord, flags As FormatFlags) 613 FormatIntegerEx(sb, TraitsIntegerD[1], x As QWord, d, field, flags) 614 End Sub 461 615 462 616 /*! … … 468 622 .Convert = AddressOf(IntegerU_Convert) 469 623 .Prefix = AddressOf(IntegerU_Prefix) 470 .MaxSize = MaxSizeU471 624 End With 472 625 … … 474 627 .Convert = AddressOf(IntegerLU_Convert) 475 628 .Prefix = AddressOf(IntegerU_Prefix) 476 .MaxSize = MaxSizeLU477 629 End With 478 630 … … 485 637 .Convert = AddressOf(IntegerD_Convert) 486 638 .Prefix = AddressOf(IntegerD_Prefix) 487 .MaxSize = MaxSizeU488 639 End With 489 640 … … 491 642 .Convert = AddressOf(IntegerLD_Convert) 492 643 .Prefix = AddressOf(IntegerD_Prefix) 493 .MaxSize = MaxSizeLU494 644 End With 495 645 … … 505 655 @date 2007/10/26 506 656 */ 507 Function IntegerU_Convert(buf As * StrChar, xq As QWord, flags As FormatFlags) As DWord657 Function IntegerU_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord 508 658 Dim x = xq As DWord 509 Dim i = MaxSize U659 Dim i = MaxSizeLO 510 660 While x <> 0 511 buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策661 buf[i] = (x As Int64 Mod 10 + &h30) As Char 'Int64への型変換は#117対策 512 662 x \= 10 513 663 i-- … … 522 672 @bug #117のため、現在Int64の最大値を超える値を正しく処理できない。 523 673 */ 524 Function IntegerLU_Convert(buf As * StrChar, x As QWord, flags As FormatFlags) As DWord525 Dim i = MaxSizeL U674 Function IntegerLU_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord 675 Dim i = MaxSizeLO 526 676 While x <> 0 527 buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策677 buf[i] = (x As Int64 Mod 10 + &h30) As Char 'Int64への型変換は#117対策 528 678 x \= 10 529 679 i-- … … 543 693 @date 2007/10/28 544 694 */ 545 Function IntegerD_Convert(buf As * StrChar, xq As QWord, flags As FormatFlags) As DWord695 Function IntegerD_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord 546 696 Return IntegerU_Convert(buf, Abs((xq As DWord) As Long) As DWord, flags) 547 697 End Function … … 552 702 @date 2007/10/28 553 703 */ 554 Function IntegerLD_Convert(buf As * StrChar, x As QWord, flags As FormatFlags) As DWord704 Function IntegerLD_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord 555 705 Return IntegerLU_Convert(buf, Abs(x As Int64) As QWord, flags) 556 706 End Function … … 570 720 End Function 571 721 572 /*! 573 @brief DWordの最大値の八進法表現37777777777の文字数 - 1 + 1。IntegerO_Convert内で使用。 574 @author Egtra 575 @date 2007/10/19 576 上の式で1を加えているのは、八進接頭辞の分。 577 */ 578 Const MaxSizeO = 11 722 579 723 580 724 /*! … … 594 738 .Convert = AddressOf(IntegerO_Convert) 595 739 .Prefix = AddressOf(IntegerO_Prefix) 596 .MaxSize = MaxSizeO597 740 End With 598 741 … … 600 743 .Convert = AddressOf(IntegerLO_Convert) 601 744 .Prefix = AddressOf(IntegerO_Prefix) 602 .MaxSize = MaxSizeLO603 745 End With 604 746 … … 630 772 @date 2007/10/22 631 773 */ 632 Function IntegerO_Convert(buf As * StrChar, xq As QWord, flags As FormatFlags) As DWord774 Function IntegerO_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord 633 775 Dim x = xq As DWord 634 Dim i = MaxSize O776 Dim i = MaxSizeLO 635 777 While x <> 0 636 buf[i] = ((x And &o7) + &h30) As StrChar778 buf[i] = ((x And &o7) + &h30) As Char 637 779 x >>= 3 638 780 i-- … … 650 792 @date 2007/10/26 651 793 */ 652 Function IntegerLO_Convert(buf As * StrChar, x As QWord, flags As FormatFlags) As DWord794 Function IntegerLO_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord 653 795 Dim i = MaxSizeLO 654 796 While x <> 0 655 buf[i] = ((x And &o7) + &h30) As StrChar797 buf[i] = ((x And &o7) + &h30) As Char 656 798 x >>= 3 657 799 i-- … … 678 820 679 821 /*! 680 @brief DWordの最大値の十六進法表現ffffffffの文字数 - 1。FormatIntegerO内で使用。681 @author Egtra682 @date 2007/10/24683 */684 Const MaxSizeX = 7685 686 /*!687 @brief QWordの最大値の十六進法表現ffffffffffffffffの文字数 - 1。FormatIntegerO内で使用。688 @author Egtra689 @date 2007/10/26690 */691 Const MaxSizeLX = 15692 693 /*!694 822 @author Egtra 695 823 @date 2007/10/24 … … 699 827 .Convert = AddressOf(IntegerX_Convert) 700 828 .Prefix = AddressOf(IntegerX_Prefix) 701 .MaxSize = MaxSizeX702 829 End With 703 830 … … 705 832 .Convert = AddressOf(IntegerLX_Convert) 706 833 .Prefix = AddressOf(IntegerX_Prefix) 707 .MaxSize = MaxSizeLX708 834 End With 709 835 … … 731 857 End Function 732 858 859 /*! 860 @brief FormatIntegerXのQWord, StringBuilder版。 861 @author Egtra 862 @date 2008/03/07 863 */ 864 Sub FormatIntegerLX(sb As System.Text.StringBuilder, x As QWord, d As DWord, field As DWord, flags As FormatFlags) 865 FormatIntegerEx(sb, TraitsIntegerX[1], x, d, field, flags) 866 End Sub 867 733 868 /* 734 869 @brief 0からFまでの文字を収めた表 … … 741 876 @date 2007/10/22 742 877 */ 743 Function IntegerX_Convert(buf As * StrChar, xq As QWord, flags As FormatFlags) As DWord744 Dim i = MaxSize X878 Function IntegerX_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord 879 Dim i = MaxSizeLO 745 880 Dim x = xq As DWord 746 881 While x <> 0 … … 757 892 @date 2007/10/22 758 893 */ 759 Function IntegerLX_Convert(buf As * StrChar, x As QWord, flags As FormatFlags) As DWord760 Dim i = MaxSizeL X894 Function IntegerLX_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord 895 Dim i = MaxSizeLO 761 896 While x <> 0 762 897 buf[i] = HexadecimalTable[x And &h0f] … … 791 926 Type IntegerConvertTraits 792 927 '!変換を行う関数へのポインタ。 793 Convert As *Function(buf As * StrChar, x As QWord, flags As FormatFlags) As DWord928 Convert As *Function(buf As *Char, x As QWord, flags As FormatFlags) As DWord 794 929 '!接頭辞を取得する関数へのポインタ。 795 930 Prefix As *Function(x As QWord, flags As FormatFlags) As String 796 '!必要なバッファの大きさ。797 MaxSize As DWord798 931 End Type 799 932 800 933 /*! 801 @brief 整数変換全てを行う関数。 これを雛形とし、形式毎の差異はIntegerConvertTraitsで表現する。934 @brief 整数変換全てを行う関数。 802 935 @author Egtra 803 936 @date 2007/10/22 … … 807 940 @param[in] field フィールド幅。 808 941 @param[in] flags フラグ。 942 @return 変換された文字列 809 943 */ 810 944 Function FormatIntegerEx(ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags) As String 945 Dim sb = New System.Text.StringBuilder(32) 946 FormatIntegerEx(sb, tr, x, d, field, flags) 947 FormatIntegerEx = sb.ToString 948 End Function 949 950 /*! 951 @brief 整数変換全てを行う関数。これを雛形とし、形式毎の差異はIntegerConvertTraitsで表現する。 952 @author Egtra 953 @date 2008/03/06 954 @param[in,out] sb 書式化した文字列を追加するバッファ。 955 @param[in] tr 特性情報。 956 @param[in] x 変換元の数値。 957 @param[in] d 精度。ここでは最低限出力する桁数。 958 @param[in] field フィールド幅。 959 @param[in] flags フラグ。 960 */ 961 Sub FormatIntegerEx(sb As System.Text.StringBuilder, ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags) 811 962 If d = DWORD_MAX Then 812 963 d = 1 … … 817 968 End If 818 969 819 Dim sb = New System.Text.StringBuilder 970 Dim lastLength = sb.Length 971 820 972 With sb 821 973 Dim prefixFunc = tr.Prefix … … 828 980 End If 829 981 830 ' Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar 831 Dim buf[MaxSizeLO] As StrChar982 'バッファの量は最も必要文字数の多くなるUInt64の8進法変換にあわせている 983 Dim buf[MaxSizeLO] As Char 832 984 Dim convertFunc = tr.Convert 833 985 Dim bufStartPos = convertFunc(buf, x, flags) 834 986 835 Dim len = ( tr.MaxSize- bufStartPos) As Long987 Dim len = (MaxSizeLO - bufStartPos) As Long 836 988 If len < 0 Then 837 989 Debug 838 990 End If 839 991 If len < d Then 840 .Append(&h30 As StrChar, d - len) 841 End If 842 992 .Append(&h30 As Char, d - len) 993 End If 843 994 .Append(buf, bufStartPos + 1, len) 844 845 Adjust FieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen)995 AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen, lastLength) 996 AdjustAlphabet(sb, flags, lastLength) 846 997 End With 847 FormatIntegerEx = sb.ToString() 848 849 If (flags And Cap) = 0 Then 850 FormatIntegerEx = FormatIntegerEx.ToLower() 851 End If 852 End Function 853 Sub FormatIntegerEx(sb As System.Text.StringBuilder, ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags) 854 855 If d = DWORD_MAX Then 856 d = 1 998 End Sub 999 1000 /*! 1001 @brief 浮動小数点数変換全てを行う関数。これを雛形とし、実際の変換関数は引数converterで与える。 1002 @author Egtra 1003 @date 2008/03/07 1004 @param[in,out] sb 書式化した文字列を追加するバッファ。 1005 @param[in] converter 変換関数。 1006 @param[in] x 変換元の数値。 1007 @param[in] d 精度。ここでは最低限出力する桁数。 1008 @param[in] field フィールド幅。 1009 @param[in] flags フラグ。 1010 */ 1011 Sub FormatFloatEx(sb As System.Text.StringBuilder, converter As FormatFloatProc, x As Double, precision As DWord, field As DWord, flags As FormatFlags) 1012 Dim lastLength = sb.Length 1013 If Math.IsNaN(x) Then 1014 sb.Append("NAN") 1015 AdjustAlphabet(sb, flags, lastLength) 1016 ElseIf Math.IsInf(x) Then 1017 AppendSign(sb, (GetQWord(VarPtr(x)) >> 63) As Boolean, flags) 1018 sb.Append("INFINITY") 1019 AdjustAlphabet(sb, flags, lastLength) 857 1020 Else 858 '精度が指定されているとき、ゼロフラグは無視される。 859 '仕様上、左揃えのときも無視されるが、それはAdjustFieldWidthが行ってくれる。 860 flags And= Not Zero 861 End If 862 863 Dim lastLength = sb.Length 864 865 With sb 866 Dim prefixFunc = tr.Prefix 867 Dim prefix = prefixFunc(x, flags) 868 sb.Append(prefix) 869 870 Dim prefixLen = 0 As DWord 871 If String.IsNullOrEmpty(prefix) = False Then 872 prefixLen = prefix.Length As DWord 873 End If 874 875 ' Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar 876 Dim buf[MaxSizeLO] As StrChar 877 Dim convertFunc = tr.Convert 878 Dim bufStartPos = convertFunc(buf, x, flags) 879 880 Dim len = (tr.MaxSize - bufStartPos) As Long 881 If len < 0 Then 882 Debug 883 End If 884 If len < d Then 885 .Append(&h30 As StrChar, d - len) 886 End If 887 888 .Append(buf, bufStartPos + 1, len) 889 890 AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen, lastLength) 891 End With 892 Dim t = sb.ToString() 893 1021 converter(sb, x, precision, field, flags) 1022 End If 1023 AdjustFieldWidth(sb, field, flags, 0, lastLength) 1024 End Sub 1025 1026 1027 /*! 1028 @brief 浮動小数点数変換全てを行う関数。 1029 @author Egtra 1030 @date 2008/03/08 1031 @param[in] converter 変換関数。 1032 @param[in] x 変換元の数値。 1033 @param[in] d 精度。ここでは最低限出力する桁数。 1034 @param[in] field フィールド幅。 1035 @param[in] flags フラグ。 1036 @return 変換された文字列。 1037 */ 1038 Function FormatFloatEx(converter As FormatFloatProc, x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String 1039 Dim sb = New System.Text.StringBuilder 1040 FormatFloatEx(sb, converter, x, precision, field, flags) 1041 FormatFloatEx = sb.ToString 1042 End Function 1043 1044 /*! 1045 @brief 書式化の仕上げとして、Capフラグが指定されていないときに小文字化する作業を行う。 1046 @author Egtra 1047 @date 2008/03/06 1048 @param[in,out] sb 書式化した文字列を格納しているバッファ。 1049 @param[in] flags フラグ。 1050 @param[in] offset 書式変換した部分の開始位置。 1051 */ 1052 Sub AdjustAlphabet(sb As System.Text.StringBuilder, flags As FormatFlags, offset As Long) 894 1053 If (flags And Cap) = 0 Then 895 1054 Dim len = sb.Length 896 1055 Dim i As Long 897 For i = lastLengthTo ELM(len)1056 For i = offset To ELM(len) 898 1057 sb[i] = CType.ToLower(sb[i]) 899 1058 Next 900 1059 End If 901 1060 End Sub 902 903 /*!904 @brief QWordの最大値18446744073709551615の文字数 - 1。FormatIntegerLU内で使用。905 @author Egtra906 @date 2007/09/18907 */908 Const MaxSizeLU = 19909 1061 910 1062 /*! … … 953 1105 */ 954 1106 Function FormatString(x As String, d As DWord, field As DWord, flags As FormatFlags) As String 1107 Imports System 955 1108 Dim sb = New System.Text.StringBuilder( 956 x, 0, System.Math.Min(x.Length As DWord, d) As Long, field) 1109 Math.Max(Math.Min(x.Length As DWord, d), field) As Long + 1) 1110 FormatString(sb, x, d, field, flags) 957 1111 AdjustFieldWidth(sb, field, flags And LeftSide) 958 1112 FormatString = sb.ToString() 959 1113 End Function 1114 1115 /*! 1116 @brief 文字列をprintfの%s相当の変換で書式化する関数。 1117 @author Egtra 1118 @date 2008/03/07 1119 @param[in,out] sb 書式化した文字列を追加するバッファ。 1120 @param[in] x 文字列。 1121 @param[in] d 精度、最大の文字数。 1122 @param[in] field フィールド幅。 1123 @param[in] flags 書式フラグ。 1124 @return 書式化された文字列。 1125 */ 1126 Sub FormatString(sb As System.Text.StringBuilder, x As String, d As DWord, field As DWord, flags As FormatFlags) 1127 Dim len = sb.Length 1128 sb.Append(x, 0, System.Math.Min(x.Length As DWord, d) As Long) 1129 AdjustFieldWidth(sb, field, flags And LeftSide, 0, len) 1130 End Sub 960 1131 961 1132 /*! … … 969 1140 @return 書式化された文字列。 970 1141 */ 971 Function FormatCharacter(x As StrChar, d As DWord, field As DWord, flags As FormatFlags) As String 972 Dim sb = New System.Text.StringBuilder(field + 1) 1142 Function FormatCharacter(x As Char, d As DWord, field As DWord, flags As FormatFlags) As String 1143 Dim sb = New System.Text.StringBuilder(field + 2) 1144 FormatCharacter(sb, x, d, field, flags) 1145 FormatCharacter = sb.ToString() 1146 End Function 1147 1148 /*! 1149 @brief 文字列をprintfの%s相当の変換で書式化する関数。 1150 @author Egtra 1151 @date 2008/03/07 1152 @param[in,out] sb 書式化した文字列を追加するバッファ。 1153 @param[in] x 文字。 1154 @param[in] d 精度、最大の文字数。 1155 @param[in] field フィールド幅。 1156 @param[in] flags 書式フラグ。 1157 @return 書式化された文字列。 1158 */ 1159 Sub FormatCharacter(sb As System.Text.StringBuilder, x As Char, d As DWord, field As DWord, flags As FormatFlags) 1160 Dim len = sb.Length 973 1161 sb.Append(x) 974 AdjustFieldWidth(sb, field, flags And LeftSide) 975 FormatCharacter = sb.ToString() 976 End Function 1162 AdjustFieldWidth(sb, field, flags And LeftSide, 0, len) 1163 End Sub 977 1164 978 1165 /*! … … 980 1167 @date 2007/10/28 981 1168 */ 982 TypeDef FormatFloatProc = * Function(x As Double, precision As DWord, fieldWidth As DWord, flags As FormatFlags) As String1169 TypeDef FormatFloatProc = *Sub(sb As System.Text.StringBuilder, x As Double, precision As DWord, fieldWidth As DWord, ByRef flags As FormatFlags) 983 1170 984 1171 /*! … … 997 1184 x = param As System.Single 998 1185 End If 999 s.Append(formatProc(x, precision, field, flags))1186 FormatFloatEx(s, formatProc, x, precision, field, flags) 1000 1187 End Sub 1001 1188 … … 1050 1237 End If 1051 1238 End If 1052 1053 ' s.Append(FormatIntegerEx(ByVal traits, x, precision, field, flags))1054 1239 FormatIntegerEx(s, ByVal traits, x, precision, field, flags) 1055 1240 End Sub … … 1066 1251 @return 変換して得られた数値。変換できなければ0。 1067 1252 */ 1068 Function StrToLong(s As * StrChar, ByRef p As *StrChar) As Long1253 Function StrToLong(s As *Char, ByRef p As *Char) As Long 1069 1254 Dim negative As Boolean 1070 1255 Dim i = 0 As Long … … 1099 1284 そうでなく、fmtに数字(先頭に-符号があっても可)が並んでいれば、それを読み取る。 1100 1285 */ 1101 Function ReadInt(ByRef fmt As * StrChar, params As *Object, ByRef paramsCount As SIZE_T, ByRef ret As Long) As Boolean1286 Function ReadInt(ByRef fmt As *Char, params As *Object, ByRef paramsCount As SIZE_T, ByRef ret As Long) As Boolean 1102 1287 If fmt[0] = &h2a Then '* 1103 1288 fmt = VarPtr(fmt[1]) 'po … … 1106 1291 ReadInt = True 1107 1292 Else 1108 Dim p As * StrChar1293 Dim p As *Char 1109 1294 ret = StrToLong(fmt, p) 1110 1295 If fmt <> p Then … … 1126 1311 @retval False 読み取り中に文字列が終了した(ヌル文字が現れた)。 1127 1312 */ 1128 Function ReadFlags(ByRef fmt As * StrChar, ByRef flags As FormatFlags) As Boolean1313 Function ReadFlags(ByRef fmt As *Char, ByRef flags As FormatFlags) As Boolean 1129 1314 ReadFlags = False 1130 1315 Do … … 1162 1347 @param[in, out] flags 1163 1348 */ 1164 Sub ReadFieldWidth(ByRef fmt As * StrChar, params As *Object, ByRef paramsCount As SIZE_T,1349 Sub ReadFieldWidth(ByRef fmt As *Char, params As *Object, ByRef paramsCount As SIZE_T, 1165 1350 ByRef fieldWidth As DWord, ByRef flags As FormatFlags) 1166 1351 Dim t As Long … … 1186 1371 @return 読み取った精度。指定がなかったときには、DWORD_MAX。 1187 1372 */ 1188 Function ReadPrecision(ByRef fmt As * StrChar,1373 Function ReadPrecision(ByRef fmt As *Char, 1189 1374 params As *Object, ByRef paramsCount As SIZE_T) As DWord 1190 1375 … … 1216 1401 @param[out] lengthSpec 1217 1402 */ 1218 Sub ReadLength(ByRef fmt As * StrChar, ByRef lengthSpec As Long)1403 Sub ReadLength(ByRef fmt As *Char, ByRef lengthSpec As Long) 1219 1404 Do 1220 1405 Select Case fmt[0] … … 1240 1425 1241 1426 /*! 1427 @brief efg変換用に、精度が指定されていないときに既定の精度を設定する。 1428 @auther Egtra 1429 @date 2008/03/07 1430 */ 1431 Sub AdjustPrecision(ByRef precision As DWord) 1432 If precision = DWORD_MAX Then 1433 precision = 6 1434 End If 1435 End Sub 1436 1437 /*! 1242 1438 @biref Cのsprintfのような書式文字列出力関数 1243 1439 @author Egtra … … 1255 1451 Dim s = New System.Text.StringBuilder 1256 1452 Do 1257 Dim last = format.Length - (((fmt - StrPtr(format)) \ SizeOf ( StrChar)) As LONG_PTR) As Long 'po1258 Dim pos = ActiveBasic.Strings.ChrFind(fmt, last, &h25 As StrChar) As Long '&h25 = %1453 Dim last = format.Length - (((fmt - StrPtr(format)) \ SizeOf (Char)) As LONG_PTR) As Long 'po 1454 Dim pos = ChrFind(fmt, last, &h25 As Char) As Long '&h25 = % 1259 1455 If pos = -1 Then 1260 1456 s.Append(fmt, 0, last) … … 1285 1481 Case &h75 'u 1286 1482 FormatInteger(s, TraitsIntegerU, params[i], False, typeWidth, precision, fieldWidth, flags) 1483 Case &h4f 'O 1484 flags Or= Cap 1485 Goto *O 1287 1486 Case &h6f 'o 1487 *O 1288 1488 FormatInteger(s, TraitsIntegerO, params[i], False, typeWidth, precision, fieldWidth, flags) 1289 Case &h4f 'O 1290 FormatInteger(s, TraitsIntegerO, params[i], False, typeWidth, precision, fieldWidth, flags Or Cap) 1489 Case &h58 'X 1490 flags Or= Cap 1491 Goto *X 1291 1492 Case &h78 'x 1493 *X 1292 1494 FormatInteger(s, TraitsIntegerX, params[i], False, typeWidth, precision, fieldWidth, flags) 1293 Case &h58 'X1294 FormatInteger(s, TraitsIntegerX, params[i], False, typeWidth, precision, fieldWidth, flags Or Cap)1295 1495 '現状ではVoidPtrを引数にする手段は無いはず 1296 1496 ' Case &h58 'p 1297 1497 ' FormatInteger(s, TraitsIntegerX, params[i], False, typeWidth, precision, fieldWidth, flags Or Cap) 1498 Case &h45 'E 1499 flags Or= Cap 1500 Goto *E 1298 1501 Case &h65 'e 1299 FormatFloat(s, AddressOf(FormatFloatE), params[i], precision, fieldWidth, flags) 1300 Case &h45 'E 1301 FormatFloat(s, AddressOf(FormatFloatE), params[i], precision, fieldWidth, flags Or Cap) 1502 *E 1503 AdjustPrecision(precision) 1504 FormatFloat(s, AddressOf(FormatFloatE_Convert), params[i], precision, fieldWidth, flags) 1505 Case &h46 'F 1506 flags Or= Cap 1507 Goto *F 1302 1508 Case &h66 'f 1303 FormatFloat(s, AddressOf(FormatFloatF), params[i], precision, fieldWidth, flags) 1304 Case &h46 'F 1305 FormatFloat(s, AddressOf(FormatFloatF), params[i], precision, fieldWidth, flags Or Cap) 1509 *F 1510 AdjustPrecision(precision) 1511 FormatFloat(s, AddressOf(FormatFloatF_Convert), params[i], precision, fieldWidth, flags) 1512 Case &h47 'G 1513 flags Or= Cap 1514 Goto *G 1306 1515 Case &h67 'g 1307 FormatFloat(s, AddressOf(FormatFloatG), params[i], precision, fieldWidth, flags) 1308 Case &h47 'G 1309 FormatFloat(s, AddressOf(FormatFloatG), params[i], precision, fieldWidth, flags Or Cap) 1516 *G 1517 AdjustPrecision(precision) 1518 FormatFloat(s, AddressOf(FormatFloatG_Convert), params[i], precision, fieldWidth, flags) 1519 Case &h41 'A 1520 flags Or= Cap 1521 Goto *A 1310 1522 Case &h61 'a 1523 *A 1311 1524 FormatFloat(s, AddressOf(FormatFloatA), params[i], precision, fieldWidth, flags) 1312 Case &h41 'A1313 FormatFloat(s, AddressOf(FormatFloatA), params[i], precision, fieldWidth, flags Or Cap)1314 1525 Case &h73 's 1315 s.Append(FormatString(params[i] As String, precision, fieldWidth, flags))1526 FormatString(s, params[i] As String, precision, fieldWidth, flags) 1316 1527 Case &h63 'c 1317 s.Append(FormatCharacter(params[i] As BoxedStrChar, precision, fieldWidth, flags))1528 FormatCharacter(s, params[i] As BoxedStrChar, precision, fieldWidth, flags) 1318 1529 ' Case &h6e 'n 1319 1530 Case &h25 '% 1320 s.Append(&h25 As StrChar)1531 s.Append(&h25 As Char) 1321 1532 i-- 1322 1533 Case 0 -
trunk/Include/Classes/System/IO/DirectoryInfo.ab
r409 r468 59 59 Select Case error 60 60 Case ERROR_ALREADY_EXISTS 61 Throw New IOException("DirectoryInfo.CreateDirectory: The directory has already existed.")61 Exit Sub 'ディレクトリが既に存在するときは、何もしない。 62 62 Case Else 63 63 Throw New IOException("DirectoryInfo.CreateDirectory: Failed to CreateDirectory") -
trunk/Include/Classes/System/IO/Path.ab
r429 r468 88 88 */ 89 89 Static Function GetFullPath(path As String) As String 90 Return Combine(System.Environment.CurrentDirectory, path) 90 If IsPathRooted(path) Then 91 Return path 92 Else 93 Return Combine(System.Environment.CurrentDirectory, path) 94 End If 91 95 End Function 92 96 … … 172 176 Static Function GetTempPath() As String 173 177 Dim size = WIN32API_GetTempPath(0, 0) 174 Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PCTSTR 175 Dim len = WIN32API_GetTempPath(size, p) 178 Dim buf = New Text.StringBuilder(size) 179 buf.Length = size 180 Dim len = WIN32API_GetTempPath(size, StrPtr(buf)) 176 181 If (len > size) or len = 0 Then 177 182 Throw New IOException("Path.GetTempPath: Failed to GetTempPath.") 178 183 Else 179 Return New String(p, len As Long) 184 buf.Length = len 185 Return buf.ToString 180 186 End If 181 187 End Function … … 209 215 Static Const ExtensionSeparatorChar = &H2E As StrChar 210 216 Static Const InvalidPathChars = Ex"\q<>|\0\t" As String 211 Static Const UniformNamingConventionString = Ex"\\\\" As String217 Static Const UniformNamingConventionString = "\\" As String 212 218 213 219 '---------------------------------------------------------------- … … 227 233 Dim i As Long 228 234 For i = 0 To ELM(InvalidPathChars.Length) 229 If path.Contains(InvalidPathChars .Substring(i, 1)) Then235 If path.Contains(InvalidPathChars[i]) Then 230 236 Throw New IOException("Path.CheckPath: The path contains invalidPathChars.") 231 237 End If -
trunk/Include/Classes/System/IO/Stream.ab
r432 r468 7 7 8 8 Public 'Protected 9 Sub Stream(): End Sub 9 Sub Stream() 10 End Sub 10 11 Public 11 12 Virtual Sub ~Stream() … … 54 55 Dispose(True) 55 56 End Sub 56 Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long: End Function 57 Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult): End Sub 57 Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long 58 End Function 59 Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult) 60 End Sub 58 61 Abstract Sub Flush() 59 62 Abstract Function Read(buffer As *Byte, offset As Long, count As Long) As Long … … 72 75 Abstract Sub SetLength(value As Int64) 73 76 Abstract Sub Write(buffer As *Byte, offset As Long, count As Long) 74 75 77 Virtual Sub WriteByte(b As Byte) 76 78 Write(VarPtr(b), 0, 1) -
trunk/Include/Classes/System/IO/StreamWriter.ab
r271 r468 4 4 5 5 Class StreamWriter 6 ' TODO: 実装 6 Inherits TextWriter 7 Public 8 /* 9 @date 2008/02/25 10 @auther Egtra 11 */ 12 Sub StreamWriter(path As String) 13 init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) 14 End Sub 15 16 /* 17 @date 2008/02/25 18 @auther Egtra 19 */ 20 Sub StreamWriter(stream As Stream) 21 init(stream) 22 End Sub 23 24 Override Sub Write(str As String) 25 buf.Append(str) 26 Dim len = buf.Length 27 If len >= 2048 Then 28 s.Write(StrPtr(buf) As *Byte, 0, len) 29 buf.Length = 0 30 End If 31 End Sub 32 33 Override Sub Write(x As Boolean) 34 buf.Append(x) 35 End Sub 36 37 Override Sub Write(x As Char) 38 buf.Append(x) 39 End Sub 40 41 Override Sub Write(x As Byte) 42 buf.Append(x) 43 End Sub 44 #ifdef UNICODE 45 Override Sub Write(x As SByte) 46 buf.Append(x) 47 End Sub 48 #else 49 Override Sub Write(x As Word) 50 buf.Append(x) 51 End Sub 52 #endif 53 Override Sub Write(x As Integer) 54 buf.Append(x) 55 End Sub 56 57 Override Sub Write(x As DWord) 58 buf.Append(x) 59 End Sub 60 61 Override Sub Write(x As Long) 62 buf.Append(x) 63 End Sub 64 65 Override Sub Write(x As QWord) 66 buf.Append(x) 67 End Sub 68 69 Override Sub Write(x As Int64) 70 buf.Append(x) 71 End Sub 72 73 Override Sub Write(x As Single) 74 buf.Append(x) 75 End Sub 76 77 Override Sub Write(x As Double) 78 buf.Append(x) 79 End Sub 80 81 Override Sub Write(x As Object) 82 Write(x.ToString) 83 End Sub 84 85 Protected 86 Override Sub Dispose(disposing As Boolean) 87 If disposing Then 88 s.Dispose() 89 End If 90 End Sub 91 92 Private 93 Sub init(stream As Stream) 94 s = stream 95 buf = New System.Text.StringBuilder(4096) 96 End Sub 97 98 buf As Text.StringBuilder 99 s As System.IO.Stream 7 100 End Class 8 101 -
trunk/Include/Classes/System/IO/TextReader.ab
r457 r468 101 101 102 102 Protected 103 Abstract Sub Dispose(disposing As Boolean) 103 Virtual Sub Dispose(disposing As Boolean) 104 End Sub 104 105 105 106 /* -
trunk/Include/Classes/System/String.ab
r457 r468 5 5 #require <Classes/ActiveBasic/Strings/Strings.ab> 6 6 7 #ifdef __STRING_IS_NOT_ALWAYS_UNICODE8 9 #ifndef UNICODE10 7 TypeDef StrChar = Char 11 #define __STRING_IS_NOT_UNICODE12 #endif13 14 #endif15 16 #ifndef __STRING_IS_NOT_UNICODE17 TypeDef StrChar = WCHAR18 8 19 9 #ifdef UNICODE 20 10 #define __STRING_IS_UNICODE 21 11 #else 22 #define __STRING_ UNICODE_WINDOWS_ANSI12 #define __STRING_IS_NOT_UNICODE 23 13 #endif 24 #endif25 14 26 15 Namespace System 27 16 28 17 Class String 29 Implements /*IComparable, ICloneable, IConvertible, IComparable<String>, IEnumerable, IEnumerable< StrChar>, IEquatable<String>*/18 Implements /*IComparable, ICloneable, IConvertible, IComparable<String>, IEnumerable, IEnumerable<Char>, IEquatable<String>*/ 30 19 31 20 m_Length As Long 32 Chars As * StrChar21 Chars As *Char 33 22 34 23 Sub validPointerCheck(p As VoidPtr, size = 1 As Long) … … 89 78 End Sub 90 79 91 Sub String(initChar As StrChar, length As Long)80 Sub String(initChar As Char, length As Long) 92 81 AllocStringBuffer(length) 93 82 ActiveBasic.Strings.ChrFill(Chars, length, initChar) … … 105 94 End Function 106 95 107 Function Operator() As * StrChar96 Function Operator() As *Char 108 97 Return Chars 109 98 End Function 110 99 111 Const Function Operator [] (n As Long) As StrChar100 Const Function Operator [] (n As Long) As Char 112 101 rangeCheck(n) 113 102 Return Chars[n] … … 154 143 End Function 155 144 156 Const Function Operator == (y As * StrChar) As Boolean145 Const Function Operator == (y As *Char) As Boolean 157 146 Return Compare(This, y) = 0 158 147 End Function … … 162 151 End Function 163 152 164 Const Function Operator <> (y As * StrChar) As Boolean153 Const Function Operator <> (y As *Char) As Boolean 165 154 Return Compare(This, y) <> 0 166 155 End Function … … 170 159 End Function 171 160 172 Const Function Operator < (y As * StrChar) As Boolean161 Const Function Operator < (y As *Char) As Boolean 173 162 Return Compare(This, y) < 0 174 163 End Function … … 178 167 End Function 179 168 180 Const Function Operator > (y As * StrChar) As Boolean169 Const Function Operator > (y As *Char) As Boolean 181 170 Return Compare(This, y) > 0 182 171 End Function … … 186 175 End Function 187 176 188 Const Function Operator <= (y As * StrChar) As Boolean177 Const Function Operator <= (y As *Char) As Boolean 189 178 Return Compare(This, y) <= 0 190 179 End Function … … 194 183 End Function 195 184 196 Const Function Operator >= (y As * StrChar) As Boolean185 Const Function Operator >= (y As *Char) As Boolean 197 186 Return Compare(This, y) >= 0 198 187 End Function … … 217 206 End Function 218 207 Private 219 Static Function Compare(x As String, y As * StrChar) As Long208 Static Function Compare(x As String, y As *Char) As Long 220 209 Return CompareOrdinal(x, y) 221 210 End Function 222 211 223 Static Function CompareOrdinal(x As String, y As * StrChar) As Long212 Static Function CompareOrdinal(x As String, y As *Char) As Long 224 213 Return CompareOrdinal(StrPtr(x), y) 225 214 End Function 226 215 227 Static Function CompareOrdinal(x As * StrChar, y As *StrChar) As Long216 Static Function CompareOrdinal(x As *Char, y As *Char) As Long 228 217 If x = 0 Then 229 218 If y = 0 Then … … 238 227 End Function 239 228 240 Static Function CompareOrdinal(x As * StrChar, indexX As Long, y As *StrChar, indexY As Long, length As Long) As Long229 Static Function CompareOrdinal(x As *Char, indexX As Long, y As *Char, indexY As Long, length As Long) As Long 241 230 If x = 0 Then 242 231 If y = 0 Then … … 273 262 End Function 274 263 275 Const Function StrPtr() As * StrChar264 Const Function StrPtr() As *Char 276 265 Return Chars 277 266 End Function … … 280 269 Sub Assign(text As PCSTR, textLengthA As Long) 281 270 #ifdef __STRING_IS_NOT_UNICODE 282 AssignFrom StrChar(text, textLengthA)271 AssignFromCharPtr(text, textLengthA) 283 272 #else 284 273 Dim textLengthW = MultiByteToWideChar(CP_THREAD_ACP, 0, text, textLengthA, 0, 0) … … 298 287 End If 299 288 #else 300 AssignFrom StrChar(text, textLengthW)289 AssignFromCharPtr(text, textLengthW) 301 290 #endif 302 291 End Sub 303 292 304 293 Private 305 Static Function Concat StrChar(text1 As *StrChar, text1Length As Long, text2 As *StrChar, text2Length As Long) As String306 Concat StrChar = New String()307 With Concat StrChar294 Static Function ConcatChar(text1 As *Char, text1Length As Long, text2 As *Char, text2Length As Long) As String 295 ConcatChar = New String() 296 With ConcatChar 308 297 .AllocStringBuffer(text1Length + text2Length) 309 298 ActiveBasic.Strings.ChrCopy(.Chars, text1, text1Length As SIZE_T) … … 315 304 Const Function Concat(text As PCSTR, len As Long) As String 316 305 #ifdef __STRING_IS_NOT_UNICODE 317 Return Concat StrChar(This.Chars, m_Length, text, len)306 Return ConcatChar(This.Chars, m_Length, text, len) 318 307 #else 319 308 With Concat … … 339 328 End With 340 329 #else 341 Return Concat StrChar(This.Chars, m_Length, text, len)330 Return ConcatChar(This.Chars, m_Length, text, len) 342 331 #endif 343 332 End Function … … 375 364 End Function 376 365 377 Const Function Contains(c As StrChar) As Boolean366 Const Function Contains(c As Char) As Boolean 378 367 Return IndexOf(c) >= 0 379 368 End Function … … 389 378 End Function 390 379 391 Const Function IndexOf(c As StrChar) As Long380 Const Function IndexOf(c As Char) As Long 392 381 Return indexOfCore(c, 0, m_Length) 393 382 End Function 394 383 395 Const Function IndexOf(c As StrChar, start As Long) As Long384 Const Function IndexOf(c As Char, start As Long) As Long 396 385 rangeCheck(start) 397 386 Return indexOfCore(c, start, m_Length - start) 398 387 End Function 399 388 400 Const Function IndexOf(c As StrChar, start As Long, count As Long) As Long389 Const Function IndexOf(c As Char, start As Long, count As Long) As Long 401 390 rangeCheck(start, count) 402 391 Return indexOfCore(c, start, count) 403 392 End Function 404 393 Private 405 Const Function indexOfCore(c As StrChar, start As Long, count As Long) As Long394 Const Function indexOfCore(c As Char, start As Long, count As Long) As Long 406 395 indexOfCore = ActiveBasic.Strings.ChrFind(VarPtr(Chars[start]), count, c) As Long 407 396 If indexOfCore <> -1 Then … … 440 429 End Function 441 430 442 Const Function LastIndexOf(c As StrChar) As Long431 Const Function LastIndexOf(c As Char) As Long 443 432 Return lastIndexOf(c, m_Length - 1, m_Length) 444 433 End Function 445 434 446 Const Function LastIndexOf(c As StrChar, start As Long) As Long435 Const Function LastIndexOf(c As Char, start As Long) As Long 447 436 rangeCheck(start) 448 437 Return lastIndexOf(c, start, start + 1) 449 438 End Function 450 439 451 Const Function LastIndexOf(c As StrChar, start As Long, count As Long) As Long440 Const Function LastIndexOf(c As Char, start As Long, count As Long) As Long 452 441 rangeCheck(start) 453 442 Dim lastFindPos = start - (count - 1) … … 458 447 End Function 459 448 Private 460 Const Function lastIndexOf(c As StrChar, start As Long, count As Long) As Long449 Const Function lastIndexOf(c As Char, start As Long, count As Long) As Long 461 450 Dim lastFindPos = start - (count - 1) 462 451 Dim i As Long … … 504 493 End Function 505 494 506 Const Function StartsWith(c As StrChar) As Boolean495 Const Function StartsWith(c As Char) As Boolean 507 496 Return IndexOf(c) = 0 508 497 End Function … … 512 501 End Function 513 502 514 Const Function EndsWith(c As StrChar) As Boolean503 Const Function EndsWith(c As Char) As Boolean 515 504 Return LastIndexOf(c) = m_Length - 1 516 505 End Function … … 556 545 End Function 557 546 558 Const Function Replace(oldChar As StrChar, newChar As StrChar) As String547 Const Function Replace(oldChar As Char, newChar As Char) As String 559 548 Dim sb = New Text.StringBuilder(This) 560 549 sb.Replace(oldChar, newChar) … … 604 593 End Function 605 594 606 Sub CopyTo(sourceIndex As Long, destination As * StrChar, destinationIndex As Long, count As Long)595 Sub CopyTo(sourceIndex As Long, destination As *Char, destinationIndex As Long, count As Long) 607 596 ActiveBasic.Strings.ChrCopy(VarPtr(destination[destinationIndex]), VarPtr(Chars[sourceIndex]), count As SIZE_T) 608 597 End Sub … … 618 607 619 608 Function PadLeft(total As Long) As String 620 PadLeft(total, &h30 As StrChar)621 End Function 622 623 Function PadLeft(total As Long, c As StrChar) As String609 PadLeft(total, &h30 As Char) 610 End Function 611 612 Function PadLeft(total As Long, c As Char) As String 624 613 If total < 0 Then 625 614 Throw New ArgumentOutOfRangeException("String.PadLeft: An arguments is out of range value.", "total") … … 635 624 636 625 Function PadRight(total As Long) As String 637 PadRight(total, &h30 As StrChar)638 End Function 639 640 Function PadRight(total As Long, c As StrChar) As String626 PadRight(total, &h30 As Char) 627 End Function 628 629 Function PadRight(total As Long, c As Char) As String 641 630 If total < 0 Then 642 631 Throw New ArgumentOutOfRangeException("String.PadRight: An arguments is out of range value.", "total") … … 651 640 End Function 652 641 Private 653 Function AllocStringBuffer(textLength As Long) As * StrChar642 Function AllocStringBuffer(textLength As Long) As *Char 654 643 If textLength < 0 Then 655 644 Return 0 656 645 End If 657 AllocStringBuffer = GC_malloc_atomic(SizeOf( StrChar) * (textLength + 1))646 AllocStringBuffer = GC_malloc_atomic(SizeOf(Char) * (textLength + 1)) 658 647 If AllocStringBuffer = 0 Then 659 648 'Throw New OutOfMemoryException … … 663 652 End Function 664 653 665 Sub AssignFrom StrChar(text As *StrChar, textLength As Long)654 Sub AssignFromCharPtr(text As *Char, textLength As Long) 666 655 AllocStringBuffer(textLength) 667 656 ActiveBasic.Strings.ChrCopy(Chars, text, textLength As SIZE_T) -
trunk/Include/Classes/System/Text/StringBuilder.ab
r457 r468 40 40 End Function 41 41 42 Function Append(x As StrChar) As StringBuilder42 Function Append(x As Char) As StringBuilder 43 43 EnsureCapacity(size + 1) 44 44 separateBuffer() … … 47 47 Return This 48 48 End Function 49 50 #ifdef __STRING_IS_NOT_UNICODE 49 #ifdef UNICODE 50 Function Append(x As SByte) As StringBuilder 51 ActiveBasic.Strings.Detail.FormatIntegerD(This, x, DWORD_MAX, 0, 0) 52 Return This 53 End Function 54 #endif 55 Function Append(x As Byte) As StringBuilder 56 ActiveBasic.Strings.Detail.FormatIntegerU(This, x, DWORD_MAX, 0, 0) 57 Return This 58 End Function 59 60 Function Append(x As Integer) As StringBuilder 61 ActiveBasic.Strings.Detail.FormatIntegerD(This, x, DWORD_MAX, 0, 0) 62 Return This 63 End Function 64 #ifndef UNICODE 51 65 Function Append(x As Word) As StringBuilder 52 Append(Str$(x As DWord)) 53 Return This 54 End Function 55 #else 56 Function Append(x As SByte) As StringBuilder 57 Append(Str$(x As Long)) 66 ActiveBasic.Strings.Detail.FormatIntegerU(This, x, DWORD_MAX, 0, 0) 58 67 Return This 59 68 End Function 60 69 #endif 61 62 Function Append(x As Byte) As StringBuilder63 Append(Str$(x As DWord))64 Return This65 End Function66 67 Function Append(x As Integer) As StringBuilder68 Append(Str$(x As Long))69 Return This70 End Function71 72 70 Function Append(x As Long) As StringBuilder 73 A ppend(Str$(x))71 ActiveBasic.Strings.Detail.FormatIntegerD(This, x, DWORD_MAX, 0, 0) 74 72 Return This 75 73 End Function 76 74 77 75 Function Append(x As DWord) As StringBuilder 78 A ppend(Str$(x))76 ActiveBasic.Strings.Detail.FormatIntegerU(This, x, DWORD_MAX, 0, 0) 79 77 Return This 80 78 End Function 81 79 82 80 Function Append(x As Int64) As StringBuilder 83 A ppend(Str$(x))81 ActiveBasic.Strings.Detail.FormatIntegerLD(This, x, DWORD_MAX, 0, 0) 84 82 Return This 85 83 End Function 86 84 87 85 Function Append(x As QWord) As StringBuilder 88 A ppend(Str$(x))86 ActiveBasic.Strings.Detail.FormatIntegerLU(This, x, DWORD_MAX, 0, 0) 89 87 Return This 90 88 End Function 91 89 92 90 Function Append(x As Single) As StringBuilder 93 A ppend(Str$(x))91 ActiveBasic.Strings.Detail.FormatFloatG(This, x, DWORD_MAX, 0, 0) 94 92 Return This 95 93 End Function 96 94 97 95 Function Append(x As Double) As StringBuilder 98 A ppend(Str$(x))96 ActiveBasic.Strings.Detail.FormatFloatG(This, x, DWORD_MAX, 0, 0) 99 97 Return This 100 98 End Function … … 105 103 End Function 106 104 107 Function Append(c As StrChar, n As Long) As StringBuilder105 Function Append(c As Char, n As Long) As StringBuilder 108 106 EnsureCapacity(size + n) 109 107 ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), n As SIZE_T, c) … … 123 121 End Function 124 122 125 Function Append(s As * StrChar, startIndex As Long, count As Long) As StringBuilder123 Function Append(s As *Char, startIndex As Long, count As Long) As StringBuilder 126 124 If s = 0 Then 127 125 If startIndex = 0 And count = 0 Then … … 137 135 End Function 138 136 Private 139 Sub appendCore(s As * StrChar, start As Long, count As Long)137 Sub appendCore(s As *Char, start As Long, count As Long) 140 138 EnsureCapacity(size + count) 141 139 separateBuffer() … … 167 165 End Function 168 166 169 Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long)167 Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As Char, destIndex As Long, count As Long) 170 168 If dest = 0 Then 171 169 Throw New ArgumentNullException("StringBuilder.CopyTo: An argument is null", "sourceIndex") … … 174 172 End If 175 173 176 memcpy(VarPtr(dest[destIndex]), VarPtr(chars[sourceIndex]), count * SizeOf ( StrChar))174 memcpy(VarPtr(dest[destIndex]), VarPtr(chars[sourceIndex]), count * SizeOf (Char)) 177 175 End Sub 178 176 … … 181 179 Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument is out of range value.", "c") 182 180 ElseIf c > Capacity Then 183 Dim p = GC_malloc_atomic((c + 1) * SizeOf ( StrChar)) As *StrChar181 Dim p = GC_malloc_atomic((c + 1) * SizeOf (Char)) As *Char 184 182 ActiveBasic.Strings.ChrCopy(p, chars, size As SIZE_T) 185 183 chars = p … … 212 210 End Function 213 211 214 Function Insert(i As Long, x As StrChar) As StringBuilder212 Function Insert(i As Long, x As Char) As StringBuilder 215 213 Insert(i, VarPtr(x), 0, 1) 216 214 Return This … … 303 301 End Function 304 302 305 Function Insert(i As Long, x As * StrChar, index As Long, count As Long) As StringBuilder303 Function Insert(i As Long, x As *Char, index As Long, count As Long) As StringBuilder 306 304 rangeCheck(i) 307 305 If x = 0 Then … … 342 340 End Function 343 341 344 Function Replace(oldChar As StrChar, newChar As StrChar) As StringBuilder342 Function Replace(oldChar As Char, newChar As Char) As StringBuilder 345 343 replaceCore(oldChar, newChar, 0, size) 346 344 Return This … … 352 350 End Function 353 351 354 Function Replace(oldChar As StrChar, newChar As StrChar, startIndex As Long, count As Long) As StringBuilder352 Function Replace(oldChar As Char, newChar As Char, startIndex As Long, count As Long) As StringBuilder 355 353 rangeCheck(startIndex, count) 356 354 replaceCore(oldChar, newChar, startIndex, count) … … 364 362 End Function 365 363 Private 366 Sub replaceCore(oldChar As StrChar, newChar As StrChar, start As Long, count As Long)364 Sub replaceCore(oldChar As Char, newChar As Char, start As Long, count As Long) 367 365 separateBuffer() 368 366 Dim i As Long … … 386 384 Dim last = start + count 387 385 Do 388 Dim nextPos = ActiveBasic.Strings.ChrFind(VarPtr(chars[curPos]) As * StrChar, size As SIZE_T, StrPtr(oldStr), oldStr.Length As SIZE_T) As Long386 Dim nextPos = ActiveBasic.Strings.ChrFind(VarPtr(chars[curPos]) As *Char, size As SIZE_T, StrPtr(oldStr), oldStr.Length As SIZE_T) As Long 389 387 If nextPos = -1 As SIZE_T Or curPos > last Then 390 388 s.appendCore(chars, curPos, size - curPos) … … 411 409 End Function 412 410 413 Const Function Operator [](i As Long) As StrChar411 Const Function Operator [](i As Long) As Char 414 412 Return Chars[i] 415 413 End Function 416 414 417 Sub Operator []=(i As Long, c As StrChar)415 Sub Operator []=(i As Long, c As Char) 418 416 Chars[i] = c 419 417 End Sub … … 431 429 End Sub 432 430 433 Const Function Chars(i As Long) As StrChar431 Const Function Chars(i As Long) As Char 434 432 If i >= Length Or i < 0 Then 435 433 Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' is out of range value.") … … 438 436 End Function 439 437 440 Sub Chars(i As Long, c As StrChar)438 Sub Chars(i As Long, c As Char) 441 439 If i >= Length Or i < 0 Then 442 440 Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument is out of range value.", "i") … … 452 450 EnsureCapacity(i) 'iが適切な値かどうかの確認はこの中で行う 453 451 If size < i Then 454 ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), (i - size + 1) As SIZE_T, 0 As StrChar)452 ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), (i - size + 1) As SIZE_T, 0 As Char) 455 453 End If 456 454 size = i … … 461 459 End Function 462 460 463 Function __Chars() As * StrChar461 Function __Chars() As *Char 464 462 Return chars 465 463 End Function … … 483 481 This.maxCapacity = maxCapacity 484 482 This.size = 0 485 This.chars = GC_malloc_atomic((This.capacity + 1) * SizeOf ( StrChar))483 This.chars = GC_malloc_atomic((This.capacity + 1) * SizeOf (Char)) 486 484 End Sub 487 485 … … 516 514 Sub separateBuffer() 517 515 If stringized Then 518 Dim newChars = GC_malloc_atomic(SizeOf ( StrChar) * capacity) As *StrChar516 Dim newChars = GC_malloc_atomic(SizeOf (Char) * capacity) As *Char 519 517 ActiveBasic.Strings.ChrCopy(newChars, chars, capacity As SIZE_T) 520 518 chars = newChars … … 523 521 End Sub 524 522 525 chars As * StrChar523 chars As *Char 526 524 maxCapacity As Long 527 525 capacity As Long … … 534 532 535 533 '暫定 536 Function StrPtr(sb As System.Text.StringBuilder) As * StrChar534 Function StrPtr(sb As System.Text.StringBuilder) As *Char 537 535 Return sb.__Chars 538 536 End Function -
trunk/Include/Classes/System/Xml/XmlDocument.ab
r463 r468 136 136 Save( fileStream ) 137 137 End Sub 138 139 /*! 140 @brief 指定したテキストライタにXML文書を保存する。 141 @param テキストライタ。 142 */ 143 Virtual Sub Save( writer As System.IO.TextWriter ) 144 writer.Write(InnerXmlSupportedIndent( True )) 145 End Sub 138 146 End Class 139 147 -
trunk/Include/Classes/System/misc.ab
r467 r468 1 1 ' Classes/System/misc.ab 2 3 #ifndef __SYSTEM_MISC_AB__4 #define __SYSTEM_MISC_AB__5 6 '#require <Classes/System/Threading/WaitHandle.ab>7 2 8 3 Namespace System … … 36 31 End Class 37 32 33 Delegate Sub EventHandler(sender As Object, e As EventArgs) 34 38 35 Delegate Sub AsyncCallback(ar As IAsyncResult) 39 36 40 41 37 End Namespace 'System 42 #require <Classes/System/Threading/WaitHandle.ab>43 44 #endif '__SYSTEM_MISC_AB__ -
trunk/Include/Classes/index.ab
r461 r468 68 68 #require "./System/IO/Stream.ab" 69 69 #require "./System/IO/TextReader.ab" 70 #require "./System/IO/TextWriter.ab" 70 71 #require "./System/IO/StreamReader.ab" 71 72 #require "./System/IO/StringReader.ab" -
trunk/Include/basic.sbp
r400 r468 64 64 TypeDef Char = SByte 65 65 #endif 66 67 ' 文字型68 #ifdef UNICODE69 TypeDef Char = Word70 #else71 TypeDef Char = SByte72 #endif73 74 66 75 67 '------------------ -
trunk/TestCase/SimpleTestCase/SPrintFTest.ab
r385 r468 118 118 s = FormatFloatG(0.0000123456, 4, 0, None) 119 119 UnitTest("FormatFloatG(0.0000123456, precision = 4) = 1.234e-05", s, "1.234e-05") 120 s = FormatFloatG(ActiveBasic.Math.Detail.GetNaN(), DWORD_MAX, 0, None) 121 UnitTest(Ex"FormatFloatG(NaN) = \qnan\q", s, "nan") 122 s = FormatFloatG(ActiveBasic.Math.Detail.GetInf(False), DWORD_MAX, 0, Sign) 123 UnitTest(Ex"FormatFloatG(Inf, Sign) = \q+infinity\q", s, "+infinity") 120 124 121 125 s = FormatFloatA(1, DWORD_MAX, 0, None) … … 127 131 s = FormatFloatA(3.1415926535897932384626433832795, DWORD_MAX, 0, None) 128 132 UnitTest("FormatFloatA(π) = 0x1.921fb54442d18p+1", s, "0x1.921fb54442d18p+1") 133 s = FormatFloatA(3.1415926535897932384626433832795, 4, 0, None) 134 UnitTest("FormatFloatA(π, precision = 4) = 0x1.921fp+1", s, "0x1.921fp+1") 129 135 s = FormatFloatA(0, DWORD_MAX, 0, None) 130 136 UnitTest("FormatFloatA(0)", s, "0x0p+0") -
trunk/TestCase/SimpleTestCase/SimpleTestCase.ab
r465 r468 5 5 Dim hStdOut = _System_hConsoleOut 6 6 7 Function GetTempDirectory() As String 8 Return System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp\" 9 ' Return System.IO.Path.GetTempPath() 10 End Function 11 7 12 Sub Initialize() 8 13 ' 初期化関数 9 14 10 15 ' 一時ディレクトリを空にしておく 11 Dim tempDir = System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp"16 Dim tempDir = GetTempDirectory() 12 17 If System.IO.Directory.Exists( tempDir ) Then 13 ' 存在するときは一旦消す 14 System.IO.Directory.Delete( tempDir, True ) 18 Try 19 ' 存在するときは一旦消す 20 System.IO.Directory.Delete( tempDir, True ) 21 Catch e As System.IO.IOException 22 OutputDebugString(e.ToString) 23 End Try 15 24 End If 16 25 System.IO.Directory.CreateDirectory( tempDir ) … … 24 33 #include "SimpleTestCase.idx" 25 34 35 Dim failureCount = 0 As DWord 36 26 37 Sub UnitTest( msg As String, isSuccessful As Boolean ) 27 38 Dim resultStr = Nothing As String … … 30 41 Else 31 42 resultStr = Ex"FAILURE!" 43 failureCount++ 32 44 End If 33 45 … … 49 61 SetConsoleTextAttribute(hStdOut, BACKGROUND_RED Or BACKGROUND_GREEN Or BACKGROUND_INTENSITY) 50 62 Print Ex"FAILURE!"; msg 51 Print " test string= '" + test + "'"63 Print " 期待 = '" + expectation + "'" + " 結果 = '" + test + "'" 52 64 SetConsoleTextAttribute(hStdOut, csbi.wAttributes) 65 failureCount++ 53 66 End If 54 67 End Sub 55 68 56 69 Function GetExclusiveTempDirPath( testCaseName As String ) As String 57 Dim tempDir = System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp"58 Dim exclusiveTempDirPath = tempDir + "\" +testCaseName70 Dim tempDir = GetTempDirectory() 71 Dim exclusiveTempDirPath = tempDir + testCaseName 59 72 60 73 If Not System.IO.Directory.Exists( exclusiveTempDirPath ) Then … … 66 79 End Function 67 80 81 Print "失敗"; failureCount; "個" 68 82 Print "Please Enter key" 69 83 System.Console.ReadLine() -
trunk/TestCase/SimpleTestCase/StringBuilderTest.ab
r457 r468 18 18 sb.Replace("こい", "いけ").Replace("いけ", "こい") 19 19 UnitTest("StringBuilder.Replace (String)", sb.ToString, "でてこいでてこいこいのこい") 20 sb.Length = 0 21 sb.Append(123) 22 UnitTest("StringBuilder.Append (Long)", sb.ToString, "123") 20 23 End Sub 21 24 … … 23 26 24 27 StringBuilderTest.TestMain() 25 -
trunk/TestCase/SimpleTestCase/XmlTest.ab
r465 r468 19 19 20 20 ' 書いて 21 doc.Save( tempDir + " \test.xml" )21 doc.Save( tempDir + "test.xml" ) 22 22 23 23 ' 読んで 24 24 Dim clone = New System.Xml.XmlDocument 25 clone.Load( tempDir + " \test.xml" )25 clone.Load( tempDir + "test.xml" ) 26 26 27 27 ' 比較してみる
Note:
See TracChangeset
for help on using the changeset viewer.