bug fix in String::Compare
[mono.git] / mcs / class / corlib / System / String.cs
1 // -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 //
3 // System.String.cs
4 //
5 // Author:
6 //   Jeffrey Stedfast (fejj@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 //
10
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.
13
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 :-)
18
19 // FIXME: The ToLower(), ToUpper(), and Compare(..., bool ignoreCase) methods
20 //        need to be made unicode aware.
21
22 // FIXME: when you have a char carr[], does carr.Length include the terminating null char?
23
24 using System;
25 using System.Text;
26 using System.Collections;
27 using System.Globalization;
28 using System.Runtime.CompilerServices;
29
30 namespace System {
31
32         //[DefaultMemberName("Chars")]
33         public sealed class String : IComparable, ICloneable, IConvertible, IEnumerable {
34                 public static readonly string Empty = "";
35                 private char[] c_str;
36                 private int length;
37
38                 // Constructors
39
40                 internal String (int storage)
41                 {
42                         length = storage;
43                         c_str = new char [storage];
44                 }
45                 
46                 [CLSCompliant(false)]
47                 unsafe public String (char *value)
48                 {
49                         int i;
50
51                         // FIXME: can I do value.Length here?
52                         if (value == null) {
53                                 this.length = 0;
54                         } else {
55                                 for (i = 0; *(value + i) != '\0'; i++);
56                                 this.length = i;
57                         }
58
59                         this.c_str = new char [this.length + 1];
60                         for (i = 0; i < this.length; i++)
61                                 this.c_str[i] = *(value + i);
62                 }
63
64                 public String (char[] value)
65                 {
66                         int i;
67
68                         // FIXME: value.Length includes the terminating null char?
69                         this.length = value != null ? strlen (value): 0;
70                         this.c_str = new char [this.length + 1];
71                         for (i = 0; i < this.length; i++)
72                                 this.c_str[i] = value[i];
73                 }
74
75                 [CLSCompliant(false)]
76                 unsafe public String (sbyte *value)
77                 {
78                         // FIXME: consider unicode?
79                         int i;
80
81                         // FIXME: can I do value.Length here? */
82                         if (value == null) {
83                                 this.length = 0;
84                         } else {
85                                 for (i = 0; *(value + i) != '\0'; i++);
86                                 this.length = i;
87                         }
88
89                         this.c_str = new char [this.length + 1];
90                         for (i = 0; i < this.length; i++)
91                                 this.c_str[i] = (char) *(value + i);
92                 }
93
94                 public String (char c, int count)
95                 {
96                         int i;
97
98                         this.length = count;
99                         this.c_str = new char [count + 1];
100                         for (i = 0; i < count; i++)
101                                 this.c_str[i] = c;
102                 }
103
104                 [CLSCompliant(false)]
105                 unsafe public String (char *value, int startIndex, int length)
106                 {
107                         int i;
108
109                         if (value == null && startIndex != 0 && length != 0)
110                                 throw new ArgumentNullException ();
111
112                         if (startIndex < 0 || length < 0)
113                                 throw new ArgumentOutOfRangeException ();
114
115                         this.length = length;
116                         this.c_str = new char [length + 1];
117                         for (i = 0; i < length; i++)
118                                 this.c_str[i] = *(value + startIndex + i);
119                 }
120
121                 public String (char[] value, int startIndex, int length)
122                 {
123                         int i;
124
125                         if (value == null && startIndex != 0 && length != 0)
126                                 throw new ArgumentNullException ();
127
128                         if (startIndex < 0 || length < 0)
129                                 throw new ArgumentOutOfRangeException ();
130
131                         this.length = length;
132                         this.c_str = new char [length + 1];
133                         for (i = 0; i < length; i++)
134                                 this.c_str[i] = value[startIndex + i];
135                 }
136
137                 [CLSCompliant(false)]
138                 unsafe public String (sbyte *value, int startIndex, int length)
139                 {
140                         // FIXME: consider unicode?
141                         int i;
142
143                         if (value == null && startIndex != 0 && length != 0)
144                                 throw new ArgumentNullException ();
145
146                         if (startIndex < 0 || length < 0)
147                                 throw new ArgumentOutOfRangeException ();
148
149                         this.length = length;
150                         this.c_str = new char [length + 1];
151                         for (i = 0; i < length; i++)
152                                 this.c_str[i] = (char) *(value + startIndex + i);
153                 }
154
155                 [CLSCompliant(false)][MonoTODO]
156                 unsafe public String (sbyte *value, int startIndex, int length, Encoding enc)
157                 {
158                         // FIXME: implement me
159                 }
160
161                 ~String ()
162                 {
163                         // FIXME: is there anything we need to do here?
164                         /*base.Finalize ();*/
165                 }
166
167                 // Properties
168                 public int Length {
169                         get {
170                                 return this.length;
171                         }
172                 }
173
174                 [IndexerName("Chars")]
175                 public char this [int index] {
176                         get {
177                                 if (index >= this.length)
178                                         throw new ArgumentOutOfRangeException ();
179
180                                 return this.c_str[index];
181                         }
182                 }
183
184                 // Private helper methods
185                 private static int strlen (char[] str)
186                 {
187                         // FIXME: if str.Length includes terminating null char, then return (str.Length - 1)
188                         return str.Length;
189                 }
190
191                 [MonoTODO]
192                 private static char tolowerordinal (char c)
193                 {
194                         // FIXME: implement me
195                         return c;
196                 }
197
198                 private static bool is_lwsp (char c)
199                 {
200                         /* this comes from the msdn docs for String.Trim() */
201                         if ((c >= '\x9' && c <= '\xD') || c == '\x20' || c == '\xA0' ||
202                             (c >= '\x2000' && c <= '\x200B') || c == '\x3000' || c == '\xFEFF')
203                                 return true;
204                         else
205                                 return false;
206                 }
207
208                 private static int BoyerMoore (char[] haystack, string needle, int startIndex, int count)
209                 {
210                         /* (hopefully) Unicode-safe Boyer-Moore implementation */
211                         int[] skiptable = new int[65536];  /* our unicode-safe skip-table */
212                         int h, n, he, ne, hc, nc, i;
213
214                         if (haystack == null || needle == null)
215                                 throw new ArgumentNullException ();
216
217                         /* if the search buffer is shorter than the pattern buffer, we can't match */
218                         if (count < needle.length)
219                                 return -1;
220
221                         /* return an instant match if the pattern is 0-length */
222                         if (needle.length == 0)
223                                 return startIndex;
224
225                         /* set a pointer at the end of each string */
226                         ne = needle.length - 1;      /* position of char before '\0' */
227                         he = startIndex + count;     /* position of last valid char */
228
229                         /* init the skip table with the pattern length */
230                         nc = needle.length;
231                         for (i = 0; i < 65536; i++)
232                                 skiptable[i] = nc;
233
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 = 0; nc < ne; nc++)
238                                 skiptable[(int) needle[nc]] = ne - nc;
239
240                         h = startIndex;
241                         while (count >= needle.length) {
242                                 hc = h + needle.length - 1;  /* set the haystack compare pointer */
243                                 nc = ne;                     /* set the needle compare pointer */
244
245                                 /* work our way backwards until they don't match */
246                                 for (i = 0; nc > 0; nc--, hc--, i++)
247                                         if (needle[nc] != haystack[hc])
248                                                 break;
249
250                                 if (needle[nc] != haystack[hc]) {
251                                         n = skiptable[(int) haystack[hc]] - i;
252                                         h += n;
253                                         count -= n;
254                                 } else
255                                         return h;
256                         }
257
258                         return -1;
259                 }
260
261                 // Methods
262                 [MonoTODO]
263                 public object Clone ()
264                 {
265                         // FIXME: implement me
266                         return null;
267                 }
268
269                 public static int Compare (string strA, string strB)
270                 {
271                         int min, i;
272
273                         if (strA == null) {
274                                 if (strB == null)
275                                         return 0;
276                                 else
277                                         return -1;
278                         } else if (strB == null)
279                                 return 1;
280
281                         min = strA.length < strB.length ? strA.length : strB.length;
282
283                         for (i = 0; i < min; i++) {
284                                 if (strA.c_str[i] != strB.c_str[i]) {
285                                         return (int)strA.c_str[i] - (int)strB.c_str[i];
286                                 }
287                         }
288                         if (strA.length == strB.length) {
289                                 return 0;
290                         }
291                         if (strA.length > min) {
292                                 return 1;
293                         } else {
294                                 return -1;
295                         }
296                 }
297
298                 public static int Compare (string strA, string strB, bool ignoreCase)
299                 {
300                         int min, i;
301
302                         if (!ignoreCase)
303                                 return Compare (strA, strB);
304
305                         /*
306                          * And here I thought Eazel developers were on crack...
307                          * if a string is null it should pelt the programmer with
308                          * ArgumentNullExceptions, damnit!
309                          */
310                         if (strA == null) {
311                                 if (strB == null)
312                                         return 0;
313                                 else
314                                         return -1;
315                         } else if (strB == null)
316                                 return 1;
317
318                         min = strA.length < strB.length ? strA.length : strB.length;
319
320                         for (i = 0; i < min; i++) {
321                                 if (Char.ToLower (strA.c_str[i]) != Char.ToLower (strB.c_str[i])) {
322                                         return (int)strA.c_str[i] - (int)strB.c_str[i];
323                                 }
324                         }
325                         if (strA.length == strB.length) {
326                                 return 0;
327                         }
328                         if (strA.length > min) {
329                                 return 1;
330                         } else {
331                                 return -1;
332                         }
333                 }
334
335                 [MonoTODO]
336                 public static int Compare (string strA, string strB, bool ignoreCase, CultureInfo culture)
337                 {
338                         // FIXME: implement me
339                         return 0;
340                 }
341
342                 public static int Compare (string strA, int indexA, string strB, int indexB, int length)
343                 {
344                         int i;
345
346                         if (length < 0 || indexA < 0 || indexB < 0)
347                                 throw new ArgumentOutOfRangeException ();
348
349                         if (indexA > strA.Length || indexB > strB.Length)
350                                 throw new ArgumentOutOfRangeException ();
351
352                         /* And again with the ("" > null) logic... lord have mercy! */
353                         if (strA == null) {
354                                 if (strB == null)
355                                         return 0;
356                                 else
357                                         return -1;
358                         } else if (strB == null)
359                                 return 1;
360
361                         for (i = 0; i < length - 1; i++) {
362                                 if (strA[indexA + i] != strB[indexB + i])
363                                         break;
364                         }
365
366                         return ((int) (strA[indexA + i] - strB[indexB + i]));
367                 }
368
369                 public static int Compare (string strA, int indexA, string strB, int indexB,
370                                            int length, bool ignoreCase)
371                 {
372                         int i;
373
374                         if (!ignoreCase)
375                                 return Compare (strA, indexA, strB, indexB, length);
376
377                         if (length < 0 || indexA < 0 || indexB < 0)
378                                 throw new ArgumentOutOfRangeException ();
379
380                         if (indexA > strA.Length || indexB > strB.Length)
381                                 throw new ArgumentOutOfRangeException ();
382
383                         /* When will the hurting stop!?!? */
384                         if (strA == null) {
385                                 if (strB == null)
386                                         return 0;
387                                 else
388                                         return -1;
389                         } else if (strB == null)
390                                 return 1;
391
392                         for (i = 0; i < length - 1; i++) {
393                                 if (Char.ToLower (strA[indexA + i]) != Char.ToLower (strB[indexB + i]))
394                                         break;
395                         }
396
397                         return ((int) (strA[indexA + i] - strB[indexB + i]));
398                 }
399
400                 [MonoTODO]
401                 public static int Compare (string strA, int indexA, string strB, int indexB,
402                                            int length, bool ignoreCase, CultureInfo culture)
403                 {
404                         if (culture == null)
405                                 throw new ArgumentNullException ();
406
407                         if (length < 0 || indexA < 0 || indexB < 0)
408                                 throw new ArgumentOutOfRangeException ();
409
410                         if (indexA > strA.Length || indexB > strB.Length)
411                                 throw new ArgumentOutOfRangeException ();
412
413                         /* I can't take it anymore! */
414                         if (strA == null) {
415                                 if (strB == null)
416                                         return 0;
417                                 else
418                                         return -1;
419                         } else if (strB == null)
420                                 return 1;
421
422                         // FIXME: implement me
423                         return 0;
424                 }
425
426                 public static int CompareOrdinal (string strA, string strB)
427                 {
428                         int i;
429
430                         /* Please God, make it stop! */
431                         if (strA == null) {
432                                 if (strB == null)
433                                         return 0;
434                                 else
435                                         return -1;
436                         } else if (strB == null)
437                                 return 1;
438
439                         for (i = 0; i < strA.Length && i < strB.Length; i++) {
440                                 char cA, cB;
441
442                                 cA = tolowerordinal (strA[i]);
443                                 cB = tolowerordinal (strB[i]);
444
445                                 if (cA != cB)
446                                         break;
447                         }
448
449                         return ((int) (strA[i] - strB[i]));
450                 }
451
452                 public static int CompareOrdinal (string strA, int indexA, string strB, int indexB,
453                                                   int length)
454                 {
455                         int i;
456
457                         if (length < 0 || indexA < 0 || indexB < 0)
458                                 throw new ArgumentOutOfRangeException ();
459
460                         if (strA == null) {
461                                 if (strB == null)
462                                         return 0;
463                                 else
464                                         return -1;
465                         } else if (strB == null)
466                                 return 1;
467
468                         for (i = 0; i < length; i++) {
469                                 char cA, cB;
470
471                                 cA = tolowerordinal (strA[indexA + i]);
472                                 cB = tolowerordinal (strB[indexB + i]);
473
474                                 if (cA != cB)
475                                         break;
476                         }
477
478                         return ((int) (strA[indexA + i] - strB[indexB + i]));
479                 }
480
481                 public int CompareTo (object obj)
482                 {
483                         return Compare (this, obj == null ? null : obj.ToString ());
484                 }
485
486                 public int CompareTo (string str)
487                 {
488                         return Compare (this, str);
489                 }
490
491                 public static string Concat (object arg)
492                 {
493                         return arg != null ? arg.ToString () : String.Empty;
494                 }
495
496                 public static string Concat (params object[] args)
497                 {
498                         string[] strings;
499                         char[] str;
500                         int len, i;
501
502                         if (args == null)
503                                 throw new ArgumentNullException ();
504
505                         strings = new string [args.Length];
506                         len = 0;
507                         i = 0;
508                         foreach (object arg in args) {
509                                 /* use Empty for each null argument */
510                                 if (arg == null)
511                                         strings[i] = String.Empty;
512                                 else
513                                         strings[i] = arg.ToString ();
514                                 len += strings[i].length;
515                                 i++;
516                         }
517
518                         if (len == 0)
519                                 return String.Empty;
520
521                         String res = new String (len);
522                         str = res.c_str;
523                         i = 0;
524                         for (int j = 0; j < strings.Length; j++)
525                                 for (int k = 0; k < strings[j].length; k++)
526                                         str[i++] = strings[j].c_str[k];
527
528                         return res;
529                 }
530
531                 public static string Concat (params string[] values)
532                 {
533                         int len, i;
534                         char[] str;
535
536                         if (values == null)
537                                 throw new ArgumentNullException ();
538
539                         len = 0;
540                         foreach (string value in values)
541                                 len += value != null ? value.Length : 0;
542
543                         if (len == 0)
544                                 return String.Empty;
545
546                         String res = new String (len);
547                         str = res.c_str;
548                         i = 0;
549                         foreach (string value in values) {
550                                 if (value == null)
551                                         continue;
552
553                                 for (int j = 0; j < value.length; j++)
554                                         str[i++] = value.c_str[j];
555                         }
556
557                         return res;
558                 }
559
560                 public static string Concat (object arg0, object arg1)
561                 {
562                         string str0 = arg0 != null ? arg0.ToString () : String.Empty;
563                         string str1 = arg1 != null ? arg1.ToString () : String.Empty;
564
565                         return Concat (str0, str1);
566                 }
567
568                 public static string Concat (string str0, string str1)
569                 {
570                         char[] concat;
571                         int i, j, len;
572
573                         if (str0 == null)
574                                 str0 = String.Empty;
575                         if (str1 == null)
576                                 str1 = String.Empty;
577
578                         len = str0.length + str1.length;
579                         if (len == 0)
580                                 return String.Empty;
581
582                         String res = new String (len);
583
584                         concat = res.c_str;
585                         for (i = 0; i < str0.length; i++)
586                                 concat[i] = str0.c_str[i];
587                         for (j = 0 ; j < str1.length; j++)
588                                 concat[i + j] = str1.c_str[j];
589
590                         return res;
591                 }
592
593                 public static string Concat (object arg0, object arg1, object arg2)
594                 {
595                         string str0 = arg0 != null ? arg0.ToString () : String.Empty;
596                         string str1 = arg1 != null ? arg1.ToString () : String.Empty;
597                         string str2 = arg2 != null ? arg2.ToString () : String.Empty;
598
599                         return Concat (str0, str1, str2);
600                 }
601
602                 public static string Concat (string str0, string str1, string str2)
603                 {
604                         char[] concat;
605                         int i, j, k, len;
606
607                         if (str0 == null)
608                                 str0 = String.Empty;
609                         if (str1 == null)
610                                 str1 = String.Empty;
611                         if (str2 == null)
612                                 str2 = String.Empty;
613
614                         len = str0.length + str1.length + str2.length;
615                         if (len == 0)
616                                 return String.Empty;
617
618                         String res = new String (len);
619
620                         concat = res.c_str;
621                         for (i = 0; i < str0.length; i++)
622                                 concat[i] = str0.c_str[i];
623                         for (j = 0; j < str1.length; j++)
624                                 concat[i + j] = str1.c_str[j];
625                         for (k = 0; k < str2.length; k++)
626                                 concat[i + j + k] = str2.c_str[k];
627
628                         return res;
629                 }
630
631                 public static string Concat (string str0, string str1, string str2, string str3)
632                 {
633                         char[] concat;
634                         int i, j, k, l, len;
635
636                         if (str0 == null)
637                                 str0 = String.Empty;
638                         if (str1 == null)
639                                 str1 = String.Empty;
640                         if (str2 == null)
641                                 str2 = String.Empty;
642                         if (str3 == null)
643                                 str3 = String.Empty;
644
645                         len = str0.length + str1.length + str2.length + str3.length;
646                         if (len == 0)
647                                 return String.Empty;
648                         String res = new String (len);
649
650                         concat = res.c_str;
651                         for (i = 0; i < str0.length; i++)
652                                 concat[i] = str0.c_str[i];
653                         for (j = 0; j < str1.length; j++)
654                                 concat[i + j] = str1.c_str[j];
655                         for (k = 0; k < str2.length; k++)
656                                 concat[i + j + k] = str2.c_str[k];
657                         for (l = 0; l < str3.length; l++)
658                                 concat[i + j + k + l] = str3.c_str[l];
659
660                         return res;
661                 }
662
663                 public static string Copy (string str)
664                 {
665                         // FIXME: how do I *copy* a string if I can only have 1 of each?
666                         if (str == null)
667                                 throw new ArgumentNullException ();
668
669                         return str;
670                 }
671
672                 public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count)
673                 {
674                         // LAMESPEC: should I null-terminate?
675                         int i;
676
677                         if (destination == null)
678                                 throw new ArgumentNullException ();
679
680                         if (sourceIndex < 0 || destinationIndex < 0 || count < 0)
681                                 throw new ArgumentOutOfRangeException ();
682
683                         if (sourceIndex + count > this.length)
684                                 throw new ArgumentOutOfRangeException ();
685
686                         if (destinationIndex + count > destination.Length)
687                                 throw new ArgumentOutOfRangeException ();
688
689                         for (i = 0; i < count; i++)
690                                 destination[destinationIndex + i] = this.c_str[sourceIndex + i];
691                 }
692
693                 public bool EndsWith (string value)
694                 {
695                         bool endswith = true;
696                         int start, i;
697
698                         if (value == null)
699                                 throw new ArgumentNullException ();
700
701                         start = this.length - value.length;
702                         if (start < 0)
703                                 return false;
704
705                         for (i = start; i < this.length && endswith; i++)
706                                 endswith = this.c_str[i] == value.c_str[i - start];
707
708                         return endswith;
709                 }
710
711                 public override bool Equals (object obj)
712                 {
713                         if (!(obj is String))
714                                 return false;
715
716                         return this == (String) obj;
717                 }
718
719                 public bool Equals (string value)
720                 {
721                         return this == value;
722                 }
723
724                 public static bool Equals (string a, string b)
725                 {
726                         return a == b;
727                 }
728
729                 [MonoTODO]
730                 public static string Format (string format, object arg0)
731                 {
732                         // FIXME: implement me
733                         return format+arg0.ToString();
734                 }
735
736                 [MonoTODO]
737                 public static string Format (string format, params object[] args)
738                 {
739                         // FIXME: implement me
740                         Console.WriteLine (args[0].ToString());
741                         if (args.Length == 1)
742                                 return format+args[0].ToString();
743                         if (args.Length == 2)
744                                 return format+args[0].ToString()+args[1].ToString();
745                         if (args.Length == 3)
746                                 return format+args[0].ToString()+args[1].ToString()+args[2].ToString();
747                         if (args.Length == 4)
748                                 return format+args[0].ToString()+args[1].ToString()+args[2].ToString()+args[3].ToString();
749                         Console.WriteLine ("String.Format with args: "+args.Length.ToString());
750                         return format;
751                 }
752                 
753                 [MonoTODO]
754                 public static string Format (IFormatProvider provider, string format, params object[] args)
755                 {
756                         // FIXME: implement me
757                         return null;
758                 }
759                 
760                 [MonoTODO]
761                 public static string Format (string format, object arg0, object arg1)
762                 {
763                         // FIXME: implement me
764                         return format+arg0.ToString()+arg1.ToString();
765                 }
766
767                 [MonoTODO]
768                 public static string Format (string format, object arg0, object arg1, object arg2)
769                 {
770                         // FIXME: implement me
771                         return format+arg0.ToString()+arg1.ToString()+arg2.ToString();
772                 }
773
774                 public CharEnumerator GetEnumerator ()
775                 {
776                         return new CharEnumerator (this);
777                 }
778                 
779                 IEnumerator IEnumerable.GetEnumerator ()
780                 {
781                         return new CharEnumerator (this);
782                 }
783
784                 public override int GetHashCode ()
785                 {
786                         int h = 0;
787                         int i;
788                         for (i = 0; i < length; ++i)
789                                 h = (h << 5) - h + c_str [i];
790                         return h;
791                 }
792
793                 public TypeCode GetTypeCode ()
794                 {
795                         return TypeCode.String;
796                 }
797
798                 public int IndexOf (char value)
799                 {
800                         return IndexOf (value, 0, this.length);
801                 }
802
803                 public int IndexOf (string value)
804                 {
805                         return IndexOf (value, 0, this.length);
806                 }
807
808                 public int IndexOf (char value, int startIndex)
809                 {
810                         return IndexOf (value, startIndex, this.length - startIndex);
811                 }
812
813                 public int IndexOf (string value, int startIndex)
814                 {
815                         return IndexOf (value, startIndex, this.length - startIndex);
816                 }
817
818                 public int IndexOf (char value, int startIndex, int count)
819                 {
820                         int i;
821
822                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
823                                 throw new ArgumentOutOfRangeException ();
824
825                         for (i = startIndex; i - startIndex < count; i++)
826                                 if (this.c_str[i] == value)
827                                         return i;
828
829                         return -1;
830                 }
831
832                 public int IndexOf (string value, int startIndex, int count)
833                 {
834                         if (value == null)
835                                 throw new ArgumentNullException ();
836
837                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
838                                 throw new ArgumentOutOfRangeException ();
839
840                         return BoyerMoore (this.c_str, value, startIndex, count);
841 #if XXX
842                         int i;
843                         for (i = startIndex; i - startIndex + value.Length <= count; ) {
844                                 if (this.c_str[i] == value[0]) {
845                                         bool equal = true;
846                                         int j, nexti = 0;
847
848                                         for (j = 1; equal && j < value.Length; j++) {
849                                                 equal = this.c_str[i + j] == value[j];
850                                                 if (this.c_str[i + j] == value[0] && nexti == 0)
851                                                         nexti = i + j;
852                                         }
853
854                                         if (equal)
855                                                 return i;
856
857                                         if (nexti != 0)
858                                                 i = nexti;
859                                         else
860                                                 i += j;
861                                 } else
862                                         i++;
863                         }
864
865                         return -1;
866 #endif
867                 }
868
869                 public int IndexOfAny (char[] values)
870                 {
871                         return IndexOfAny (values, 0, this.length);
872                 }
873
874                 public int IndexOfAny (char[] values, int startIndex)
875                 {
876                         return IndexOfAny (values, startIndex, this.length - startIndex);
877                 }
878
879                 public int IndexOfAny (char[] values, int startIndex, int count)
880                 {
881                         if (values == null)
882                                 throw new ArgumentNullException ();
883
884                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
885                                 throw new ArgumentOutOfRangeException ();
886
887                         for (int i = startIndex; i < startIndex + count; i++) {
888                                 for (int j = 0; j < strlen (values); j++) {
889                                         if (this.c_str[i] == values[j])
890                                                 return i;
891                                 }
892                         }
893
894                         return -1;
895                 }
896
897                 public string Insert (int startIndex, string value)
898                 {
899                         char[] str;
900                         int i, j;
901
902                         if (value == null)
903                                 throw new ArgumentNullException ();
904
905                         if (startIndex < 0 || startIndex > this.length)
906                                 throw new ArgumentOutOfRangeException ();
907
908                         String res = new String (value.length + this.length);
909
910                         str = res.c_str;
911                         for (i = 0; i < startIndex; i++)
912                                 str[i] = this.c_str[i];
913                         for (j = 0; j < value.length; j++)
914                                 str[i + j] = value.c_str[j];
915                         for ( ; i < this.length; i++)
916                                 str[i + j] = this.c_str[i];
917
918                         return res;
919                 }
920
921                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
922                 public extern static string Intern (string str);
923
924                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
925                 public extern static string IsInterned (string str);
926
927                 public static string Join (string separator, string[] value)
928                 {
929                         return Join (separator, value, 0, value.Length);
930                 }
931
932                 public static string Join (string separator, string[] value, int startIndex, int count)
933                 {
934                         // LAMESPEC: msdn doesn't specify what happens when separator is null
935                         int len, i, j, used;
936                         char[] str;
937
938                         if (separator == null || value == null)
939                                 throw new ArgumentNullException ();
940
941                         if (startIndex + count > value.Length)
942                                 throw new ArgumentOutOfRangeException ();
943
944                         len = 0;
945                         for (i = startIndex, used = 0; used < count; i++, used++) {
946                                 if (i != startIndex)
947                                         len += separator.length;
948
949                                 len += value[i].length;
950                         }
951
952                         // We have no elements to join?
953                         if (i == startIndex)
954                                 return String.Empty;
955
956                         String res = new String (len);
957
958                         str = res.c_str;
959                         for (i = 0; i < value[startIndex].length; i++)
960                                 str[i] = value[startIndex][i];
961
962                         used = 1;
963                         for (j = startIndex + 1; used < count; j++, used++) {
964                                 int k;
965
966                                 for (k = 0; k < separator.length; k++)
967                                         str[i++] = separator.c_str[k];
968                                 for (k = 0; k < value[j].length; k++)
969                                         str[i++] = value[j].c_str[k];
970                         }
971
972                         return res;
973                 }
974
975                 public int LastIndexOf (char value)
976                 {
977                         int i = this.length;
978                         if (i == 0)
979                                 return -1;
980                         --i;
981                         for (; i >= 0; i--) {
982                                 if (this.c_str[i] == value)
983                                         return i;
984                         }
985
986                         return -1;
987                 }
988
989                 public int LastIndexOf (string value)
990                 {
991                         return LastIndexOf (value, this.length - 1, this.length);
992                 }
993
994                 public int LastIndexOf (char value, int startIndex)
995                 {
996                         if (startIndex < 0 || startIndex >= this.length)
997                                 throw new ArgumentOutOfRangeException ();
998
999                         for (int i = startIndex; i >= 0; i--) {
1000                                 if (this.c_str[i] == value)
1001                                         return i;
1002                         }
1003
1004                         return -1;
1005                 }
1006
1007                 public int LastIndexOf (string value, int startIndex)
1008                 {
1009                         return LastIndexOf (value, startIndex, startIndex + 1);
1010                 }
1011
1012                 public int LastIndexOf (char value, int startIndex, int count)
1013                 {
1014                         if (startIndex < 0 || count < 0)
1015                                 throw new ArgumentOutOfRangeException ();
1016
1017                         if (startIndex >= this.length || startIndex - count + 1 < 0)
1018                                 throw new ArgumentOutOfRangeException ();
1019
1020                         for (int i = startIndex; i > startIndex - count; i--) {
1021                                 if (this.c_str[i] == value)
1022                                         return i;
1023                         }
1024
1025                         return -1;
1026                 }
1027
1028                 public int LastIndexOf (string value, int startIndex, int count)
1029                 {
1030                         // LAMESPEC: currently I'm using startIndex as the 0-position in the comparison,
1031                         //           but maybe it's the end-position in MS's implementation?
1032                         //           msdn is unclear on this point. I think this is correct though.
1033                         int i, len;
1034
1035                         if (value == null)
1036                                 throw new ArgumentNullException ();
1037
1038                         if (startIndex < 0 || startIndex >= this.length)
1039                                 throw new ArgumentOutOfRangeException ();
1040
1041                         if (count < 0 || startIndex - count + 1 < 0)
1042                                 throw new ArgumentOutOfRangeException ();
1043
1044                         if (value == String.Empty)
1045                                 return startIndex;
1046
1047                         if (startIndex + value.length > this.length) {
1048                                 /* just a little optimization */
1049                                 int start;
1050
1051                                 start = this.length - value.length;
1052                                 count -= startIndex - start;
1053                                 startIndex = start;
1054                         }
1055
1056                         // FIXME: use a reversed-unicode-safe-Boyer-Moore?
1057                         len = value.length - 1;
1058                         for (i = startIndex; i > startIndex - count; i--) {
1059                                 if (this.c_str[i + len] == value.c_str[len]) {
1060                                         bool equal = true;
1061                                         int j;
1062
1063                                         for (j = len - 1; equal && j >= 0; j--)
1064                                                 equal = this.c_str[i + j] == value.c_str[j];
1065
1066                                         if (equal)
1067                                                 return i;
1068                                 }
1069                         }
1070
1071                         return -1;
1072                 }
1073
1074                 public int LastIndexOfAny (char[] values)
1075                 {
1076                         return LastIndexOfAny (values, this.length - 1, this.length);
1077                 }
1078
1079                 public int LastIndexOfAny (char[] values, int startIndex)
1080                 {
1081                         return LastIndexOfAny (values, startIndex, startIndex + 1);
1082                 }
1083
1084                 public int LastIndexOfAny (char[] values, int startIndex, int count)
1085                 {
1086                         int i;
1087
1088                         if (values == null)
1089                                 throw new ArgumentNullException ();
1090
1091                         if (startIndex < 0 || count < 0 || startIndex - count + 1 < 0)
1092                                 throw new ArgumentOutOfRangeException ();
1093
1094                         for (i = startIndex; i > startIndex - count; i--) {
1095                                 for (int j = 0; j < strlen (values); j++) {
1096                                         if (this.c_str[i] == values[j])
1097                                                 return i;
1098                                 }
1099                         }
1100
1101                         return -1;
1102                 }
1103
1104                 public string PadLeft (int totalWidth)
1105                 {
1106                         return PadLeft (totalWidth, ' ');
1107                 }
1108
1109                 public string PadLeft (int totalWidth, char padChar)
1110                 {
1111                         char[] str;
1112                         int i, j;
1113
1114                         if (totalWidth < 0)
1115                                 throw new ArgumentException ();
1116
1117                         str = new char [totalWidth > this.length ? totalWidth : this.length];
1118                         for (i = 0; i < totalWidth - this.length; i++)
1119                                 str[i] = padChar;
1120
1121                         for (j = 0; j < this.length; i++, j++)
1122                                 str[i] = this.c_str[j];
1123
1124                         return new String (str);
1125                 }
1126
1127                 public string PadRight (int totalWidth)
1128                 {
1129                         return PadRight (totalWidth, ' ');
1130                 }
1131
1132                 public string PadRight (int totalWidth, char padChar)
1133                 {
1134                         char[] str;
1135                         int i;
1136
1137                         if (totalWidth < 0)
1138                                 throw new ArgumentException ();
1139
1140                         str = new char [totalWidth > this.length ? totalWidth : this.length];
1141                         for (i = 0; i < this.length; i++)
1142                                 str[i] = this.c_str[i];
1143
1144                         for ( ; i < str.Length; i++)
1145                                 str[i] = padChar;
1146
1147                         return new String (str);
1148                 }
1149
1150                 public string Remove (int startIndex, int count)
1151                 {
1152                         char[] str;
1153                         int i, j, len;
1154
1155                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
1156                                 throw new ArgumentOutOfRangeException ();
1157
1158                         len = this.length - count;
1159                         if (len == 0)
1160                                 return String.Empty;
1161                         
1162                         String res = new String (len);
1163                         str = res.c_str;
1164                         for (i = 0; i < startIndex; i++)
1165                                 str[i] = this.c_str[i];
1166                         for (j = i + count; j < this.length; j++)
1167                                 str[i++] = this.c_str[j];
1168
1169                         return res;
1170                 }
1171
1172                 public string Replace (char oldChar, char newChar)
1173                 {
1174                         char[] str;
1175                         int i;
1176
1177                         String res = new String (length);
1178                         str = res.c_str;
1179                         for (i = 0; i < this.length; i++) {
1180                                 if (this.c_str[i] == oldChar)
1181                                         str[i] = newChar;
1182                                 else
1183                                         str[i] = this.c_str[i];
1184                         }
1185
1186                         return res;
1187                 }
1188
1189                 public string Replace (string oldValue, string newValue)
1190                 {
1191                         // LAMESPEC: msdn doesn't specify what to do if either args is null
1192                         int index, len, i, j;
1193                         char[] str;
1194
1195                         if (oldValue == null || newValue == null)
1196                                 throw new ArgumentNullException ();
1197
1198                         // Use IndexOf in case I later rewrite it to use Boyer-Moore
1199                         index = IndexOf (oldValue, 0);
1200                         if (index == -1) {
1201                                 // This is the easy one ;-)
1202                                 return Substring (0, this.length);
1203                         }
1204
1205                         len = this.length - oldValue.length + newValue.length;
1206                         if (len == 0)
1207                                 return String.Empty;
1208
1209                         String res = new String (len);
1210                         str = res.c_str;
1211                         for (i = 0; i < index; i++)
1212                                 str[i] = this.c_str[i];
1213                         for (j = 0; j < newValue.length; j++)
1214                                 str[i++] = newValue[j];
1215                         for (j = index + oldValue.length; j < this.length; j++)
1216                                 str[i++] = this.c_str[j];
1217
1218                         return res;
1219                 }
1220
1221                 private int splitme (char[] separators, int startIndex)
1222                 {
1223                         /* this is basically a customized IndexOfAny() for the Split() methods */
1224                         for (int i = startIndex; i < this.length; i++) {
1225                                 if (separators != null) {
1226                                         foreach (char sep in separators) {
1227                                                 if (this.c_str[i] == sep)
1228                                                         return i - startIndex;
1229                                         }
1230                                 } else if (is_lwsp (this.c_str[i])) {
1231                                         return i - startIndex;
1232                                 }
1233                         }
1234
1235                         return -1;
1236                 }
1237
1238                 public string[] Split (params char[] separator)
1239                 {
1240                         /**
1241                          * split:
1242                          * @separator: delimiting chars or null to split on whtspc
1243                          *
1244                          * Returns: 1. An array consisting of a single
1245                          * element (@this) if none of the delimiting
1246                          * chars appear in @this. 2. An array of
1247                          * substrings which are delimited by one of
1248                          * the separator chars. 3. An array of
1249                          * substrings separated by whitespace if
1250                          * @separator is null. The Empty string should
1251                          * be returned wherever 2 delimiting chars are
1252                          * adjacent.
1253                          **/
1254                         // FIXME: would using a Queue be better?
1255                         string[] strings;
1256                         ArrayList list;
1257                         int index, len;
1258
1259                         list = new ArrayList ();
1260                         for (index = 0, len = 0; index < this.length; index += len + 1) {
1261                                 len = splitme (separator, index);
1262                                 len = len > -1 ? len : this.length - index;
1263                                 if (len == 0) {
1264                                         list.Add (String.Empty);
1265                                 } else {
1266                                         char[] str;
1267                                         int i;
1268
1269                                         str = new char [len];
1270                                         for (i = 0; i < len; i++)
1271                                                 str[i] = this.c_str[index + i];
1272
1273                                         list.Add (new String (str));
1274                                 }
1275                         }
1276
1277                         strings = new string [list.Count];
1278                         if (list.Count == 1) {
1279                                 /* special case for an array holding @this */
1280                                 strings[0] = this;
1281                         } else {
1282                                 for (index = 0; index < list.Count; index++)
1283                                         strings[index] = (string) list[index];
1284                         }
1285
1286                         return strings;
1287                 }
1288
1289                 public string[] Split (char[] separator, int maxCount)
1290                 {
1291                         // FIXME: what to do if maxCount <= 0?
1292                         // FIXME: would using Queue be better than ArrayList?
1293                         string[] strings;
1294                         ArrayList list;
1295                         int index, len, used;
1296
1297                         used = 0;
1298                         list = new ArrayList ();
1299                         for (index = 0, len = 0; index < this.length && used < maxCount; index += len + 1) {
1300                                 len = splitme (separator, index);
1301                                 len = len > -1 ? len : this.length - index;
1302                                 if (len == 0) {
1303                                         list.Add (String.Empty);
1304                                 } else {
1305                                         char[] str;
1306                                         int i;
1307
1308                                         str = new char [len];
1309                                         for (i = 0; i < len; i++)
1310                                                 str[i] = this.c_str[index + i];
1311
1312                                         list.Add (new String (str));
1313                                 }
1314                                 used++;
1315                         }
1316
1317                         /* fit the remaining chunk of the @this into it's own element */
1318                         if (index != this.length) {
1319                                 char[] str;
1320                                 int i;
1321
1322                                 str = new char [this.length - index];
1323                                 for (i = index; i < this.length; i++)
1324                                         str[i - index] = this.c_str[i];
1325
1326                                 list.Add (new String (str));
1327                         }
1328
1329                         strings = new string [list.Count];
1330                         if (list.Count == 1) {
1331                                 /* special case for an array holding @this */
1332                                 strings[0] = this;
1333                         } else {
1334                                 for (index = 0; index < list.Count; index++)
1335                                         strings[index] = (string) list[index];
1336                         }
1337
1338                         return strings;
1339                 }
1340
1341                 public bool StartsWith (string value)
1342                 {
1343                         bool startswith = true;
1344                         int i;
1345
1346                         if (value == null)
1347                                 throw new ArgumentNullException ();
1348
1349                         if (value.length > this.length)
1350                                 return false;
1351
1352                         for (i = 0; i < value.length && startswith; i++)
1353                                 startswith = startswith && value.c_str[i] == this.c_str[i];
1354
1355                         return startswith;
1356                 }
1357
1358                 public string Substring (int startIndex)
1359                 {
1360                         char[] str;
1361                         int i, len;
1362
1363                         if (startIndex < 0 || startIndex > this.length)
1364                                 throw new ArgumentOutOfRangeException ();
1365
1366                         len = this.length - startIndex;
1367                         if (len == 0)
1368                                 return String.Empty;
1369                         String res = new String (len);
1370                         str = res.c_str;
1371                         for (i = startIndex; i < this.length; i++)
1372                                 str[i - startIndex] = this.c_str[i];
1373
1374                         return res;
1375                 }
1376
1377                 public string Substring (int startIndex, int length)
1378                 {
1379                         char[] str;
1380                         int i;
1381
1382                         if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1383                                 throw new ArgumentOutOfRangeException ();
1384
1385                         if (length == 0)
1386                                 return String.Empty;
1387                         
1388                         String res = new String (length);
1389                         str = res.c_str;
1390                         for (i = startIndex; i < startIndex + length; i++)
1391                                 str[i - startIndex] = this.c_str[i];
1392
1393                         return res;
1394                 }
1395
1396                 [MonoTODO]
1397                 public bool ToBoolean (IFormatProvider provider)
1398                 {
1399                         // FIXME: implement me
1400                         throw new NotImplementedException ();
1401                 }
1402                 
1403                 [MonoTODO]
1404                 public byte ToByte (IFormatProvider provider)
1405                 {
1406                         // FIXME: implement me
1407                         throw new NotImplementedException ();
1408                 }
1409                 
1410                 [MonoTODO]
1411                 public char ToChar (IFormatProvider provider)
1412                 {
1413                         // FIXME: implement me
1414                         throw new NotImplementedException ();
1415                 }
1416
1417                 public char[] ToCharArray ()
1418                 {
1419                         return ToCharArray (0, this.length);
1420                 }
1421
1422                 public char[] ToCharArray (int startIndex, int length)
1423                 {
1424                         char[] chars;
1425                         int i;
1426
1427                         if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1428                                 throw new ArgumentOutOfRangeException ();
1429
1430                         chars = new char [length];
1431                         for (i = startIndex; i < length; i++)
1432                                 chars[i - startIndex] = this.c_str[i];
1433
1434                         return chars;
1435                 }
1436
1437                 [MonoTODO]
1438                 public DateTime ToDateTime (IFormatProvider provider)
1439                 {
1440                         // FIXME: implement me
1441                         // return new DateTime (0);
1442                         throw new NotImplementedException ();
1443                 }
1444
1445                 [MonoTODO]
1446                 public decimal ToDecimal (IFormatProvider provider)
1447                 {
1448                         // FIXME: implement me
1449                         throw new NotImplementedException ();
1450                 }
1451
1452                 [MonoTODO]
1453                 public double ToDouble (IFormatProvider provider)
1454                 {
1455                         // FIXME: implement me
1456                         throw new NotImplementedException ();
1457                 }
1458
1459                 [MonoTODO]
1460                 public short ToInt16 (IFormatProvider provider)
1461                 {
1462                         // FIXME: implement me
1463                         throw new NotImplementedException ();
1464                 }
1465
1466                 [MonoTODO]
1467                 public int ToInt32 (IFormatProvider provider)
1468                 {
1469                         // FIXME: implement me
1470                         throw new NotImplementedException ();
1471                 }
1472
1473                 [MonoTODO]
1474                 public long ToInt64 (IFormatProvider provider)
1475                 {
1476                         // FIXME: implement me
1477                         throw new NotImplementedException ();
1478                 }
1479
1480                 public string ToLower ()
1481                 {
1482                         char[] str;
1483                         int i;
1484
1485                         String res = new String (length);
1486                         str = res.c_str;
1487                         for (i = 0; i < this.length; i++)
1488                                 str[i] = Char.ToLower (this.c_str[i]);
1489
1490                         return res;
1491                 }
1492
1493                 [MonoTODO]
1494                 public string ToLower (CultureInfo culture)
1495                 {
1496                         // FIXME: implement me
1497                         throw new NotImplementedException ();
1498
1499                 }
1500
1501                 [CLSCompliant(false)][MonoTODO]
1502                 public sbyte ToSByte (IFormatProvider provider)
1503                 {
1504                         // FIXME: implement me
1505                         throw new NotImplementedException ();
1506                 }
1507
1508                 [MonoTODO]
1509                 public float ToSingle (IFormatProvider provider)
1510                 {
1511                         // FIXME: implement me
1512                         throw new NotImplementedException ();
1513                 }
1514
1515                 public override string ToString ()
1516                 {
1517                         return this;
1518                 }
1519
1520                 [MonoTODO]
1521                 public string ToString (IFormatProvider format)
1522                 {
1523                         // FIXME: implement me
1524                         throw new NotImplementedException ();
1525                 }
1526
1527                 [MonoTODO]
1528                 public object ToType (Type conversionType, IFormatProvider provider)
1529                 {
1530                         // FIXME: implement me
1531                         throw new NotImplementedException ();
1532                 }
1533
1534                 [CLSCompliant(false)][MonoTODO]
1535                 public ushort ToUInt16 (IFormatProvider provider)
1536                 {
1537                         // FIXME: implement me
1538                         throw new NotImplementedException ();
1539                 }
1540
1541                 [CLSCompliant(false)][MonoTODO]
1542                 public uint ToUInt32 (IFormatProvider provider)
1543                 {
1544                         // FIXME: implement me
1545                         throw new NotImplementedException ();
1546                 }
1547
1548                 [CLSCompliant(false)][MonoTODO]
1549                 public ulong ToUInt64 (IFormatProvider provider)
1550                 {
1551                         // FIXME: implement me
1552                         throw new NotImplementedException ();
1553                 }
1554
1555                 public string ToUpper ()
1556                 {
1557                         char[] str;
1558                         int i;
1559
1560                         String res = new String (length);
1561                         str = res.c_str;
1562                         for (i = 0; i < this.length; i++)
1563                                 str[i] = Char.ToUpper (this.c_str[i]);
1564
1565                         return res;
1566                 }
1567
1568                 [MonoTODO]
1569                 public string ToUpper (CultureInfo culture)
1570                 {
1571                         // FIXME: implement me
1572                         throw new NotImplementedException ();
1573                 }
1574
1575                 public string Trim ()
1576                 {
1577                         return Trim (null);
1578                 }
1579
1580                 public string Trim (params char[] trimChars)
1581                 {
1582                         int begin, end;
1583                         bool matches;
1584
1585                         matches = true;
1586                         for (begin = 0; matches && begin < this.length; begin++) {
1587                                 if (trimChars != null) {
1588                                         matches = false;
1589                                         foreach (char c in trimChars) {
1590                                                 matches = this.c_str[begin] == c;
1591                                                 if (matches)
1592                                                         break;
1593                                         }
1594                                 } else {
1595                                         matches = is_lwsp (this.c_str[begin]);
1596                                 }
1597                         }
1598
1599                         matches = true;
1600                         for (end = this.length - 1; matches && end > begin; end--) {
1601                                 if (trimChars != null) {
1602                                         matches = false;
1603                                         foreach (char c in trimChars) {
1604                                                 matches = this.c_str[end] == c;
1605                                                 if (matches)
1606                                                         break;
1607                                         }
1608                                 } else {
1609                                         matches = is_lwsp (this.c_str[end]);
1610                                 }
1611                         }
1612
1613                         if (begin >= end)
1614                                 return String.Empty;
1615
1616                         return Substring (begin, end - begin);
1617                 }
1618
1619                 public string TrimEnd (params char[] trimChars)
1620                 {
1621                         bool matches = true;
1622                         int end;
1623
1624                         for (end = this.length; end > 0; end--) {
1625                                 if (trimChars != null) {
1626                                         matches = false;
1627                                         foreach (char c in trimChars) {
1628                                                 matches = this.c_str[end] == c;
1629                                                 if (matches)
1630                                                         break;
1631                                         }
1632                                 } else {
1633                                         matches = is_lwsp (this.c_str[end]);
1634                                 }
1635                         }
1636
1637                         if (end == 0)
1638                                 return String.Empty;
1639
1640                         return Substring (0, end);
1641                 }
1642
1643                 public string TrimStart (params char[] trimChars)
1644                 {
1645                         bool matches = true;
1646                         int begin;
1647
1648                         for (begin = 0; matches && begin < this.length; begin++) {
1649                                 if (trimChars != null) {
1650                                         matches = false;
1651                                         foreach (char c in trimChars) {
1652                                                 matches = this.c_str[begin] == c;
1653                                                 if (matches)
1654                                                         break;
1655                                         }
1656                                 } else {
1657                                         matches = is_lwsp (this.c_str[begin]);
1658                                 }
1659                         }
1660
1661                         if (begin == this.length)
1662                                 return String.Empty;
1663
1664                         return Substring (begin, this.length - begin);
1665                 }
1666
1667                 // Operators
1668                 public static bool operator ==(string a, string b)
1669                 {
1670                         if ((object)a == null) {
1671                                 if ((object)b == null)
1672                                         return true;
1673                                 return false;
1674                         }
1675                         if ((object)b == null)
1676                                 return false;
1677         
1678                         if (a.length != b.length)
1679                                 return false;
1680
1681                         int l = a.length;
1682                         for (int i = 0; i < l; i++)
1683                                 if (a.c_str[i] != b.c_str[i])
1684                                         return false;
1685
1686                         return true;
1687                 }
1688
1689                 public static bool operator !=(string a, string b)
1690                 {
1691                         return !(a == b);
1692                 }
1693         }
1694 }