1 // -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
6 // Jeffrey Stedfast (fejj@ximian.com)
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
11 // FIXME: from what I gather from msdn, when a function is to return an empty string
12 // we should be returning this.Empty - some methods do this and others don't.
14 // FIXME: I didn't realise until later that `string' has a .Length method and so
15 // I am missing some proper bounds-checking in some methods. Find these
16 // instances and throw the ArgumentOutOfBoundsException at the programmer.
17 // I like pelting programmers with ArgumentOutOfBoundsException's :-)
19 // FIXME: The ToLower(), ToUpper(), and Compare(..., bool ignoreCase) methods
20 // need to be made unicode aware.
22 // FIXME: when you have a char carr[], does carr.Length include the terminating null char?
26 using System.Collections;
27 using System.Globalization;
28 using System.Runtime.CompilerServices;
32 public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable {
33 public static readonly string Empty = "";
38 unsafe public String (char *value)
42 // FIXME: can I do value.Length here?
46 for (i = 0; *(value + i) != '\0'; i++);
50 this.c_str = new char [this.length + 1];
51 for (i = 0; i < this.length; i++)
52 this.c_str[i] = *(value + i);
56 public String (char[] value)
60 // FIXME: value.Length includes the terminating null char?
61 this.length = value != null ? strlen (value): 0;
62 this.c_str = new char [this.length + 1];
63 for (i = 0; i < this.length; i++)
64 this.c_str[i] = value[i];
68 unsafe public String (sbyte *value)
70 // FIXME: consider unicode?
73 // FIXME: can I do value.Length here? */
77 for (i = 0; *(value + i) != '\0'; i++);
81 this.c_str = new char [this.length + 1];
82 for (i = 0; i < this.length; i++)
83 this.c_str[i] = (char) *(value + i);
87 public String (char c, int count)
92 this.c_str = new char [count + 1];
93 for (i = 0; i < count; i++)
98 unsafe public String (char *value, int startIndex, int length)
102 if (value == null && startIndex != 0 && length != 0)
103 throw new ArgumentNullException ();
105 if (startIndex < 0 || length < 0)
106 throw new ArgumentOutOfRangeException ();
108 this.length = length;
109 this.c_str = new char [length + 1];
110 for (i = 0; i < length; i++)
111 this.c_str[i] = *(value + startIndex + i);
112 this.c_str[i] = '\0';
115 public String (char[] value, int startIndex, int length)
119 if (value == null && startIndex != 0 && length != 0)
120 throw new ArgumentNullException ();
122 if (startIndex < 0 || length < 0)
123 throw new ArgumentOutOfRangeException ();
125 this.length = length;
126 this.c_str = new char [length + 1];
127 for (i = 0; i < length; i++)
128 this.c_str[i] = value[startIndex + i];
129 this.c_str[i] = '\0';
132 unsafe public String (sbyte *value, int startIndex, int length)
134 // FIXME: consider unicode?
137 if (value == null && startIndex != 0 && length != 0)
138 throw new ArgumentNullException ();
140 if (startIndex < 0 || length < 0)
141 throw new ArgumentOutOfRangeException ();
143 this.length = length;
144 this.c_str = new char [length + 1];
145 for (i = 0; i < length; i++)
146 this.c_str[i] = (char) *(value + startIndex + i);
147 this.c_str[i] = '\0';
150 unsafe public String (sbyte *value, int startIndex, int length, Encoding enc)
152 // FIXME: implement me
157 // FIXME: is there anything we need to do here?
158 /*base.Finalize ();*/
168 // FIXME: is this correct syntax??
169 public char this [int index] {
171 if (index > this.length)
172 throw new ArgumentOutOfRangeException ();
174 return this.c_str[index];
178 // Private helper methods
179 private static int strlen (char[] str)
181 // FIXME: if str.Length includes terminating null char, then return (str.Length - 1)
185 private static char tolowerordinal (char c)
187 // FIXME: implement me
191 private static bool is_lwsp (char c)
193 /* this comes from the msdn docs for String.Trim() */
194 if ((c >= '\x9' && c <= '\xD') || c == '\x20' || c == '\xA0' ||
195 (c >= '\x2000' && c <= '\x200B') || c == '\x3000' || c == '\xFEFF')
201 private static int BoyerMoore (char[] haystack, string needle, int startIndex, int count)
203 /* (hopefully) Unicode-safe Boyer-Moore implementation */
204 int[] skiptable = new int[65536]; /* our unicode-safe skip-table */
205 int h, n, he, ne, hc, nc, i;
207 if (haystack == null || needle == null)
208 throw new ArgumentNullException ();
210 /* if the search buffer is shorter than the pattern buffer, we can't match */
211 if (count < needle.Length)
214 /* return an instant match if the pattern is 0-length */
215 if (needle.Length == 0)
218 /* set a pointer at the end of each string */
219 ne = needle.Length - 1; /* position of char before '\0' */
220 he = startIndex + count; /* position of last valid char */
222 /* init the skip table with the pattern length */
223 for (i = 0; i < 65536; i++)
224 skiptable[i] = needle.Length;
226 /* set the skip value for the chars that *do* appear in the
227 * pattern buffer (needle) to the distance from the index to
228 * the end of the pattern buffer. */
229 for (nc = 0; nc < ne; nc++)
230 skiptable[(int) needle[nc]] = ne - nc;
233 while (count >= needle.Length) {
234 hc = h + needle.Length - 1; /* set the haystack compare pointer */
235 nc = ne; /* set the needle compare pointer */
237 /* work our way backwards until they don't match */
238 for (i = 0; nc > 0; nc--, hc--, i++)
239 if (needle[nc] != haystack[hc])
242 if (needle[nc] != haystack[hc]) {
243 n = skiptable[(int) haystack[hc]] - i;
254 public object Clone ()
256 // FIXME: implement me
260 public static int Compare (string strA, string strB)
264 /* Does this remind anyone of the nautilus string.h wrappers? ;-) */
270 } else if (strB == null)
273 for (i = 0; strA[i] == strB[i] && strA[i] != '\0'; i++);
275 return ((int) (strA[i] - strB[i]));
278 public static int Compare (string strA, string strB, bool ignoreCase)
283 return Compare (strA, strB);
286 * And here I thought Eazel developers were on crack...
287 * if a string is null it should pelt the programmer with
288 * ArgumentNullExceptions, damnit!
295 } else if (strB == null)
298 for (i = 0; strA[i] != '\0' && strB[i] != '\0'; i++) {
299 if (Char.ToLower (strA[i]) != Char.ToLower (strB[i]))
303 return ((int) (strA[i] - strB[i]));
306 public static int Compare (string strA, string strB, bool ignoreCase, CultureInfo culture)
308 // FIXME: implement me
312 public static int Compare (string strA, int indexA, string strB, int indexB, int length)
316 if (length < 0 || indexA < 0 || indexB < 0)
317 throw new ArgumentOutOfRangeException ();
319 if (indexA > strA.Length || indexB > strB.Length)
320 throw new ArgumentOutOfRangeException ();
322 /* And again with the ("" > null) logic... lord have mercy! */
328 } else if (strB == null)
331 for (i = 0; i < length - 1; i++) {
332 if (strA[indexA + i] != strB[indexB + i])
336 return ((int) (strA[indexA + i] - strB[indexB + i]));
339 public static int Compare (string strA, int indexA, string strB, int indexB,
340 int length, bool ignoreCase)
345 return Compare (strA, indexA, strB, indexB, length);
347 if (length < 0 || indexA < 0 || indexB < 0)
348 throw new ArgumentOutOfRangeException ();
350 if (indexA > strA.Length || indexB > strB.Length)
351 throw new ArgumentOutOfRangeException ();
353 /* When will the hurting stop!?!? */
359 } else if (strB == null)
362 for (i = 0; i < length - 1; i++) {
363 if (Char.ToLower (strA[indexA + i]) != Char.ToLower (strB[indexB + i]))
367 return ((int) (strA[indexA + i] - strB[indexB + i]));
370 public static int Compare (string strA, int indexA, string strB, int indexB,
371 int length, bool ignoreCase, CultureInfo culture)
374 throw new ArgumentNullException ();
376 if (length < 0 || indexA < 0 || indexB < 0)
377 throw new ArgumentOutOfRangeException ();
379 if (indexA > strA.Length || indexB > strB.Length)
380 throw new ArgumentOutOfRangeException ();
382 /* I can't take it anymore! */
388 } else if (strB == null)
390 // FIXME: implement me
394 public static int CompareOrdinal (string strA, string strB)
398 /* Please God, make it stop! */
404 } else if (strB == null)
407 for (i = 0; strA[i] != '\0'; i++) {
410 cA = tolowerordinal (strA[i]);
411 cB = tolowerordinal (strB[i]);
417 return ((int) (strA[i] - strB[i]));
420 public static int CompareOrdinal (string strA, int indexA, string strB, int indexB,
425 if (length < 0 || indexA < 0 || indexB < 0)
426 throw new ArgumentOutOfRangeException ();
434 } else if (strB == null)
437 for (i = 0; i < length; i++) {
440 cA = tolowerordinal (strA[indexA + i]);
441 cB = tolowerordinal (strB[indexB + i]);
447 return ((int) (strA[indexA + i] - strB[indexB + i]));
450 public int CompareTo (object obj)
452 return Compare (this, obj == null ? null : obj.ToString ());
455 public int CompareTo (string str)
457 return Compare (this, str);
460 public static string Concat (object arg)
462 return arg != null ? arg.ToString () : String.Empty;
465 public static string Concat (params object[] args)
472 throw new ArgumentNullException ();
474 strings = new string [args.Length];
477 foreach (object arg in args) {
478 /* use Empty for each null argument */
480 strings[i] = String.Empty;
482 strings[i] = arg.ToString ();
483 len += strings[i].Length;
490 str = new char [len + 1];
492 for (int j = 0; j < strings.Length; j++)
493 for (int k = 0; k < strings[j].Length; k++)
494 str[i++] = strings[j][k];
497 return new String (str);
500 public static string Concat (params string[] values)
506 throw new ArgumentNullException ();
509 foreach (string value in values)
510 len += value != null ? value.Length : 0;
515 str = new char [len + 1];
517 foreach (string value in values) {
521 for (int j = 0; j < value.Length; j++)
526 return new String (str);
529 public static string Concat (object arg0, object arg1)
531 string str0 = arg0 != null ? arg0.ToString () : String.Empty;
532 string str1 = arg1 != null ? arg1.ToString () : String.Empty;
534 return Concat (str0, str1);
537 public static string Concat (string str0, string str1)
547 len = str0.Length + str1.Length;
551 concat = new char [len + 1];
552 for (i = 0; i < str0.Length; i++)
554 for (j = 0 ; j < str1.Length; j++)
555 concat[i + j] = str1[j];
558 return new String (concat);
561 public static string Concat (object arg0, object arg1, object arg2)
563 string str0 = arg0 != null ? arg0.ToString () : String.Empty;
564 string str1 = arg1 != null ? arg1.ToString () : String.Empty;
565 string str2 = arg2 != null ? arg2.ToString () : String.Empty;
567 return Concat (str0, str1, str2);
570 public static string Concat (string str0, string str1, string str2)
582 len = str0.Length + str1.Length + str2.Length;
586 concat = new char [len + 1];
587 for (i = 0; i < str0.Length; i++)
589 for (j = 0; j < str1.Length; j++)
590 concat[i + j] = str1[j];
591 for (k = 0; k < str2.Length; k++)
592 concat[i + j + k] = str2[k];
595 return new String (concat);
598 public static string Concat (string str0, string str1, string str2, string str3)
612 len = str0.Length + str1.Length + str2.Length + str3.Length;
616 concat = new char [len + 1];
617 for (i = 0; i < str0.Length; i++)
619 for (j = 0; j < str1.Length; j++)
620 concat[i + j] = str1[j];
621 for (k = 0; k < str2.Length; k++)
622 concat[i + j + k] = str2[k];
623 for (l = 0; l < str3.Length; l++)
624 concat[i + j + k + l] = str3[l];
627 return new String (concat);
630 public static string Copy (string str)
632 // FIXME: how do I *copy* a string if I can only have 1 of each?
634 throw new ArgumentNullException ();
639 public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count)
641 // LAMESPEC: should I null-terminate?
644 if (destination == null)
645 throw new ArgumentNullException ();
647 if (sourceIndex < 0 || destinationIndex < 0 || count < 0)
648 throw new ArgumentOutOfRangeException ();
650 if (sourceIndex + count > this.length)
651 throw new ArgumentOutOfRangeException ();
653 if (destinationIndex + count > destination.Length)
654 throw new ArgumentOutOfRangeException ();
656 for (i = 0; i < count; i++)
657 destination[destinationIndex + i] = this.c_str[sourceIndex + i];
660 public bool EndsWith (string value)
662 bool endswith = true;
666 throw new ArgumentNullException ();
668 start = this.length - value.Length;
672 for (i = start; i < this.length && endswith; i++)
673 endswith = this.c_str[i] == value[i - start];
678 public override bool Equals (object obj)
680 if (!(obj is String))
683 return this == (String) obj;
686 public bool Equals (string value)
688 return this == value;
691 public static bool Equals (string a, string b)
696 public static string Format (string format, object arg0)
698 // FIXME: implement me
702 public static string Format (string format, params object[] args)
704 // FIXME: implement me
708 public static string Format (IFormatProvider provider, string format, params object[] args)
710 // FIXME: implement me
714 public static string Format (string format, object arg0, object arg1)
716 // FIXME: implement me
720 public static string Format (string format, object arg0, object arg1, object arg2)
722 // FIXME: implement me
726 //public CharEnumerator GetEnumerator ()
727 public IEnumerator GetEnumerator ()
729 // FIXME: implement me
733 public override int GetHashCode ()
735 // FIXME: implement me
739 public new Type GetType ()
741 // FIXME: implement me
745 public TypeCode GetTypeCode ()
747 // FIXME: implement me
751 public int IndexOf (char value)
753 return IndexOf (value, 0, this.length);
756 public int IndexOf (string value)
758 return IndexOf (value, 0, this.length);
761 public int IndexOf (char value, int startIndex)
763 return IndexOf (value, startIndex, this.length - startIndex);
766 public int IndexOf (string value, int startIndex)
768 return IndexOf (value, startIndex, this.length - startIndex);
771 public int IndexOf (char value, int startIndex, int count)
775 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
776 throw new ArgumentOutOfRangeException ();
778 for (i = startIndex; i - startIndex < count; i++)
779 if (this.c_str[i] == value)
785 public int IndexOf (string value, int startIndex, int count)
788 throw new ArgumentNullException ();
790 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
791 throw new ArgumentOutOfRangeException ();
793 return BoyerMoore (this.c_str, value, startIndex, count);
796 for (i = startIndex; i - startIndex + value.Length <= count; ) {
797 if (this.c_str[i] == value[0]) {
801 for (j = 1; equal && value[j] != '\0'; j++) {
802 equal = this.c_str[i + j] == value[j];
803 if (this.c_str[i + j] == value[0] && nexti == 0)
822 public int IndexOfAny (char[] values)
824 return IndexOfAny (values, 0, this.length);
827 public int IndexOfAny (char[] values, int startIndex)
829 return IndexOfAny (values, startIndex, this.length - startIndex);
832 public int IndexOfAny (char[] values, int startIndex, int count)
835 throw new ArgumentNullException ();
837 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
838 throw new ArgumentOutOfRangeException ();
840 for (int i = startIndex; i < startIndex + count; i++) {
841 for (int j = 0; j < strlen (values); j++) {
842 if (this.c_str[i] == values[j])
850 public string Insert (int startIndex, string value)
856 throw new ArgumentNullException ();
858 if (startIndex < 0 || startIndex > this.length)
859 throw new ArgumentOutOfRangeException ();
861 str = new char [value.Length + this.length + 1];
862 for (i = 0; i < startIndex; i++)
863 str[i] = this.c_str[i];
864 for (j = 0; j < value.Length; j++)
865 str[i + j] = value[j];
866 for ( ; i < this.length; i++)
867 str[i + j] = this.c_str[i];
870 return new String (str);
873 [MethodImplAttribute(MethodImplOptions.InternalCall)]
874 public extern static string Intern (string str);
876 [MethodImplAttribute(MethodImplOptions.InternalCall)]
877 public extern static string IsInterned (string str);
879 public static string Join (string separator, string[] value)
881 return Join (separator, value, 0, value.Length);
884 public static string Join (string separator, string[] value, int startIndex, int count)
886 // LAMESPEC: msdn doesn't specify what happens when separator is null
890 if (separator == null || value == null)
891 throw new ArgumentNullException ();
893 if (startIndex + count > value.Length)
894 throw new ArgumentOutOfRangeException ();
897 for (i = startIndex, used = 0; used < count; i++, used++) {
899 len += separator.Length;
901 len += value[i].Length;
904 // We have no elements to join?
908 str = new char [len + 1];
909 for (i = 0; i < value[startIndex].Length; i++)
910 str[i] = value[startIndex][i];
913 for (j = startIndex + 1; used < count; j++, used++) {
916 for (k = 0; k < separator.Length; k++)
917 str[i++] = separator[k];
918 for (k = 0; k < value[j].Length; k++)
919 str[i++] = value[j][k];
923 return new String (str);
926 public int LastIndexOf (char value)
931 for (; i >= 0; i--) {
932 if (this.c_str[i] == value)
939 public int LastIndexOf (string value)
941 return LastIndexOf (value, this.length, this.length);
944 public int LastIndexOf (char value, int startIndex)
946 if (startIndex < 0 || startIndex > this.length)
947 throw new ArgumentOutOfRangeException ();
949 for (int i = startIndex; i >= 0; i--) {
950 if (this.c_str[i] == value)
957 public int LastIndexOf (string value, int startIndex)
959 return LastIndexOf (value, startIndex, this.length);
962 public int LastIndexOf (char value, int startIndex, int count)
964 if (startIndex < 0 || count < 0)
965 throw new ArgumentOutOfRangeException ();
967 if (startIndex > this.length || startIndex - count < 0)
968 throw new ArgumentOutOfRangeException ();
970 for (int i = startIndex; i >= startIndex - count; i--) {
971 if (this.c_str[i] == value)
978 public int LastIndexOf (string value, int startIndex, int count)
980 // LAMESPEC: currently I'm using startIndex as the 0-position in the comparison,
981 // but maybe it's the end-position in MS's implementation?
982 // msdn is unclear on this point. I think this is correct though.
986 throw new ArgumentNullException ();
988 if (startIndex < 0 || startIndex > this.length)
989 throw new ArgumentOutOfRangeException ();
991 if (count < 0 || startIndex - count < 0)
992 throw new ArgumentOutOfRangeException ();
994 if (value == String.Empty)
997 if (startIndex + value.Length > this.length) {
998 /* just a little optimization */
1001 start = this.length - value.Length;
1002 count -= startIndex - start;
1006 // FIXME: use a reversed-unicode-safe-Boyer-Moore?
1007 len = value.Length - 1;
1008 for (i = startIndex; i >= startIndex - count; i--) {
1009 if (this.c_str[i + len] == value[len]) {
1013 for (j = len - 1; equal && j >= 0; j--)
1014 equal = this.c_str[i + j] == value[j];
1024 public int LastIndexOfAny (char[] values)
1026 return LastIndexOfAny (values, this.length, this.length);
1029 public int LastIndexOfAny (char[] values, int startIndex)
1031 return LastIndexOfAny (values, startIndex, startIndex);
1034 public int LastIndexOfAny (char[] values, int startIndex, int count)
1039 throw new ArgumentNullException ();
1041 if (startIndex < 0 || count < 0 || startIndex - count < 0)
1042 throw new ArgumentOutOfRangeException ();
1044 for (i = startIndex; i >= startIndex - count; i--) {
1045 for (int j = 0; j < strlen (values); j++) {
1046 if (this.c_str[i] == values[j])
1054 public string PadLeft (int totalWidth)
1056 return PadLeft (totalWidth, ' ');
1059 public string PadLeft (int totalWidth, char padChar)
1065 throw new ArgumentException ();
1067 str = new char [totalWidth > this.length ? totalWidth : this.length + 1];
1068 for (i = 0; i < totalWidth - this.length; i++)
1071 for (j = 0; j < this.length; i++, j++)
1072 str[i] = this.c_str[j];
1076 return new String (str);
1079 public string PadRight (int totalWidth)
1081 return PadRight (totalWidth, ' ');
1084 public string PadRight (int totalWidth, char padChar)
1090 throw new ArgumentException ();
1092 str = new char [totalWidth > this.length ? totalWidth : this.length + 1];
1093 for (i = 0; i < this.length; i++)
1094 str[i] = this.c_str[i];
1096 for ( ; i < str.Length; i++)
1101 return new String (str);
1104 public string Remove (int startIndex, int count)
1109 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
1110 throw new ArgumentOutOfRangeException ();
1112 len = this.length - count;
1114 return String.Empty;
1116 str = new char [len + 1];
1117 for (i = 0; i < startIndex; i++)
1118 str[i] = this.c_str[i];
1119 for (j = i + count; j < this.length; j++)
1120 str[i++] = this.c_str[j];
1123 return new String (str);
1126 public string Replace (char oldChar, char newChar)
1131 str = new char [this.length + 1];
1132 for (i = 0; i < this.length; i++) {
1133 if (this.c_str[i] == oldChar)
1136 str[i] = this.c_str[i];
1140 return new String (str);
1143 public string Replace (string oldValue, string newValue)
1145 // LAMESPEC: msdn doesn't specify what to do if either args is null
1146 int index, len, i, j;
1149 if (oldValue == null || newValue == null)
1150 throw new ArgumentNullException ();
1152 // Use IndexOf in case I later rewrite it to use Boyer-Moore
1153 index = IndexOf (oldValue, 0);
1155 // This is the easy one ;-)
1156 return Substring (0, this.length);
1159 len = this.length - oldValue.Length + newValue.Length;
1161 return String.Empty;
1163 str = new char [len + 1];
1164 for (i = 0; i < index; i++)
1165 str[i] = this.c_str[i];
1166 for (j = 0; j < newValue.Length; j++)
1167 str[i++] = newValue[j];
1168 for (j = index + oldValue.Length; j < this.length; j++)
1169 str[i++] = this.c_str[j];
1172 return new String (str);
1175 private int splitme (char[] separators, int startIndex)
1177 /* this is basically a customized IndexOfAny() for the Split() methods */
1178 for (int i = startIndex; i < this.length; i++) {
1179 if (separators != null) {
1180 foreach (char sep in separators) {
1181 if (this.c_str[i] == sep)
1182 return i - startIndex;
1184 } else if (is_lwsp (this.c_str[i])) {
1185 return i - startIndex;
1192 public string[] Split (params char[] separator)
1196 * @separator: delimiting chars or null to split on whtspc
1198 * Returns: 1. An array consisting of a single
1199 * element (@this) if none of the delimiting
1200 * chars appear in @this. 2. An array of
1201 * substrings which are delimited by one of
1202 * the separator chars. 3. An array of
1203 * substrings separated by whitespace if
1204 * @separator is null. The Empty string should
1205 * be returned wherever 2 delimiting chars are
1208 // FIXME: would using a Queue be better?
1213 list = new ArrayList ();
1214 for (index = 0, len = 0; index < this.length; index += len + 1) {
1215 len = splitme (separator, index);
1216 len = len > -1 ? len : this.length - index;
1218 list.Add (String.Empty);
1223 str = new char [len + 1];
1224 for (i = 0; i < len; i++)
1225 str[i] = this.c_str[index + i];
1228 list.Add (new String (str));
1232 strings = new string [list.Count];
1233 if (list.Count == 1) {
1234 /* special case for an array holding @this */
1237 for (index = 0; index < list.Count; index++)
1238 strings[index] = (string) list[index];
1244 public string[] Split (char[] separator, int maxCount)
1246 // FIXME: what to do if maxCount <= 0?
1247 // FIXME: would using Queue be better than ArrayList?
1250 int index, len, used;
1253 list = new ArrayList ();
1254 for (index = 0, len = 0; index < this.length && used < maxCount; index += len + 1) {
1255 len = splitme (separator, index);
1256 len = len > -1 ? len : this.length - index;
1258 list.Add (String.Empty);
1263 str = new char [len + 1];
1264 for (i = 0; i < len; i++)
1265 str[i] = this.c_str[index + i];
1268 list.Add (new String (str));
1273 /* fit the remaining chunk of the @this into it's own element */
1274 if (index != this.length) {
1278 str = new char [this.length - index + 1];
1279 for (i = index; i < this.length; i++)
1280 str[i - index] = this.c_str[i];
1281 str[i - index] = '\0';
1283 list.Add (new String (str));
1286 strings = new string [list.Count];
1287 if (list.Count == 1) {
1288 /* special case for an array holding @this */
1291 for (index = 0; index < list.Count; index++)
1292 strings[index] = (string) list[index];
1298 public bool StartsWith (string value)
1300 bool startswith = true;
1304 throw new ArgumentNullException ();
1306 if (value.Length > this.length)
1309 for (i = 0; i < value.Length && startswith; i++)
1310 startswith = startswith && value[i] == this.c_str[i];
1315 public string Substring (int startIndex)
1320 if (startIndex < 0 || startIndex > this.length)
1321 throw new ArgumentOutOfRangeException ();
1323 len = this.length - startIndex;
1325 return String.Empty;
1327 str = new char [len + 1];
1328 for (i = startIndex; i < this.length; i++)
1329 str[i - startIndex] = this.c_str[i];
1332 return new String (str);
1335 public string Substring (int startIndex, int length)
1340 if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1341 throw new ArgumentOutOfRangeException ();
1344 return String.Empty;
1346 str = new char [length + 1];
1347 for (i = startIndex; i < startIndex + length; i++)
1348 str[i - startIndex] = this.c_str[i];
1351 return new String (str);
1354 public bool ToBoolean (IFormatProvider provider)
1356 // FIXME: implement me
1360 public byte ToByte (IFormatProvider provider)
1362 // FIXME: implement me
1366 public char ToChar (IFormatProvider provider)
1368 // FIXME: implement me
1372 public char[] ToCharArray ()
1374 return ToCharArray (0, this.length);
1377 public char[] ToCharArray (int startIndex, int length)
1382 if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1383 throw new ArgumentOutOfRangeException ();
1385 chars = new char [length + 1];
1386 for (i = startIndex; i < length; i++)
1387 chars[i - startIndex] = this.c_str[i];
1389 chars[length] = '\0';
1394 public DateTime ToDateTime (IFormatProvider provider)
1396 // FIXME: implement me
1398 return new DateTime (0);
1401 public decimal ToDecimal (IFormatProvider provider)
1403 // FIXME: implement me
1407 public double ToDouble (IFormatProvider provider)
1409 // FIXME: implement me
1413 public short ToInt16 (IFormatProvider provider)
1415 // FIXME: implement me
1419 public int ToInt32 (IFormatProvider provider)
1421 // FIXME: implement me
1425 public long ToInt64 (IFormatProvider provider)
1427 // FIXME: implement me
1431 public string ToLower ()
1436 str = new char [this.length + 1];
1437 for (i = 0; i < this.length; i++)
1438 str[i] = Char.ToLower (this.c_str[i]);
1441 return new String (str);
1444 public string ToLower (CultureInfo culture)
1446 // FIXME: implement me
1450 public sbyte ToSByte (IFormatProvider provider)
1452 // FIXME: implement me
1456 public float ToSingle (IFormatProvider provider)
1458 // FIXME: implement me
1462 public override string ToString ()
1464 return Substring (0, this.length);
1467 public string ToString (IFormatProvider format)
1469 // FIXME: implement me
1473 public object ToType (Type conversionType, IFormatProvider provider)
1475 // FIXME: implement me
1479 public ushort ToUInt16 (IFormatProvider provider)
1481 // FIXME: implement me
1485 public uint ToUInt32 (IFormatProvider provider)
1487 // FIXME: implement me
1491 public ulong ToUInt64 (IFormatProvider provider)
1493 // FIXME: implement me
1497 public string ToUpper ()
1502 str = new char [this.length + 1];
1503 for (i = 0; i < this.length; i++)
1504 str[i] = Char.ToUpper (this.c_str[i]);
1507 return new String (str);
1510 public string ToUpper (CultureInfo culture)
1512 // FIXME: implement me
1516 public string Trim ()
1521 public string Trim (params char[] trimChars)
1527 for (begin = 0; matches && begin < this.length; begin++) {
1528 if (trimChars != null) {
1530 foreach (char c in trimChars) {
1531 matches = this.c_str[begin] == c;
1536 matches = is_lwsp (this.c_str[begin]);
1541 for (end = this.length-1; end > begin; end--) {
1542 if (trimChars != null) {
1544 foreach (char c in trimChars) {
1545 matches = this.c_str[end] == c;
1550 matches = is_lwsp (this.c_str[end]);
1555 return String.Empty;
1557 return Substring (begin, end - begin);
1560 public string TrimEnd (params char[] trimChars)
1562 bool matches = true;
1565 for (end = this.length; end > 0; end--) {
1566 if (trimChars != null) {
1568 foreach (char c in trimChars) {
1569 matches = this.c_str[end] == c;
1574 matches = is_lwsp (this.c_str[end]);
1579 return String.Empty;
1581 return Substring (0, end);
1584 public string TrimStart (params char[] trimChars)
1586 bool matches = true;
1589 for (begin = 0; matches && begin < this.length; begin++) {
1590 if (trimChars != null) {
1592 foreach (char c in trimChars) {
1593 matches = this.c_str[begin] == c;
1598 matches = is_lwsp (this.c_str[begin]);
1602 if (begin == this.length)
1603 return String.Empty;
1605 return Substring (begin, this.length - begin);
1609 public static bool operator ==(string a, string b)
1611 if (a.length != b.length)
1615 for (int i = 0; i < l; i++)
1616 if (a.c_str [i] != b.c_str [i])
1622 public static bool operator !=(string a, string b)