source: trunk/ab5.0/ablib/src/Classes/System/String.ab@ 634

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

#202 Compare/CompareOrdinal完了

File size: 22.7 KB
Line 
1' Classes/System/String.ab
2
3Namespace System
4
5 Class String
6 Implements /*IComparable, ICloneable, IConvertible, IComparable<String>, IEnumerable, IEnumerable<Char>, IEquatable<String>*/
7
8 m_Length As Long
9 Chars As *Char
10
11 Sub validPointerCheck(p As VoidPtr, size = 1 As Long)
12 If p As ULONG_PTR < &h10000 Then
13 Throw New ArgumentException
14 ElseIf IsBadReadPtr(p, size As ULONG_PTR) Then
15 Throw New ArgumentException
16 End If
17 End Sub
18 Public
19 Static Const Empty = New String
20
21 Sub String()
22' Chars = 0
23' m_Length = 0
24 End Sub
25
26 Sub String(initStr As PCWSTR)
27 validPointerCheck(initStr)
28 Assign(initStr, lstrlenW(initStr))
29 End Sub
30
31 Sub String(initStr As PCWSTR, length As Long)
32 validPointerCheck(initStr, length)
33 Assign(initStr, length)
34 End Sub
35
36 Sub String(initStr As PCWSTR, start As Long, length As Long)
37 If start < 0 Or length Or start + length < 0 Then
38 Throw New ArgumentOutOfRangeException("String constractor: One or more arguments are out of range value.", "start or length or both")
39 End If
40 validPointerCheck(initStr + start, length)
41 Assign(initStr + start, length)
42 End Sub
43
44 Sub String(initStr As PCSTR)
45 validPointerCheck(initStr)
46 Assign(initStr, lstrlenA(initStr))
47 End Sub
48
49 Sub String(initStr As PCSTR, length As Long)
50 validPointerCheck(initStr, length)
51 Assign(initStr, length)
52 End Sub
53
54 Sub String(initStr As PCSTR, start As Long, length As Long)
55 If start < 0 Or length < 0 Then
56 Throw New ArgumentOutOfRangeException("String constructor: One or more arguments are out of range value.", "start or length or both")
57 End If
58 validPointerCheck(initStr + start, length)
59 Assign(initStr + start, length)
60 End Sub
61
62 Sub String(initStr As String)
63 If Not IsNullOrEmpty(initStr) Then
64 Assign(initStr.Chars, initStr.m_Length)
65 End If
66 End Sub
67
68 Sub String(initChar As Char, length As Long)
69 AllocStringBuffer(length)
70 ActiveBasic.Strings.ChrFill(Chars, length, initChar)
71 Chars[length] = 0
72 End Sub
73
74 Sub String(sb As Text.StringBuilder)
75 Chars = StrPtr(sb)
76 m_Length = sb.Length
77 sb.__Stringized()
78 End Sub
79
80 Const Function Length() As Long
81 Return m_Length
82 End Function
83
84 Function Operator() As *Char
85 Return Chars
86 End Function
87
88 Const Function Operator [] (n As Long) As Char
89 rangeCheck(n)
90 Return Chars[n]
91 End Function
92
93 Const Function Operator + (y As PCSTR) As String
94 If y = 0 Then
95 Return This
96 Else
97 Return Concat(y, lstrlenA(y))
98 End If
99 End Function
100
101 Const Function Operator + (y As PCWSTR) As String
102 If y = 0 Then
103 Return This
104 Else
105 Return Concat(y, lstrlenW(y))
106 End If
107 End Function
108
109 Const Function Operator + (y As String) As String
110 If ActiveBasic.IsNothing(y) Then
111 Return This
112 Else
113 Return Concat(y.Chars, y.m_Length)
114 End If
115 End Function
116
117 Const Function Operator & (y As PCSTR) As String
118 Return This + y
119 End Function
120
121 Const Function Operator & (y As PCWSTR) As String
122 Return This + y
123 End Function
124
125 Const Function Operator & (y As String) As String
126 Return This + y
127 End Function
128
129 Const Function Operator == (y As String) As Boolean
130 Return CompareOrdinal(This, y) = 0
131 End Function
132
133 Const Function Operator == (y As *Char) As Boolean
134 Return CompareOrdinal(This, y) = 0
135 End Function
136
137 Const Function Operator <> (y As String) As Boolean
138 Return CompareOrdinal(This, y) <> 0
139 End Function
140
141 Const Function Operator <> (y As *Char) As Boolean
142 Return CompareOrdinal(This, y) <> 0
143 End Function
144
145 Const Function Operator < (y As String) As Boolean
146 Return CompareOrdinal(This, y) < 0
147 End Function
148
149 Const Function Operator < (y As *Char) As Boolean
150 Return CompareOrdinal(This, y) < 0
151 End Function
152
153 Const Function Operator > (y As String) As Boolean
154 Return CompareOrdinal(This, y) > 0
155 End Function
156
157 Const Function Operator > (y As *Char) As Boolean
158 Return CompareOrdinal(This, y) > 0
159 End Function
160
161 Const Function Operator <= (y As String) As Boolean
162 Return CompareOrdinal(This, y) <= 0
163 End Function
164
165 Const Function Operator <= (y As *Char) As Boolean
166 Return CompareOrdinal(This, y) <= 0
167 End Function
168
169 Const Function Operator >= (y As String) As Boolean
170 Return CompareOrdinal(This, y) >= 0
171 End Function
172
173 Const Function Operator >= (y As *Char) As Boolean
174 Return CompareOrdinal(This, y) >= 0
175 End Function
176
177 /*!
178 @brief 単語順での文字列比較
179 @auther Egtra
180 */
181 Static Function Compare(x As String, y As String) As Long
182 Return Compare(x, y, False)
183 End Function
184
185 Static Function Compare(x As String, y As String, ignoreCase As Boolean) As Long
186 Dim lhs = removeNull(x)
187 Dim rhs = removeNull(y)
188 Return compareImpl(lhs.Chars, lhs.Length, rhs.Chars, rhs.Length, ignoreCase)
189 End Function
190
191 Static Function Compare(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long
192 Return Compare(x, indexX, y, indexY, length, False)
193 End Function
194
195 Static Function Compare(x As String, indexX As Long, y As String, indexY As Long, length As Long, ignoreCase As Boolean) As Long
196 Dim lhs = removeNull(x)
197 Dim rhs = removeNull(y)
198 If lhs.Length > indexX Or indexX < 0 Then
199 Throw New ArgumentOutOfRangeException("indexX")
200 ElseIf rhs.Length > indexY Or indexY < 0 Then
201 Throw New ArgumentOutOfRangeException("indexY")
202 ElseIf length < 0 Then
203 Throw New ArgumentOutOfRangeException("length")
204 End If
205 Dim cmpLen = Math.Min(Math.Min(lhs.Length - indexX, rhs.Length - indexY), length)
206 Return compareImpl(VarPtr(lhs.Chars[indexX]), cmpLen, VarPtr(rhs.Chars[indexY]), cmpLen, ignoreCase)
207 End Function
208
209 /*!
210 @brief 序数での文字列比較
211 */
212 Static Function CompareOrdinal(x As String, y As String) As Long
213 Dim lhs = removeNull(x)
214 Dim rhs = removeNull(y)
215 Return compareOrdinalImpl(lhs.Chars, lhs.Length, rhs.Chars, rhs.Length)
216 End Function
217
218 Static Function CompareOrdinal(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long
219 Dim lhs = removeNull(x)
220 Dim rhs = removeNull(y)
221 If lhs.Length > indexX Or indexX < 0 Then
222 Throw New ArgumentOutOfRangeException("indexX")
223 ElseIf rhs.Length > indexY Or indexY < 0 Then
224 Throw New ArgumentOutOfRangeException("indexY")
225 ElseIf length < 0 Then
226 Throw New ArgumentOutOfRangeException("length")
227 End If
228 Dim cmpLen = Math.Min(Math.Min(lhs.Length - indexX, rhs.Length - indexY), length)
229 Return compareOrdinalImpl(VarPtr(lhs.Chars[indexX]), cmpLen, VarPtr(rhs.Chars[indexY]), cmpLen)
230 End Function
231
232 Static Function CompareOrdinal(x As String, y As *Char) As Long
233 Dim lhs = removeNull(x)
234 Return compareOrdinalImpl(lhs.Chars, lhs.Length, y, lstrlen(y))
235 End Function
236
237 Private
238 Static Function compareImpl(x As *Char, lenX As Long, y As *Char, lenY As Long, ignoreCase As Boolean) As Long
239 Dim flags = 0 As DWord
240 If ignoreCase Then
241 flags = NORM_IGNORECASE
242 End If
243 Dim ret = CompareString(LOCALE_USER_DEFAULT, ignoreCase, x, lenX, y, lenY)
244 Select Case ret
245 Case CSTR_LESS_THAN
246 compareImpl = -1
247 Case CSTR_EQUAL
248 compareImpl = 0
249 Case CSTR_GREATER_THAN
250 compareImpl = 1
251 Case Else
252 ActiveBasic.Windows.ThrowWithLastError("String.Compare")
253 End Select
254 End Function
255
256 Static Function compareOrdinalImpl(x As *Char, lenX As Long, y As *Char, lenY As Long) As Long
257 Return ActiveBasic.Strings.ChrCmp(x, lenX As SIZE_T, y, lenY As SIZE_T)
258 End Function
259
260 Public
261 Function CompareTo(y As String) As Long
262 Return String.Compare(This, y)
263 End Function
264
265 Function CompareTo(y As Object) As Long
266 If Not Object.Equals(This.GetType(), y.GetType()) Then
267 Throw New ArgumentException("String.CompareTo: y is not String.", "y")
268 End If
269 Return CompareTo(y As String)
270 End Function
271
272 Function Equals(s As String) As Boolean
273 Return This = s
274 End Function
275
276 Override Function Equals(s As Object) As Boolean
277 If Not ActiveBasic.IsNothing(s) Then
278 If Object.Equals(This.GetType(), s.GetType()) Then
279 Return This.Equals(s As String)
280 End If
281 End If
282 Return False
283 End Function
284
285 Const Function StrPtr() As *Char
286 Return Chars
287 End Function
288Private
289
290 Sub Assign(text As PCSTR, textLengthA As Long)
291#ifdef UNICODE
292 Dim textLengthW = MultiByteToWideChar(CP_THREAD_ACP, 0, text, textLengthA, 0, 0)
293 AllocStringBuffer(textLengthW)
294 MultiByteToWideChar(CP_THREAD_ACP, 0, text, textLengthA, Chars, textLengthW)
295 Chars[textLengthW] = 0
296#else
297 AssignFromCharPtr(text, textLengthA)
298#endif
299 End Sub
300
301 Sub Assign(text As PCWSTR, textLengthW As Long)
302#ifdef UNICODE
303 AssignFromCharPtr(text, textLengthW)
304#else
305 Dim textLengthA = WideCharToMultiByte(CP_THREAD_ACP, 0, text, textLengthW, 0, 0, 0, 0)
306 AllocStringBuffer(textLengthA)
307 WideCharToMultiByte(CP_THREAD_ACP, 0, text, textLengthW, Chars, textLengthA, 0, 0)
308 Chars[textLengthA] = 0
309#endif
310 End Sub
311
312 Private
313 Static Function ConcatChar(text1 As *Char, text1Length As Long, text2 As *Char, text2Length As Long) As String
314 ConcatChar = New String()
315 With ConcatChar
316 .AllocStringBuffer(text1Length + text2Length)
317 ActiveBasic.Strings.ChrCopy(.Chars, text1, text1Length As SIZE_T)
318 ActiveBasic.Strings.ChrCopy(VarPtr(.Chars[text1Length]), text2, text2Length As SIZE_T)
319 .Chars[text1Length + text2Length] = 0
320 End With
321 End Function
322 Public
323 Const Function Concat(text As PCSTR, len As Long) As String
324#ifdef UNICODE
325 With Concat
326 Dim lenW = MultiByteToWideChar(CP_THREAD_ACP, 0, text, len, 0, 0)
327 Concat = New String
328 .AllocStringBuffer(m_Length + lenW)
329 ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length As SIZE_T)
330 MultiByteToWideChar(CP_THREAD_ACP, 0, text, len, VarPtr(.Chars[m_Length]), lenW)
331 .Chars[m_Length + lenW] = 0
332 End With
333#else
334 Return ConcatChar(This.Chars, m_Length, text, len)
335#endif
336 End Function
337
338 Const Function Concat(text As PCWSTR, len As Long) As String
339#ifdef UNICODE
340 Return ConcatChar(This.Chars, m_Length, text, len)
341#else
342 With Concat
343 Concat = New String
344 Dim lenA = WideCharToMultiByte(CP_THREAD_ACP, 0, text, len, 0, 0, 0, 0)
345 .AllocStringBuffer(m_Length + lenA)
346 ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length As SIZE_T)
347 WideCharToMultiByte(CP_THREAD_ACP, 0, text, len, VarPtr(.Chars[m_Length]), lenA, 0, 0)
348 .Chars[m_Length + lenA] = 0
349 End With
350#endif
351 End Function
352
353 Static Function Concat(x As String, y As String) As String
354 If IsNullOrEmpty(x) Then
355 Return y
356 Else
357 Return x.Concat(y.Chars, y.m_Length)
358 End If
359 End Function
360
361 Static Function Concat(x As String, y As String, z As String) As String
362 Dim sb = New Text.StringBuilder(removeNull(x).Length + removeNull(y).Length + removeNull(z).Length)
363 sb.Append(x).Append(y).Append(z)
364 Concat = sb.ToString
365 End Function
366
367 Static Function Concat(x As String, y As String, z As String, w As String) As String
368 Dim sb = New Text.StringBuilder(removeNull(x).Length + removeNull(y).Length + removeNull(z).Length + removeNull(w).Length)
369 sb.Append(x).Append(y).Append(z).Append(w)
370 Concat = sb.ToString
371 End Function
372
373 Static Function Concat(x As Object, y As Object) As String
374 Return Concat(x.ToString, y.ToString)
375 End Function
376
377 Static Function Concat(x As Object, y As Object, z As Object) As String
378 Return Concat(x.ToString, y.ToString, z.ToString)
379 End Function
380
381 Static Function Concat(x As Object, y As Object, z As Object, w As Object) As String
382 Return Concat(x.ToString, y.ToString, z.ToString, w.ToString)
383 End Function
384
385 Const Function Contains(c As Char) As Boolean
386 Return IndexOf(c) >= 0
387 End Function
388
389 Const Function Contains(s As String) As Boolean
390 If ActiveBasic.IsNothing(s) Then
391 Throw New ArgumentNullException("String.Contains: An argument is null value.", "s")
392 ElseIf s = "" Then
393 Return True
394 Else
395 Return IndexOf(s, 0, m_Length) >= 0
396 End If
397 End Function
398
399 Const Function IndexOf(c As Char) As Long
400 Return indexOfCore(c, 0, m_Length)
401 End Function
402
403 Const Function IndexOf(c As Char, start As Long) As Long
404 rangeCheck(start)
405 Return indexOfCore(c, start, m_Length - start)
406 End Function
407
408 Const Function IndexOf(c As Char, start As Long, count As Long) As Long
409 rangeCheck(start, count)
410 Return indexOfCore(c, start, count)
411 End Function
412 Private
413 Const Function indexOfCore(c As Char, start As Long, count As Long) As Long
414 indexOfCore = ActiveBasic.Strings.ChrFind(VarPtr(Chars[start]), count, c) As Long
415 If indexOfCore <> -1 Then
416 indexOfCore += start
417 End If
418 End Function
419 Public
420 Const Function IndexOf(s As String) As Long
421 Return IndexOf(s, 0, m_Length)
422 End Function
423
424 Const Function IndexOf(s As String, startIndex As Long) As Long
425 Return IndexOf(s, startIndex, m_Length - startIndex)
426 End Function
427
428 Const Function IndexOf(s As String, startIndex As Long, count As Long) As Long
429 rangeCheck(startIndex, count)
430 If ActiveBasic.IsNothing(s) Then
431 Throw New ArgumentNullException("String.IndexOf: An argument is out of range value.", "s")
432 End If
433
434 Dim length = s.Length
435 If length = 0 Then Return startIndex
436
437 Dim i As Long, j As Long
438 For i = startIndex To startIndex + count - 1
439 For j = 0 To length - 1
440 If Chars[i + j] = s[j] Then
441 If j = length - 1 Then Return i
442 Else
443 Exit For
444 End If
445 Next
446 Next
447 Return -1
448 End Function
449
450 Const Function LastIndexOf(c As Char) As Long
451 Return lastIndexOf(c, m_Length - 1, m_Length)
452 End Function
453
454 Const Function LastIndexOf(c As Char, start As Long) As Long
455 rangeCheck(start)
456 Return lastIndexOf(c, start, start + 1)
457 End Function
458
459 Const Function LastIndexOf(c As Char, start As Long, count As Long) As Long
460 rangeCheck(start)
461 Dim lastFindPos = start - (count - 1)
462 If Not (m_Length > lastFindPos And lastFindPos >= 0) Then
463 Throw New ArgumentOutOfRangeException("String.LastIndexOf: An argument is out of range value.", "count")
464 End If
465 Return lastIndexOf(c, start, count)
466 End Function
467 Private
468 Const Function lastIndexOf(c As Char, start As Long, count As Long) As Long
469 Dim lastFindPos = start - (count - 1)
470 Dim i As Long
471 For i = start To lastFindPos Step -1
472 If Chars[i] = c Then
473 Return i
474 End If
475 Next
476 Return -1
477 End Function
478
479 Public
480 Const Function LastIndexOf(s As String) As Long
481 Return LastIndexOf(s, m_Length - 1, m_Length)
482 End Function
483
484 Const Function LastIndexOf(s As String, startIndex As Long) As Long
485 Return LastIndexOf(s, startIndex, startIndex + 1)
486 End Function
487
488 Const Function LastIndexOf(s As String, start As Long, count As Long) As Long
489 If ActiveBasic.IsNothing(s) Then
490 Throw New ArgumentNullException("String.LastIndexOf: An argument is out of range value.", "s")
491 End If
492
493 If start < 0 Or start > m_Length - 1 Or _
494 count < 0 Or count > start + 2 Then
495 Throw New ArgumentOutOfRangeException("String.LastIndexOf: One or more arguments are out of range value.", "start or count or both")
496 End If
497 Dim length = s.m_Length
498 If length > m_Length Then Return -1
499 If length = 0 Then Return start
500
501 Dim i As Long, j As Long
502 For i = start To start - count + 1 Step -1
503 For j = length - 1 To 0 Step -1
504 If Chars[i + j] = s[j] Then
505 If j = 0 Then Return i
506 Else
507 Exit For
508 End If
509 Next
510 Next
511 Return -1
512 End Function
513
514 Const Function StartsWith(c As Char) As Boolean
515 Return IndexOf(c) = 0
516 End Function
517
518 Const Function StartsWith(s As String) As Boolean
519 Return IndexOf(s) = 0
520 End Function
521
522 Const Function EndsWith(c As Char) As Boolean
523 Return LastIndexOf(c) = m_Length - 1
524 End Function
525
526 Const Function EndsWith(s As String) As Boolean
527 Return LastIndexOf(s) = m_Length - s.Length
528 End Function
529
530 Const Function Insert(startIndex As Long, text As String) As String
531 Dim sb = New Text.StringBuilder(This)
532 sb.Insert(startIndex, text)
533 Return sb.ToString
534 End Function
535
536 Const Function Substring(startIndex As Long) As String
537 rangeCheck(startIndex)
538 Return Substring(startIndex, m_Length - startIndex)
539 End Function
540
541 Const Function Substring(startIndex As Long, length As Long) As String
542 rangeCheck(startIndex, length)
543 Return New String(Chars, startIndex, length)
544 End Function
545
546 Const Function Remove(startIndex As Long) As String
547 rangeCheck(startIndex)
548 Remove = Substring(0, startIndex)
549 End Function
550
551 Const Function Remove(startIndex As Long, count As Long) As String
552 Dim sb = New Text.StringBuilder(This)
553 sb.Remove(startIndex, count)
554 Remove = sb.ToString
555 End Function
556
557 Static Function IsNullOrEmpty(s As String) As Boolean
558 If Not Object.ReferenceEquals(s, Nothing) Then
559 If s.m_Length > 0 Then
560 Return False
561 End If
562 End If
563 Return True
564 End Function
565
566 Const Function Replace(oldChar As Char, newChar As Char) As String
567 Dim sb = New Text.StringBuilder(This)
568 sb.Replace(oldChar, newChar)
569 Replace = sb.ToString
570 End Function
571
572 Const Function Replace(oldStr As String, newStr As String) As String
573 Dim sb = New Text.StringBuilder(This)
574 sb.Replace(oldStr, newStr)
575 Return sb.ToString
576 End Function
577
578 Function Split(separator As System.Collections.Generic.List<String>) As System.Collections.Generic.List<String>
579 Return Split(separator, -1, StringSplitOptions.None)
580 End Function
581
582 Function Split(separator As System.Collections.Generic.List<String>, options As StringSplitOptions) As System.Collections.Generic.List<String>
583 Return Split(separator, -1, options)
584 End Function
585
586 Function Split(separator As System.Collections.Generic.List<String>, count As Long, options As StringSplitOptions) As System.Collections.Generic.List<String>
587 Dim split As System.Collections.Generic.List<String>
588 Dim index As Long, t1Index As Long, t2Index As Long
589 Dim s As String, substring As String
590 Dim flag As Boolean
591
592 Do
593 t1Index = Length
594 flag = True
595 Foreach s In separator
596 t2Index = IndexOf(s, index)
597 If t2Index > -1 Then
598 t1Index = Math.Min(t1Index, t2Index)
599 flag = False
600 End If
601 Next
602
603 substring = Substring(index, t1Index - index)
604 If Not ( IsNullOrEmpty(substring) and (options = StringSplitOptions.RemoveEmptyEntries) ) Then
605 split.Add(substring)
606 End If
607
608 If flag Then Return split
609 If split.Count = count Then Return split
610
611 index = t1Index + 1
612 Loop
613 End Function
614
615 Static Function Join(separator As String, strings As System.Collections.Generic.List<String>) As String
616 Return Join(separator, strings, 0, strings.Count)
617 End Function
618
619 Static Function Join(separator As String, strings As System.Collections.Generic.List<String>, startIndex As Long, count As Long) As String
620 If (startIndex+count > strings.Count) or (startIndex < 0) or (count < 1) Then
621 Throw New ArgumentOutOfRangeException("String.Join: One or more arguments are out of range value.", "startIndex or count")
622 End If
623
624 Dim string As String
625 Dim i As Long
626 For i = startIndex To startIndex + count - 2
627 string += strings[i] + separator
628 Next
629 Return string + strings[i]
630 End Function
631
632 Const Function ToLower() As String
633 Dim sb = New Text.StringBuilder(m_Length)
634 sb.Length = m_Length
635 Dim i As Long
636 For i = 0 To ELM(m_Length)
637 sb[i] = ActiveBasic.CType.ToLower(Chars[i])
638 Next
639 Return sb.ToString
640 End Function
641
642 Const Function ToUpper() As String
643 Dim sb = New Text.StringBuilder(m_Length)
644 sb.Length = m_Length
645 Dim i As Long
646 For i = 0 To ELM(m_Length)
647 sb[i] = ActiveBasic.CType.ToUpper(Chars[i])
648 Next
649 Return sb.ToString
650 End Function
651
652 Override Function ToString() As String
653 ToString = This
654 End Function
655
656 Const Function Clone() As String
657 Clone = This
658 End Function
659/*
660 Function Clone() As Object
661 Clone = This
662 End Function
663*/
664 Static Function Copy(s As String) As String
665 Copy = New String(s.Chars, s.m_Length)
666 End Function
667
668 Sub CopyTo(sourceIndex As Long, destination As *Char, destinationIndex As Long, count As Long)
669 ActiveBasic.Strings.ChrCopy(VarPtr(destination[destinationIndex]), VarPtr(Chars[sourceIndex]), count As SIZE_T)
670 End Sub
671
672 Override Function GetHashCode() As Long
673#ifdef UNICODE
674 Dim size = m_Length
675#else
676 Dim size = (m_Length + 1) >> 1
677#endif
678 Return _System_GetHashFromWordArray(Chars As *Word, size) Xor m_Length
679 End Function
680
681 Function PadLeft(total As Long) As String
682 PadLeft(total, &h30 As Char)
683 End Function
684
685 Function PadLeft(total As Long, c As Char) As String
686 If total < 0 Then
687 Throw New ArgumentOutOfRangeException("String.PadLeft: An arguments is out of range value.", "total")
688 End If
689 If total >= m_Length Then
690 Return This
691 End If
692 Dim sb = New Text.StringBuilder(total)
693 sb.Append(c, total - m_Length)
694 sb.Append(This)
695 Return sb.ToString
696 End Function
697
698 Function PadRight(total As Long) As String
699 PadRight(total, &h30 As Char)
700 End Function
701
702 Function PadRight(total As Long, c As Char) As String
703 If total < 0 Then
704 Throw New ArgumentOutOfRangeException("String.PadRight: An arguments is out of range value.", "total")
705 End If
706 If total >= m_Length Then
707 Return This
708 End If
709 Dim sb = New Text.StringBuilder(total)
710 sb.Append(This)
711 sb.Append(c, total - m_Length)
712 Return sb.ToString
713 End Function
714 Private
715 Sub AllocStringBuffer(textLength As Long)
716 If textLength < 0 Then
717 Throw New ArgumentException
718 End If
719 Chars = GC_malloc_atomic(SizeOf(Char) * (textLength + 1))
720 m_Length = textLength
721 End Sub
722
723 Sub AssignFromCharPtr(text As *Char, textLength As Long)
724 AllocStringBuffer(textLength)
725 ActiveBasic.Strings.ChrCopy(Chars, text, textLength As SIZE_T)
726 Chars[m_Length] = 0
727 End Sub
728
729 Const Sub rangeCheck(index As Long)
730 If index < 0 Or index > m_Length Then
731 Throw New ArgumentOutOfRangeException("String: An argument is out of range value.", "index")
732 End If
733 End Sub
734
735 Const Sub rangeCheck(start As Long, length As Long)
736 If start < 0 Or start > This.m_Length Or length < 0 Then
737 Throw New ArgumentOutOfRangeException("String: One or more arguments are out of range value.", "start or length or both")
738 End If
739 End Sub
740
741 Static Function removeNull(s As String) As String
742 If ActiveBasic.IsNothing(s) Then
743 removeNull = Empty
744 Else
745 removeNull = s
746 End If
747 End Function
748 End Class
749
750 Enum StringSplitOptions
751 None
752 RemoveEmptyEntries
753 End Enum
754
755End Namespace
Note: See TracBrowser for help on using the repository browser.