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;
31 public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable {
32 public static readonly string Empty = "";
37 unsafe public String (char *value)
41 // FIXME: can I do value.Length here?
45 for (i = 0; *(value + i) != '\0'; i++);
49 this.c_str = new char [this.length + 1];
50 for (i = 0; i < this.length; i++)
51 this.c_str[i] = *(value + i);
55 public String (char[] value)
59 // FIXME: value.Length includes the terminating null char?
60 this.length = value != null ? strlen (value): 0;
61 this.c_str = new char [this.length + 1];
62 for (i = 0; i < this.length; i++)
63 this.c_str[i] = value[i];
67 unsafe public String (sbyte *value)
69 // FIXME: consider unicode?
72 // FIXME: can I do value.Length here? */
76 for (i = 0; *(value + i) != '\0'; i++);
80 this.c_str = new char [this.length + 1];
81 for (i = 0; i < this.length; i++)
82 this.c_str[i] = (char) *(value + i);
86 public String (char c, int count)
91 this.c_str = new char [count + 1];
92 for (i = 0; i < count; i++)
97 unsafe public String (char *value, int startIndex, int length)
101 if (value == null && startIndex != 0 && length != 0)
102 throw new ArgumentNullException ();
104 if (startIndex < 0 || length < 0)
105 throw new ArgumentOutOfRangeException ();
107 this.length = length;
108 this.c_str = new char [length + 1];
109 for (i = 0; i < length; i++)
110 this.c_str[i] = *(value + startIndex + i);
111 this.c_str[i] = '\0';
114 public String (char[] value, int startIndex, int length)
118 if (value == null && startIndex != 0 && length != 0)
119 throw new ArgumentNullException ();
121 if (startIndex < 0 || length < 0)
122 throw new ArgumentOutOfRangeException ();
124 this.length = length;
125 this.c_str = new char [length + 1];
126 for (i = 0; i < length; i++)
127 this.c_str[i] = value[startIndex + i];
128 this.c_str[i] = '\0';
131 unsafe public String (sbyte *value, int startIndex, int length)
133 // FIXME: consider unicode?
136 if (value == null && startIndex != 0 && length != 0)
137 throw new ArgumentNullException ();
139 if (startIndex < 0 || length < 0)
140 throw new ArgumentOutOfRangeException ();
142 this.length = length;
143 this.c_str = new char [length + 1];
144 for (i = 0; i < length; i++)
145 this.c_str[i] = (char) *(value + startIndex + i);
146 this.c_str[i] = '\0';
149 unsafe public String (sbyte *value, int startIndex, int length, Encoding enc)
151 // FIXME: implement me
156 // FIXME: is there anything we need to do here?
157 /*base.Finalize ();*/
167 // FIXME: is this correct syntax??
168 public char this [int index] {
170 if (index > this.length)
171 throw new ArgumentOutOfRangeException ();
173 return this.c_str[index];
177 // Private helper methods
178 private static int strlen (char[] str)
180 // FIXME: if str.Length includes terminating null char, then return (str.Length - 1)
184 private static char tolowerordinal (char c)
186 // FIXME: implement me
190 private static bool is_lwsp (char c)
192 /* this comes from the msdn docs for String.Trim() */
193 if ((c >= '\x9' && c <= '\xD') || c == '\x20' || c == '\xA0' ||
194 (c >= '\x2000' && c <= '\x200B') || c == '\x3000' || c == '\xFEFF')
200 unsafe private static int BoyerMoore (char[] haystack, char[] needle, int startIndex, int count)
202 /* (hopefully) Unicode-safe Boyer-Moore implementation */
203 uint[] skiptable = new uint[65536]; /* our unicode-safe skip-table */
205 char *ne_ptr; /* end-of-string pointers */
207 char *nc_ptr; /* compare pointers */
209 char *the_ptr; /* haystack pointers */
210 int h_len, n_len, n, i;
212 if (haystack == null || needle == null)
213 throw new ArgumentNullException ();
216 n_len = strlen (needle);
218 /* if the search buffer is shorter than the pattern buffer, we can't match */
222 /* return an instant match if the pattern is 0-length */
226 /* set a pointer at the end of each string */
227 ne_ptr = needle + n_len - 1; /* point to char before '\0' */
228 he_ptr = haystack + startIndex + count; /* point to last valid char */
230 /* init the skip table with the pattern length */
231 for (i = 0; i < 65536; i++)
232 skiptable[i] = n_len;
234 /* set the skip value for the chars that *do* appear in the
235 * pattern buffer (needle) to the distance from the index to
236 * the end of the pattern buffer. */
237 for (nc_ptr = needle; nc_ptr < ne_ptr; nc_ptr++)
238 skiptable[(uint) *nc_ptr] = ne_ptr - nc_ptr;
240 h_ptr = haystack + startIndex;
241 while (h_len >= n_len) {
242 the_ptr = h_ptr + n_len - 1; /* set the temp haystack end pointer */
243 hc_ptr = h_ptr + n_len - 1; /* set the haystack compare pointer */
244 nc_ptr = ne_ptr; /* set the needle compare pointer */
246 /* work our way backwards until they don't match */
247 for (i = 0; nc_ptr > needle; nc_ptr--, hc_ptr--, i++)
248 if (*nc_ptr != *hc_ptr)
251 if (*nc_ptr != *hc_ptr) {
252 n = skiptable[(uint) *hc_ptr] - i;
256 return h_ptr - haystack;
263 public object Clone ()
265 // FIXME: implement me
269 public static int Compare (string strA, string strB)
273 /* Does this remind anyone of the nautilus string.h wrappers? ;-) */
279 } else if (strB == null)
282 for (i = 0; strA[i] == strB[i] && strA[i] != '\0'; i++);
284 return ((int) (strA[i] - strB[i]));
287 public static int Compare (string strA, string strB, bool ignoreCase)
292 return Compare (strA, strB);
295 * And here I thought Eazel developers were on crack...
296 * if a string is null it should pelt the programmer with
297 * ArgumentNullExceptions, damnit!
304 } else if (strB == null)
307 for (i = 0; strA[i] != '\0' && strB[i] != '\0'; i++) {
308 if (Char.ToLower (strA[i]) != Char.ToLower (strB[i]))
312 return ((int) (strA[i] - strB[i]));
315 public static int Compare (string strA, string strB, bool ignoreCase, CultureInfo culture)
317 // FIXME: implement me
321 public static int Compare (string strA, int indexA, string strB, int indexB, int length)
325 if (length < 0 || indexA < 0 || indexB < 0)
326 throw new ArgumentOutOfRangeException ();
328 if (indexA > strA.Length || indexB > strB.Length)
329 throw new ArgumentOutOfRangeException ();
331 /* And again with the ("" > null) logic... lord have mercy! */
337 } else if (strB == null)
340 for (i = 0; i < length - 1; i++) {
341 if (strA[indexA + i] != strB[indexB + i])
345 return ((int) (strA[indexA + i] - strB[indexB + i]));
348 public static int Compare (string strA, int indexA, string strB, int indexB,
349 int length, bool ignoreCase)
354 return Compare (strA, indexA, strB, indexB, length);
356 if (length < 0 || indexA < 0 || indexB < 0)
357 throw new ArgumentOutOfRangeException ();
359 if (indexA > strA.Length || indexB > strB.Length)
360 throw new ArgumentOutOfRangeException ();
362 /* When will the hurting stop!?!? */
368 } else if (strB == null)
371 for (i = 0; i < length - 1; i++) {
372 if (Char.ToLower (strA[indexA + i]) != Char.ToLower (strB[indexB + i]))
376 return ((int) (strA[indexA + i] - strB[indexB + i]));
379 public static int Compare (string strA, int indexA, string strB, int indexB,
380 int length, bool ignoreCase, CultureInfo culture)
383 throw new ArgumentNullException ();
385 if (length < 0 || indexA < 0 || indexB < 0)
386 throw new ArgumentOutOfRangeException ();
388 if (indexA > strA.Length || indexB > strB.Length)
389 throw new ArgumentOutOfRangeException ();
391 /* I can't take it anymore! */
397 } else if (strB == null)
399 // FIXME: implement me
403 public static int CompareOrdinal (string strA, string strB)
407 /* Please God, make it stop! */
413 } else if (strB == null)
416 for (i = 0; strA[i] != '\0'; i++) {
419 cA = tolowerordinal (strA[i]);
420 cB = tolowerordinal (strB[i]);
426 return ((int) (strA[i] - strB[i]));
429 public static int CompareOrdinal (string strA, int indexA, string strB, int indexB,
434 if (length < 0 || indexA < 0 || indexB < 0)
435 throw new ArgumentOutOfRangeException ();
443 } else if (strB == null)
446 for (i = 0; i < length; i++) {
449 cA = tolowerordinal (strA[indexA + i]);
450 cB = tolowerordinal (strB[indexB + i]);
456 return ((int) (strA[indexA + i] - strB[indexB + i]));
459 public int CompareTo (object obj)
461 return Compare (this, obj == null ? null : obj.ToString ());
464 public int CompareTo (string str)
466 return Compare (this, str);
469 public static string Concat (object arg)
471 return Concat (this, arg ? arg.ToString () : String.Empty);
474 public static string Concat (params object[] args)
481 throw new ArgumentNullException ();
483 strings = new string [args.Length];
485 foreach (object arg in args) {
486 /* use Empty for each null argument */
488 strings[i] = String.Empty;
490 strings[i] = arg.ToString ();
491 len += strings[i].Length;
497 str = new string [len + 1];
499 for (int j = 0; j < strings.Length; j++)
500 for (int k = 0; k < strings[j].Length; k++)
501 str[i++] = strings[j][k];
507 public static string Concat (params string[] values)
513 throw new ArgumentNullException ();
516 foreach (string value in values)
517 len += value ? value.Length : 0;
522 str = new string [len + 1];
524 foreach (string value in values) {
528 for (int j = 0; j < value.Length; j++)
536 public static string Concat (object arg0, object arg1)
538 string str0 = arg0 ? arg0.ToString () : String.Empty;
539 string str1 = arg1 ? arg1.ToString () : String.Empty;
541 return Concat (str0, str1);
544 public static string Concat (string str0, string str1)
552 str1 == String.Empty;
554 len = str0.Length + str1.Length;
558 concat = new string [len + 1];
559 for (i = 0; i < str0.Length; i++)
561 for (j = 0 ; j < str1.Length; j++)
562 concat[i + j] = str1[j];
568 public static string Concat (object arg0, object arg1, object arg2)
570 string str0 = arg0 ? arg0.ToString () : String.Empty;
571 string str1 = arg1 ? arg1.ToString () : String.Empty;
572 string str2 = arg2 ? arg2.ToString () : String.Empty;
574 return Concat (str0, str1, str2);
577 public static string Concat (string str0, string str1, string str2)
589 len = str0.Length + str1.Length + str2.Length;
593 concat = new string [len + 1];
594 for (i = 0; i < str0.Length; i++)
596 for (j = 0; j < str1.Length; j++)
597 concat[i + j] = str1[j];
598 for (k = 0; k < str2.Length; k++)
599 concat[i + j + k] = str2[k];
605 public static string Concat (string str0, string str1, string str2, string str3)
619 len = str0.Length + str1.Length + str2.Length + str3.Length;
623 concat = new string [len + 1];
624 for (i = 0; i < str0.Length; i++)
626 for (j = 0; j < str1.Length; j++)
627 concat[i + j] = str1[j];
628 for (k = 0; k < str2.Length; k++)
629 concat[i + j + k] = str2[k];
630 for (l = 0; l < str3.Length; l++)
631 concat[i + j + k + l] = str3[l];
637 public static string Copy (string str)
640 throw new ArgumentNullException ();
642 return new String (str);
645 public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count)
647 // LAMESPEC: should I null-terminate?
650 if (destination == null)
651 throw new ArgumentNullException ();
653 if (sourceIndex < 0 || destinationIndex < 0 || count < 0)
654 throw new ArgumentOutOfRangeException ();
656 if (sourceIndex + count > this.length)
657 throw new ArgumentOutOfRangeException ();
659 if (destinationIndex + count > destination.Length)
660 throw new ArgumentOutOfRangeException ();
662 for (i = 0; i < count; i++)
663 destination[destinationIndex + i] = this.c_str[sourceIndex + i];
666 public bool EndsWith (string value)
668 bool endswith = true;
672 throw new ArgumentNullException ();
674 start = this.length - value.Length;
678 for (i = start; i < this.length && endswith; i++)
679 endswith = this.c_str[i] == value[i - start];
684 public override bool Equals (object obj)
686 if (!(obj is String))
689 return this == (String) obj;
692 public bool Equals (string value)
694 return this == value;
697 public static bool Equals (string a, string b)
702 public static string Format (string format, object arg0)
704 // FIXME: implement me
708 public static string Format (string format, params object[] args)
710 // FIXME: implement me
714 public static string Format (IFormatProvider provider, string format, params object[] args)
716 // FIXME: implement me
720 public static string Format (string format, object arg0, object arg1)
722 // FIXME: implement me
726 public static string Format (string format, object arg0, object arg1, object arg2)
728 // FIXME: implement me
732 //public CharEnumerator GetEnumerator ()
733 public IEnumerator GetEnumerator ()
735 // FIXME: implement me
739 public override int GetHashCode ()
741 // FIXME: implement me
745 public new Type GetType ()
747 // FIXME: implement me
751 public TypeCode GetTypeCode ()
753 // FIXME: implement me
757 public int IndexOf (char value)
759 return IndexOf (value, 0, this.length);
762 public int IndexOf (string value)
764 return IndexOf (value, 0, this.length);
767 public int IndexOf (char value, int startIndex)
769 return IndexOf (value, startIndex, this.length - startIndex);
772 public int IndexOf (string value, int startIndex)
774 return IndexOf (value, startIndex, this.length - startIndex);
777 public int IndexOf (char value, int startIndex, int count)
781 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
782 throw new ArgumentOutOfRangeException ();
784 for (i = startIndex; i - startIndex < count; i++)
785 if (this.c_str[i] == value)
791 public int IndexOf (string value, int startIndex, int count)
793 // FIXME: Use a modified Boyer-Moore algorithm to work with unicode?
797 throw new ArgumentNullException ();
799 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
800 throw new ArgumentOutOfRangeException ();
802 for (i = startIndex; i - startIndex + value.Length <= count; ) {
803 if (this.c_str[i] == value[0]) {
807 for (j = 1; equal && value[j] != '\0'; j++) {
808 equal = this.c_str[i + j] == value[j];
809 if (this.c_str[i + j] == value[0] && nexti == 0)
827 public int IndexOfAny (char[] values)
829 return IndexOfAny (values, 0, this.length);
832 public int IndexOfAny (char[] values, int startIndex)
834 return IndexOfAny (values, startIndex, this.length - startIndex);
837 public int IndexOfAny (char[] values, int startIndex, int count)
840 throw new ArgumentNullException ();
842 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
843 throw new ArgumentOutOfRangeException ();
845 for (int i = startIndex; i < startIndex + count; i++) {
846 for (int j = 0; j < strlen (values); j++) {
847 if (this.c_str[i] == values[j])
855 public string Insert (int startIndex, string value)
861 throw new ArgumentNullException ();
863 if (startIndex < 0 || startIndex > this.length)
864 throw new ArgumentOutOfRangeException ();
866 str = new string [value.Length + this.length + 1];
867 for (i = 0; i < startIndex; i++)
868 str[i] = this.c_str[i];
869 for (j = 0; j < value.Length; j++)
870 str[i + j] = value[j];
871 for ( ; i < this.length; i++)
872 str[i + j] = this.c_str[i];
878 public static string Intern (string str)
881 throw new ArgumentNullException ();
882 // FIXME: implement me
886 public static string IsInterned (string str)
889 throw new ArgumentNullException ();
890 // FIXME: implement me
894 public static string Join (string separator, string[] value)
896 return Join (separator, value, 0, value.Length);
899 public static string Join (string separator, string[] value, int startIndex, int count)
901 // LAMESPEC: msdn doesn't specify what happens when separator is null
905 if (separator == null || value == null)
906 throw new ArgumentNullException ();
908 if (startIndex + count > value.Length)
909 throw new ArgumentOutOfRangeException ();
912 for (i = startIndex, used = 0; used < count; i++, used++) {
914 len += separator.Length;
916 len += value[i].Length;
919 // We have no elements to join?
923 str = new string [len + 1];
924 for (i = 0; i < value[startIndex].Length; i++)
925 str[i] = value[startIndex][i];
928 for (j = startIndex + 1; used < count; j++, used++) {
931 for (k = 0; k < separator.Length; k++)
932 str[i++] = separator[k];
933 for (k = 0; k < value[j].Length; k++)
934 str[i++] = value[j][k];
941 public int LastIndexOf (char value)
943 for (int i = this.length; i >= 0; i--) {
944 if (this.c_str[i] == value)
951 public int LastIndexOf (string value)
953 return LastIndexOf (value, this.length, this.length);
956 public int LastIndexOf (char value, int startIndex)
958 if (startIndex < 0 || startIndex > this.length)
959 throw new ArgumentOutOfRangeException ();
961 for (int i = startIndex; i >= 0; i--) {
962 if (this.c_str[i] == value)
969 public int LastIndexOf (string value, int startIndex)
971 return LastIndexOf (value, startIndex, this.length);
974 public int LastIndexOf (char value, int startIndex, int count)
976 if (startIndex < 0 || count < 0)
977 throw new ArgumentOutOfRangeException ();
979 if (startIndex > this.length || startIndex - count < 0)
980 throw new ArgumentOutOfRangeException ();
982 for (int i = startIndex; i >= startIndex - count; i--) {
983 if (this.c_str[i] == value)
990 public int LastIndexOf (string value, int startIndex, int count)
992 // LAMESPEC: currently I'm using startIndex as the 0-position in the comparison,
993 // but maybe it's the end-position in MS's implementation?
994 // msdn is unclear on this point. I think this is correct though.
998 throw new ArgumentNullException ();
1000 if (startIndex < 0 || startIndex > this.length)
1001 throw new ArgumentOutOfRangeException ();
1003 if (count < 0 || startIndex - count < 0)
1004 throw new ArgumentOutOfRangeException ();
1006 if (value == String.Empty)
1009 if (startIndex + value.Length > this.length) {
1010 /* just a little optimization */
1013 start = this.length - value.Length;
1014 count -= startIndex - start;
1018 // FIXME: use a reversed-unicode-safe-Boyer-Moore?
1019 len = value.Length - 1;
1020 for (i = startIndex; i >= startIndex - count; i--) {
1021 if (this.c_str[i + len] == value[len]) {
1025 for (j = len - 1; equal && j >= 0; j--)
1026 equal = this.c_str[i + j] == value[j];
1036 public int LastIndexOfAny (char[] values)
1038 return LastIndexOfAny (values, this.length, this.length);
1041 public int LastIndexOfAny (char[] values, int startIndex)
1043 return LastIndexOfAny (values, startIndex, startIndex);
1046 public int LastIndexOfAny (char[] values, int startIndex, int count)
1051 throw new ArgumentNullException ();
1053 if (startIndex < 0 || count < 0 || startIndex - count < 0)
1054 throw new ArgumentOutOfRangeException ();
1056 for (i = startIndex; i >= startIndex - count; i--) {
1057 for (int j = 0; j < strlen (values); j++) {
1058 if (this.c_str[i] == values[j])
1066 public string PadLeft (int totalWidth)
1068 return PadLeft (totalWidth, ' ');
1071 public string PadLeft (int totalWidth, char padChar)
1077 throw new ArgumentException ();
1079 str = new string [totalWidth > this.length ? totalWidth : this.length + 1];
1080 for (i = 0; i < totalWidth - this.length; i++)
1083 for (j = 0; j < this.length; i++, j++)
1084 str[i] = this.c_str[j];
1091 public string PadRight (int totalWidth)
1093 return PadRight (totalWidth, ' ');
1096 public string PadRight (int totalWidth, char padChar)
1102 throw new ArgumentException ();
1104 str = new string [totalWidth > this.length ? totalWidth : this.length + 1];
1105 for (i = 0; i < this.length; i++)
1106 str[i] = this.c_str[i];
1108 for ( ; j < str.Length; i++)
1116 public string Remove (int startIndex, int count)
1121 if (startIndex < 0 || count < 0 || startIndex + count > this.length)
1122 throw new ArgumentOutOfRangeException ();
1124 len = this.length - count;
1126 return String.Empty;
1128 str = new string [len + 1];
1129 for (i = 0; i < startIndex; i++)
1130 str[i] = this.c_str[i];
1131 for (j = i + count; j < this.length; j++)
1132 str[i++] = this.c_str[j];
1138 public string Replace (char oldChar, char newChar)
1143 str = new string [this.length + 1];
1144 for (i = 0; i < this.length; i++) {
1145 if (this.c_str[i] == oldChar)
1148 str[i] = this.c_str[i];
1155 public string Replace (string oldValue, string newValue)
1157 // LAMESPEC: msdn doesn't specify what to do if either args is null
1158 int index, len, i, j;
1161 if (oldValue == null || newValue == null)
1162 throw new ArgumentNullException ();
1164 // Use IndexOf in case I later rewrite it to use Boyer-Moore
1165 index = IndexOf (oldValue, 0);
1167 // This is the easy one ;-)
1168 return Substring (0, this.length);
1171 len = this.length - oldValue.Length + newValue.Length;
1173 return String.Empty;
1175 str = new string [len + 1];
1176 for (i = 0; i < index; i++)
1177 str[i] = this.c_str[i];
1178 for (j = 0; j < newValue.Length; j++)
1179 str[i++] = newValue[j];
1180 for (j = index + oldValue.Length; j < this.length; j++)
1181 str[i++] = this.c_str[j];
1187 private int splitme (char[] separators, int startIndex)
1189 /* this is basically a customized IndexOfAny() for the Split() methods */
1190 for (int i = startIndex; i < this.length; i++) {
1191 if (separators != null) {
1192 foreach (char sep in separators) {
1193 if (this.c_str[i] == sep)
1194 return i - startIndex;
1196 } else if (is_lwsp (this.c_str[i])) {
1197 return i - startIndex;
1204 public string[] Split (params char[] separator)
1208 * @separator: delimiting chars or null to split on whtspc
1210 * Returns: 1. An array consisting of a single
1211 * element (@this) if none of the delimiting
1212 * chars appear in @this. 2. An array of
1213 * substrings which are delimited by one of
1214 * the separator chars. 3. An array of
1215 * substrings separated by whitespace if
1216 * @separator is null. The Empty string should
1217 * be returned wherever 2 delimiting chars are
1220 // FIXME: would using a Queue be better?
1225 list = new ArrayList ();
1226 for (index = 0, len = 0; index < this.length; index += len + 1) {
1227 len = splitme (separator, index);
1228 len = len > -1 ? len : this.length - index;
1230 list.Add (String.Empty);
1235 str = new string [len + 1];
1236 for (i = 0; i < len; i++)
1237 str[i] = this.c_str[index + i];
1244 strings = new string [list.Count];
1245 if (list.Count == 1) {
1246 /* special case for an array holding @this */
1249 for (index = 0; index < list.Count; index++)
1250 strings[index] = (string) list[index];
1256 public string[] Split (char[] separator, int maxCount)
1258 // FIXME: what to do if maxCount <= 0?
1259 // FIXME: would using Queue be better than ArrayList?
1262 int index, len, used;
1265 list = new ArrayList ();
1266 for (index = 0, len = 0; index < this.length && used < maxCount; index += len + 1) {
1267 len = splitme (separator, index);
1268 len = len > -1 ? len : this.length - index;
1270 list.Add (String.Empty);
1275 str = new string [len + 1];
1276 for (i = 0; i < len; i++)
1277 str[i] = this.c_str[index + i];
1285 /* fit the remaining chunk of the @this into it's own element */
1286 if (index != this.length) {
1290 str = new string [this.length - index + 1];
1291 for (i = index; i < this.length; i++)
1292 str[i - index] = this.c_str[i];
1293 str[i - index] = '\0';
1298 strings = new string [list.Count];
1299 if (list.Count == 1) {
1300 /* special case for an array holding @this */
1303 for (index = 0; index < list.Count; index++)
1304 strings[index] = (string) list[index];
1310 public bool StartsWith (string value)
1312 bool startswith = true;
1316 throw new ArgumentNullException ();
1318 if (value.Length > this.length)
1321 for (i = 0; i < value.Length && startswith; i++)
1322 startswith = startswith && value[i] == this.c_str[i];
1327 public string Substring (int startIndex)
1332 if (startIndex < 0 || startIndex > this.length)
1333 throw new ArgumentOutOfRangeException ();
1335 len = this.length - startIndex;
1337 return String.Empty;
1339 str = new string [len + 1];
1340 for (i = startIndex; i < this.length; i++)
1341 str[i - startIndex] = this.c_str[i];
1347 public string Substring (int startIndex, int length)
1352 if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1353 throw new ArgumentOutOfRangeException ();
1356 return String.Empty;
1358 str = new string [length + 1];
1359 for (i = startIndex; i < startIndex + length; i++)
1360 str[i - startIndex] = this.c_str[i];
1366 public bool ToBoolean (IFormatProvider provider)
1368 // FIXME: implement me
1372 public byte ToByte (IFormatProvider provider)
1374 // FIXME: implement me
1378 public char ToChar (IFormatProvider provider)
1380 // FIXME: implement me
1384 public char[] ToCharArray ()
1386 return ToCharArray (0, this.length);
1389 public char[] ToCharArray (int startIndex, int length)
1394 if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1395 throw new ArgumentOutOfRangeException ();
1397 chars = new char [length + 1];
1398 for (i = startIndex, i < length; i++)
1399 chars[i - startIndex] = this.c_str[i];
1401 chars[length] = '\0';
1406 public DateTime ToDateTime (IFormatProvider provider)
1408 // FIXME: implement me
1412 public decimal ToDecimal (IFormatProvider provider)
1414 // FIXME: implement me
1418 public double ToDouble (IFormatProvider provider)
1420 // FIXME: implement me
1424 public short ToInt16 (IFormatProvider provider)
1426 // FIXME: implement me
1430 public int ToInt32 (IFormatProvider provider)
1432 // FIXME: implement me
1436 public long ToInt64 (IFormatProvider provider)
1438 // FIXME: implement me
1442 public string ToLower ()
1447 str = new string [this.length + 1];
1448 for (i = 0; i < this.length; i++)
1449 str[i] = tolower (this.c_str[i]);
1455 public string ToLower (CultureInfo culture)
1457 // FIXME: implement me
1461 public sbyte ToSByte (IFormatProvider provider)
1463 // FIXME: implement me
1467 public float ToSingle (IFormatProvider provider)
1469 // FIXME: implement me
1473 public override string ToString ()
1475 return Substring (0, this.length);
1478 public string ToString (IFormatProvider format)
1480 // FIXME: implement me
1484 public object ToType (Type conversionType, IFormatProvider provider)
1486 // FIXME: implement me
1490 public ushort ToUInt16 (IFormatProvider provider)
1492 // FIXME: implement me
1496 public uint ToUInt32 (IFormatProvider provider)
1498 // FIXME: implement me
1502 public ulong ToUInt64 (IFormatProvider provider)
1504 // FIXME: implement me
1508 public string ToUpper ()
1513 str = new string [this.length + 1];
1514 for (i = 0; i < this.length; i++)
1515 str[i] = toupper (this.c_str[i]);
1521 public string ToUpper (CultureInfo culture)
1523 // FIXME: implement me
1527 public string Trim ()
1532 public string Trim (params char[] trimChars)
1538 for (begin = 0; matches && begin < this.length; begin++) {
1539 if (trimChars != null) {
1541 foreach (char c in trimChars)
1542 matches = this.c_str[begin] == c;
1544 matches = is_lwsp (this.c_str[begin]);
1549 for (end = this.length; end > begin; end--) {
1550 if (trimChars != null) {
1552 foreach (char c in trimChars)
1553 matches = this.c_str[end] == c;
1555 matches = is_lwsp (this.c_str[end]);
1560 return String.Empty;
1562 return Substring (begin, end - begin);
1565 public string TrimEnd (params char[] trimChars)
1567 bool matches = true;
1570 for (end = this.length; end > 0; end--) {
1571 if (trimChars != null) {
1573 foreach (char c in trimChars)
1574 matches = this.c_str[end] == c;
1576 matches = is_lwsp (this.c_str[end]);
1581 return String.Empty;
1583 return Substring (0, end);
1586 public string TrimStart (params char[] trimChars)
1588 bool matches = true;
1591 for (begin = 0; matches && begin < this.length; begin++) {
1592 if (trimChars != null) {
1594 foreach (char c in trimChars)
1595 matches = this.c_str[begin] == c;
1597 matches = is_lwsp (this.c_str[begin]);
1601 if (begin == this.length)
1602 return String.Empty;
1604 return Substring (begin, this.length - begin);
1608 public static bool operator ==(string a, string b)
1613 public static bool operator !=(string a, string b)