Changeset 468 for trunk/Include/Classes/System/String.ab
- Timestamp:
- Mar 9, 2008, 12:00:01 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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)
Note:
See TracChangeset
for help on using the changeset viewer.