Back out my change
[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                                         break;
323                         }
324
325                         return ((int) (strA.c_str[i] - strB.c_str[i]));
326                 }
327
328                 [MonoTODO]
329                 public static int Compare (string strA, string strB, bool ignoreCase, CultureInfo culture)
330                 {
331                         // FIXME: implement me
332                         return 0;
333                 }
334
335                 public static int Compare (string strA, int indexA, string strB, int indexB, int length)
336                 {
337                         int i;
338
339                         if (length < 0 || indexA < 0 || indexB < 0)
340                                 throw new ArgumentOutOfRangeException ();
341
342                         if (indexA > strA.Length || indexB > strB.Length)
343                                 throw new ArgumentOutOfRangeException ();
344
345                         /* And again with the ("" > null) logic... lord have mercy! */
346                         if (strA == null) {
347                                 if (strB == null)
348                                         return 0;
349                                 else
350                                         return -1;
351                         } else if (strB == null)
352                                 return 1;
353
354                         for (i = 0; i < length - 1; i++) {
355                                 if (strA[indexA + i] != strB[indexB + i])
356                                         break;
357                         }
358
359                         return ((int) (strA[indexA + i] - strB[indexB + i]));
360                 }
361
362                 public static int Compare (string strA, int indexA, string strB, int indexB,
363                                            int length, bool ignoreCase)
364                 {
365                         int i;
366
367                         if (!ignoreCase)
368                                 return Compare (strA, indexA, strB, indexB, length);
369
370                         if (length < 0 || indexA < 0 || indexB < 0)
371                                 throw new ArgumentOutOfRangeException ();
372
373                         if (indexA > strA.Length || indexB > strB.Length)
374                                 throw new ArgumentOutOfRangeException ();
375
376                         /* When will the hurting stop!?!? */
377                         if (strA == null) {
378                                 if (strB == null)
379                                         return 0;
380                                 else
381                                         return -1;
382                         } else if (strB == null)
383                                 return 1;
384
385                         for (i = 0; i < length - 1; i++) {
386                                 if (Char.ToLower (strA[indexA + i]) != Char.ToLower (strB[indexB + i]))
387                                         break;
388                         }
389
390                         return ((int) (strA[indexA + i] - strB[indexB + i]));
391                 }
392
393                 [MonoTODO]
394                 public static int Compare (string strA, int indexA, string strB, int indexB,
395                                            int length, bool ignoreCase, CultureInfo culture)
396                 {
397                         if (culture == null)
398                                 throw new ArgumentNullException ();
399
400                         if (length < 0 || indexA < 0 || indexB < 0)
401                                 throw new ArgumentOutOfRangeException ();
402
403                         if (indexA > strA.Length || indexB > strB.Length)
404                                 throw new ArgumentOutOfRangeException ();
405
406                         /* I can't take it anymore! */
407                         if (strA == null) {
408                                 if (strB == null)
409                                         return 0;
410                                 else
411                                         return -1;
412                         } else if (strB == null)
413                                 return 1;
414
415                         // FIXME: implement me
416                         return 0;
417                 }
418
419                 public static int CompareOrdinal (string strA, string strB)
420                 {
421                         int i;
422
423                         /* Please God, make it stop! */
424                         if (strA == null) {
425                                 if (strB == null)
426                                         return 0;
427                                 else
428                                         return -1;
429                         } else if (strB == null)
430                                 return 1;
431
432                         for (i = 0; i < strA.Length && i < strB.Length; i++) {
433                                 char cA, cB;
434
435                                 cA = tolowerordinal (strA[i]);
436                                 cB = tolowerordinal (strB[i]);
437
438                                 if (cA != cB)
439                                         break;
440                         }
441
442                         return ((int) (strA[i] - strB[i]));
443                 }
444
445                 public static int CompareOrdinal (string strA, int indexA, string strB, int indexB,
446                                                   int length)
447                 {
448                         int i;
449
450                         if (length < 0 || indexA < 0 || indexB < 0)
451                                 throw new ArgumentOutOfRangeException ();
452
453                         if (strA == null) {
454                                 if (strB == null)
455                                         return 0;
456                                 else
457                                         return -1;
458                         } else if (strB == null)
459                                 return 1;
460
461                         for (i = 0; i < length; i++) {
462                                 char cA, cB;
463
464                                 cA = tolowerordinal (strA[indexA + i]);
465                                 cB = tolowerordinal (strB[indexB + i]);
466
467                                 if (cA != cB)
468                                         break;
469                         }
470
471                         return ((int) (strA[indexA + i] - strB[indexB + i]));
472                 }
473
474                 public int CompareTo (object obj)
475                 {
476                         return Compare (this, obj == null ? null : obj.ToString ());
477                 }
478
479                 public int CompareTo (string str)
480                 {
481                         return Compare (this, str);
482                 }
483
484                 public static string Concat (object arg)
485                 {
486                         return arg != null ? arg.ToString () : String.Empty;
487                 }
488
489                 public static string Concat (params object[] args)
490                 {
491                         string[] strings;
492                         char[] str;
493                         int len, i;
494
495                         if (args == null)
496                                 throw new ArgumentNullException ();
497
498                         strings = new string [args.Length];
499                         len = 0;
500                         i = 0;
501                         foreach (object arg in args) {
502                                 /* use Empty for each null argument */
503                                 if (arg == null)
504                                         strings[i] = String.Empty;
505                                 else
506                                         strings[i] = arg.ToString ();
507                                 len += strings[i].length;
508                                 i++;
509                         }
510
511                         if (len == 0)
512                                 return String.Empty;
513
514                         String res = new String (len);
515                         str = res.c_str;
516                         i = 0;
517                         for (int j = 0; j < strings.Length; j++)
518                                 for (int k = 0; k < strings[j].length; k++)
519                                         str[i++] = strings[j].c_str[k];
520
521                         return res;
522                 }
523
524                 public static string Concat (params string[] values)
525                 {
526                         int len, i;
527                         char[] str;
528
529                         if (values == null)
530                                 throw new ArgumentNullException ();
531
532                         len = 0;
533                         foreach (string value in values)
534                                 len += value != null ? value.Length : 0;
535
536                         if (len == 0)
537                                 return String.Empty;
538
539                         String res = new String (len);
540                         str = res.c_str;
541                         i = 0;
542                         foreach (string value in values) {
543                                 if (value == null)
544                                         continue;
545
546                                 for (int j = 0; j < value.length; j++)
547                                         str[i++] = value.c_str[j];
548                         }
549
550                         return res;
551                 }
552
553                 public static string Concat (object arg0, object arg1)
554                 {
555                         string str0 = arg0 != null ? arg0.ToString () : String.Empty;
556                         string str1 = arg1 != null ? arg1.ToString () : String.Empty;
557
558                         return Concat (str0, str1);
559                 }
560
561                 public static string Concat (string str0, string str1)
562                 {
563                         char[] concat;
564                         int i, j, len;
565
566                         if (str0 == null)
567                                 str0 = String.Empty;
568                         if (str1 == null)
569                                 str1 = String.Empty;
570
571                         len = str0.length + str1.length;
572                         if (len == 0)
573                                 return String.Empty;
574
575                         String res = new String (len);
576
577                         concat = res.c_str;
578                         for (i = 0; i < str0.length; i++)
579                                 concat[i] = str0.c_str[i];
580                         for (j = 0 ; j < str1.length; j++)
581                                 concat[i + j] = str1.c_str[j];
582
583                         return res;
584                 }
585
586                 public static string Concat (object arg0, object arg1, object arg2)
587                 {
588                         string str0 = arg0 != null ? arg0.ToString () : String.Empty;
589                         string str1 = arg1 != null ? arg1.ToString () : String.Empty;
590                         string str2 = arg2 != null ? arg2.ToString () : String.Empty;
591
592                         return Concat (str0, str1, str2);
593                 }
594
595                 public static string Concat (string str0, string str1, string str2)
596                 {
597                         char[] concat;
598                         int i, j, k, len;
599
600                         if (str0 == null)
601                                 str0 = String.Empty;
602                         if (str1 == null)
603                                 str1 = String.Empty;
604                         if (str2 == null)
605                                 str2 = String.Empty;
606
607                         len = str0.length + str1.length + str2.length;
608                         if (len == 0)
609                                 return String.Empty;
610
611                         String res = new String (len);
612
613                         concat = res.c_str;
614                         for (i = 0; i < str0.length; i++)
615                                 concat[i] = str0.c_str[i];
616                         for (j = 0; j < str1.length; j++)
617                                 concat[i + j] = str1.c_str[j];
618                         for (k = 0; k < str2.length; k++)
619                                 concat[i + j + k] = str2.c_str[k];
620
621                         return res;
622                 }
623
624                 public static string Concat (string str0, string str1, string str2, string str3)
625                 {
626                         char[] concat;
627                         int i, j, k, l, len;
628
629                         if (str0 == null)
630                                 str0 = String.Empty;
631                         if (str1 == null)
632                                 str1 = String.Empty;
633                         if (str2 == null)
634                                 str2 = String.Empty;
635                         if (str3 == null)
636                                 str3 = String.Empty;
637
638                         len = str0.length + str1.length + str2.length + str3.length;
639                         if (len == 0)
640                                 return String.Empty;
641                         String res = new String (len);
642
643                         concat = res.c_str;
644                         for (i = 0; i < str0.length; i++)
645                                 concat[i] = str0.c_str[i];
646                         for (j = 0; j < str1.length; j++)
647                                 concat[i + j] = str1.c_str[j];
648                         for (k = 0; k < str2.length; k++)
649                                 concat[i + j + k] = str2.c_str[k];
650                         for (l = 0; l < str3.length; l++)
651                                 concat[i + j + k + l] = str3.c_str[l];
652
653                         return res;
654                 }
655
656                 public static string Copy (string str)
657                 {
658                         // FIXME: how do I *copy* a string if I can only have 1 of each?
659                         if (str == null)
660                                 throw new ArgumentNullException ();
661
662                         return str;
663                 }
664
665                 public void CopyTo (int sourceIndex, char[] destination, int destinationIndex, int count)
666                 {
667                         // LAMESPEC: should I null-terminate?
668                         int i;
669
670                         if (destination == null)
671                                 throw new ArgumentNullException ();
672
673                         if (sourceIndex < 0 || destinationIndex < 0 || count < 0)
674                                 throw new ArgumentOutOfRangeException ();
675
676                         if (sourceIndex + count > this.length)
677                                 throw new ArgumentOutOfRangeException ();
678
679                         if (destinationIndex + count > destination.Length)
680                                 throw new ArgumentOutOfRangeException ();
681
682                         for (i = 0; i < count; i++)
683                                 destination[destinationIndex + i] = this.c_str[sourceIndex + i];
684                 }
685
686                 public bool EndsWith (string value)
687                 {
688                         bool endswith = true;
689                         int start, i;
690
691                         if (value == null)
692                                 throw new ArgumentNullException ();
693
694                         start = this.length - value.length;
695                         if (start < 0)
696                                 return false;
697
698                         for (i = start; i < this.length && endswith; i++)
699                                 endswith = this.c_str[i] == value.c_str[i - start];
700
701                         return endswith;
702                 }
703
704                 public override bool Equals (object obj)
705                 {
706                         if (!(obj is String))
707                                 return false;
708
709                         return this == (String) obj;
710                 }
711
712                 public bool Equals (string value)
713                 {
714                         return this == value;
715                 }
716
717                 public static bool Equals (string a, string b)
718                 {
719                         return a == b;
720                 }
721
722                 [MonoTODO]
723                 public static string Format (string format, object arg0)
724                 {
725                         // FIXME: implement me
726                         return format+arg0.ToString();
727                 }
728
729                 [MonoTODO]
730                 public static string Format (string format, params object[] args)
731                 {
732                         // FIXME: implement me
733                         Console.WriteLine (args[0].ToString());
734                         if (args.Length == 1)
735                                 return format+args[0].ToString();
736                         if (args.Length == 2)
737                                 return format+args[0].ToString()+args[1].ToString();
738                         if (args.Length == 3)
739                                 return format+args[0].ToString()+args[1].ToString()+args[2].ToString();
740                         if (args.Length == 4)
741                                 return format+args[0].ToString()+args[1].ToString()+args[2].ToString()+args[3].ToString();
742                         Console.WriteLine ("String.Format with args: "+args.Length.ToString());
743                         return format;
744                 }
745                 
746                 [MonoTODO]
747                 public static string Format (IFormatProvider provider, string format, params object[] args)
748                 {
749                         // FIXME: implement me
750                         return null;
751                 }
752                 
753                 [MonoTODO]
754                 public static string Format (string format, object arg0, object arg1)
755                 {
756                         // FIXME: implement me
757                         return format+arg0.ToString()+arg1.ToString();
758                 }
759
760                 [MonoTODO]
761                 public static string Format (string format, object arg0, object arg1, object arg2)
762                 {
763                         // FIXME: implement me
764                         return format+arg0.ToString()+arg1.ToString()+arg2.ToString();
765                 }
766
767                 //public CharEnumerator GetEnumerator ()
768                 [MonoTODO]
769                 public IEnumerator GetEnumerator ()
770                 {
771                         // FIXME: implement me
772                         return null;
773                 }
774
775                 public override int GetHashCode ()
776                 {
777                         int h = 0;
778                         int i;
779                         for (i = 0; i < length; ++i)
780                                 h = (h << 5) - h + c_str [i];
781                         return h;
782                 }
783
784                 public TypeCode GetTypeCode ()
785                 {
786                         return TypeCode.String;
787                 }
788
789                 public int IndexOf (char value)
790                 {
791                         return IndexOf (value, 0, this.length);
792                 }
793
794                 public int IndexOf (string value)
795                 {
796                         return IndexOf (value, 0, this.length);
797                 }
798
799                 public int IndexOf (char value, int startIndex)
800                 {
801                         return IndexOf (value, startIndex, this.length - startIndex);
802                 }
803
804                 public int IndexOf (string value, int startIndex)
805                 {
806                         return IndexOf (value, startIndex, this.length - startIndex);
807                 }
808
809                 public int IndexOf (char value, int startIndex, int count)
810                 {
811                         int i;
812
813                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
814                                 throw new ArgumentOutOfRangeException ();
815
816                         for (i = startIndex; i - startIndex < count; i++)
817                                 if (this.c_str[i] == value)
818                                         return i;
819
820                         return -1;
821                 }
822
823                 public int IndexOf (string value, int startIndex, int count)
824                 {
825                         if (value == null)
826                                 throw new ArgumentNullException ();
827
828                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
829                                 throw new ArgumentOutOfRangeException ();
830
831                         return BoyerMoore (this.c_str, value, startIndex, count);
832 #if XXX
833                         int i;
834                         for (i = startIndex; i - startIndex + value.Length <= count; ) {
835                                 if (this.c_str[i] == value[0]) {
836                                         bool equal = true;
837                                         int j, nexti = 0;
838
839                                         for (j = 1; equal && j < value.Length; j++) {
840                                                 equal = this.c_str[i + j] == value[j];
841                                                 if (this.c_str[i + j] == value[0] && nexti == 0)
842                                                         nexti = i + j;
843                                         }
844
845                                         if (equal)
846                                                 return i;
847
848                                         if (nexti != 0)
849                                                 i = nexti;
850                                         else
851                                                 i += j;
852                                 } else
853                                         i++;
854                         }
855
856                         return -1;
857 #endif
858                 }
859
860                 public int IndexOfAny (char[] values)
861                 {
862                         return IndexOfAny (values, 0, this.length);
863                 }
864
865                 public int IndexOfAny (char[] values, int startIndex)
866                 {
867                         return IndexOfAny (values, startIndex, this.length - startIndex);
868                 }
869
870                 public int IndexOfAny (char[] values, int startIndex, int count)
871                 {
872                         if (values == null)
873                                 throw new ArgumentNullException ();
874
875                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
876                                 throw new ArgumentOutOfRangeException ();
877
878                         for (int i = startIndex; i < startIndex + count; i++) {
879                                 for (int j = 0; j < strlen (values); j++) {
880                                         if (this.c_str[i] == values[j])
881                                                 return i;
882                                 }
883                         }
884
885                         return -1;
886                 }
887
888                 public string Insert (int startIndex, string value)
889                 {
890                         char[] str;
891                         int i, j;
892
893                         if (value == null)
894                                 throw new ArgumentNullException ();
895
896                         if (startIndex < 0 || startIndex > this.length)
897                                 throw new ArgumentOutOfRangeException ();
898
899                         String res = new String (value.length + this.length);
900
901                         str = res.c_str;
902                         for (i = 0; i < startIndex; i++)
903                                 str[i] = this.c_str[i];
904                         for (j = 0; j < value.length; j++)
905                                 str[i + j] = value.c_str[j];
906                         for ( ; i < this.length; i++)
907                                 str[i + j] = this.c_str[i];
908
909                         return res;
910                 }
911
912                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
913                 public extern static string Intern (string str);
914
915                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
916                 public extern static string IsInterned (string str);
917
918                 public static string Join (string separator, string[] value)
919                 {
920                         return Join (separator, value, 0, value.Length);
921                 }
922
923                 public static string Join (string separator, string[] value, int startIndex, int count)
924                 {
925                         // LAMESPEC: msdn doesn't specify what happens when separator is null
926                         int len, i, j, used;
927                         char[] str;
928
929                         if (separator == null || value == null)
930                                 throw new ArgumentNullException ();
931
932                         if (startIndex + count > value.Length)
933                                 throw new ArgumentOutOfRangeException ();
934
935                         len = 0;
936                         for (i = startIndex, used = 0; used < count; i++, used++) {
937                                 if (i != startIndex)
938                                         len += separator.length;
939
940                                 len += value[i].length;
941                         }
942
943                         // We have no elements to join?
944                         if (i == startIndex)
945                                 return String.Empty;
946
947                         String res = new String (len);
948
949                         str = res.c_str;
950                         for (i = 0; i < value[startIndex].length; i++)
951                                 str[i] = value[startIndex][i];
952
953                         used = 1;
954                         for (j = startIndex + 1; used < count; j++, used++) {
955                                 int k;
956
957                                 for (k = 0; k < separator.length; k++)
958                                         str[i++] = separator.c_str[k];
959                                 for (k = 0; k < value[j].length; k++)
960                                         str[i++] = value[j].c_str[k];
961                         }
962
963                         return res;
964                 }
965
966                 public int LastIndexOf (char value)
967                 {
968                         int i = this.length;
969                         if (i == 0)
970                                 return -1;
971                         --i;
972                         for (; i >= 0; i--) {
973                                 if (this.c_str[i] == value)
974                                         return i;
975                         }
976
977                         return -1;
978                 }
979
980                 public int LastIndexOf (string value)
981                 {
982                         return LastIndexOf (value, this.length - 1, this.length);
983                 }
984
985                 public int LastIndexOf (char value, int startIndex)
986                 {
987                         if (startIndex < 0 || startIndex >= this.length)
988                                 throw new ArgumentOutOfRangeException ();
989
990                         for (int i = startIndex; i >= 0; i--) {
991                                 if (this.c_str[i] == value)
992                                         return i;
993                         }
994
995                         return -1;
996                 }
997
998                 public int LastIndexOf (string value, int startIndex)
999                 {
1000                         return LastIndexOf (value, startIndex, startIndex + 1);
1001                 }
1002
1003                 public int LastIndexOf (char value, int startIndex, int count)
1004                 {
1005                         if (startIndex < 0 || count < 0)
1006                                 throw new ArgumentOutOfRangeException ();
1007
1008                         if (startIndex >= this.length || startIndex - count + 1 < 0)
1009                                 throw new ArgumentOutOfRangeException ();
1010
1011                         for (int i = startIndex; i > startIndex - count; i--) {
1012                                 if (this.c_str[i] == value)
1013                                         return i;
1014                         }
1015
1016                         return -1;
1017                 }
1018
1019                 public int LastIndexOf (string value, int startIndex, int count)
1020                 {
1021                         // LAMESPEC: currently I'm using startIndex as the 0-position in the comparison,
1022                         //           but maybe it's the end-position in MS's implementation?
1023                         //           msdn is unclear on this point. I think this is correct though.
1024                         int i, len;
1025
1026                         if (value == null)
1027                                 throw new ArgumentNullException ();
1028
1029                         if (startIndex < 0 || startIndex >= this.length)
1030                                 throw new ArgumentOutOfRangeException ();
1031
1032                         if (count < 0 || startIndex - count + 1 < 0)
1033                                 throw new ArgumentOutOfRangeException ();
1034
1035                         if (value == String.Empty)
1036                                 return startIndex;
1037
1038                         if (startIndex + value.length > this.length) {
1039                                 /* just a little optimization */
1040                                 int start;
1041
1042                                 start = this.length - value.length;
1043                                 count -= startIndex - start;
1044                                 startIndex = start;
1045                         }
1046
1047                         // FIXME: use a reversed-unicode-safe-Boyer-Moore?
1048                         len = value.length - 1;
1049                         for (i = startIndex; i > startIndex - count; i--) {
1050                                 if (this.c_str[i + len] == value.c_str[len]) {
1051                                         bool equal = true;
1052                                         int j;
1053
1054                                         for (j = len - 1; equal && j >= 0; j--)
1055                                                 equal = this.c_str[i + j] == value.c_str[j];
1056
1057                                         if (equal)
1058                                                 return i;
1059                                 }
1060                         }
1061
1062                         return -1;
1063                 }
1064
1065                 public int LastIndexOfAny (char[] values)
1066                 {
1067                         return LastIndexOfAny (values, this.length - 1, this.length);
1068                 }
1069
1070                 public int LastIndexOfAny (char[] values, int startIndex)
1071                 {
1072                         return LastIndexOfAny (values, startIndex, startIndex + 1);
1073                 }
1074
1075                 public int LastIndexOfAny (char[] values, int startIndex, int count)
1076                 {
1077                         int i;
1078
1079                         if (values == null)
1080                                 throw new ArgumentNullException ();
1081
1082                         if (startIndex < 0 || count < 0 || startIndex - count + 1 < 0)
1083                                 throw new ArgumentOutOfRangeException ();
1084
1085                         for (i = startIndex; i > startIndex - count; i--) {
1086                                 for (int j = 0; j < strlen (values); j++) {
1087                                         if (this.c_str[i] == values[j])
1088                                                 return i;
1089                                 }
1090                         }
1091
1092                         return -1;
1093                 }
1094
1095                 public string PadLeft (int totalWidth)
1096                 {
1097                         return PadLeft (totalWidth, ' ');
1098                 }
1099
1100                 public string PadLeft (int totalWidth, char padChar)
1101                 {
1102                         char[] str;
1103                         int i, j;
1104
1105                         if (totalWidth < 0)
1106                                 throw new ArgumentException ();
1107
1108                         str = new char [totalWidth > this.length ? totalWidth : this.length];
1109                         for (i = 0; i < totalWidth - this.length; i++)
1110                                 str[i] = padChar;
1111
1112                         for (j = 0; j < this.length; i++, j++)
1113                                 str[i] = this.c_str[j];
1114
1115                         return new String (str);
1116                 }
1117
1118                 public string PadRight (int totalWidth)
1119                 {
1120                         return PadRight (totalWidth, ' ');
1121                 }
1122
1123                 public string PadRight (int totalWidth, char padChar)
1124                 {
1125                         char[] str;
1126                         int i;
1127
1128                         if (totalWidth < 0)
1129                                 throw new ArgumentException ();
1130
1131                         str = new char [totalWidth > this.length ? totalWidth : this.length];
1132                         for (i = 0; i < this.length; i++)
1133                                 str[i] = this.c_str[i];
1134
1135                         for ( ; i < str.Length; i++)
1136                                 str[i] = padChar;
1137
1138                         return new String (str);
1139                 }
1140
1141                 public string Remove (int startIndex, int count)
1142                 {
1143                         char[] str;
1144                         int i, j, len;
1145
1146                         if (startIndex < 0 || count < 0 || startIndex + count > this.length)
1147                                 throw new ArgumentOutOfRangeException ();
1148
1149                         len = this.length - count;
1150                         if (len == 0)
1151                                 return String.Empty;
1152                         
1153                         String res = new String (len);
1154                         str = res.c_str;
1155                         for (i = 0; i < startIndex; i++)
1156                                 str[i] = this.c_str[i];
1157                         for (j = i + count; j < this.length; j++)
1158                                 str[i++] = this.c_str[j];
1159
1160                         return res;
1161                 }
1162
1163                 public string Replace (char oldChar, char newChar)
1164                 {
1165                         char[] str;
1166                         int i;
1167
1168                         String res = new String (length);
1169                         str = res.c_str;
1170                         for (i = 0; i < this.length; i++) {
1171                                 if (this.c_str[i] == oldChar)
1172                                         str[i] = newChar;
1173                                 else
1174                                         str[i] = this.c_str[i];
1175                         }
1176
1177                         return res;
1178                 }
1179
1180                 public string Replace (string oldValue, string newValue)
1181                 {
1182                         // LAMESPEC: msdn doesn't specify what to do if either args is null
1183                         int index, len, i, j;
1184                         char[] str;
1185
1186                         if (oldValue == null || newValue == null)
1187                                 throw new ArgumentNullException ();
1188
1189                         // Use IndexOf in case I later rewrite it to use Boyer-Moore
1190                         index = IndexOf (oldValue, 0);
1191                         if (index == -1) {
1192                                 // This is the easy one ;-)
1193                                 return Substring (0, this.length);
1194                         }
1195
1196                         len = this.length - oldValue.length + newValue.length;
1197                         if (len == 0)
1198                                 return String.Empty;
1199
1200                         String res = new String (len);
1201                         str = res.c_str;
1202                         for (i = 0; i < index; i++)
1203                                 str[i] = this.c_str[i];
1204                         for (j = 0; j < newValue.length; j++)
1205                                 str[i++] = newValue[j];
1206                         for (j = index + oldValue.length; j < this.length; j++)
1207                                 str[i++] = this.c_str[j];
1208
1209                         return res;
1210                 }
1211
1212                 private int splitme (char[] separators, int startIndex)
1213                 {
1214                         /* this is basically a customized IndexOfAny() for the Split() methods */
1215                         for (int i = startIndex; i < this.length; i++) {
1216                                 if (separators != null) {
1217                                         foreach (char sep in separators) {
1218                                                 if (this.c_str[i] == sep)
1219                                                         return i - startIndex;
1220                                         }
1221                                 } else if (is_lwsp (this.c_str[i])) {
1222                                         return i - startIndex;
1223                                 }
1224                         }
1225
1226                         return -1;
1227                 }
1228
1229                 public string[] Split (params char[] separator)
1230                 {
1231                         /**
1232                          * split:
1233                          * @separator: delimiting chars or null to split on whtspc
1234                          *
1235                          * Returns: 1. An array consisting of a single
1236                          * element (@this) if none of the delimiting
1237                          * chars appear in @this. 2. An array of
1238                          * substrings which are delimited by one of
1239                          * the separator chars. 3. An array of
1240                          * substrings separated by whitespace if
1241                          * @separator is null. The Empty string should
1242                          * be returned wherever 2 delimiting chars are
1243                          * adjacent.
1244                          **/
1245                         // FIXME: would using a Queue be better?
1246                         string[] strings;
1247                         ArrayList list;
1248                         int index, len;
1249
1250                         list = new ArrayList ();
1251                         for (index = 0, len = 0; index < this.length; index += len + 1) {
1252                                 len = splitme (separator, index);
1253                                 len = len > -1 ? len : this.length - index;
1254                                 if (len == 0) {
1255                                         list.Add (String.Empty);
1256                                 } else {
1257                                         char[] str;
1258                                         int i;
1259
1260                                         str = new char [len];
1261                                         for (i = 0; i < len; i++)
1262                                                 str[i] = this.c_str[index + i];
1263
1264                                         list.Add (new String (str));
1265                                 }
1266                         }
1267
1268                         strings = new string [list.Count];
1269                         if (list.Count == 1) {
1270                                 /* special case for an array holding @this */
1271                                 strings[0] = this;
1272                         } else {
1273                                 for (index = 0; index < list.Count; index++)
1274                                         strings[index] = (string) list[index];
1275                         }
1276
1277                         return strings;
1278                 }
1279
1280                 public string[] Split (char[] separator, int maxCount)
1281                 {
1282                         // FIXME: what to do if maxCount <= 0?
1283                         // FIXME: would using Queue be better than ArrayList?
1284                         string[] strings;
1285                         ArrayList list;
1286                         int index, len, used;
1287
1288                         used = 0;
1289                         list = new ArrayList ();
1290                         for (index = 0, len = 0; index < this.length && used < maxCount; index += len + 1) {
1291                                 len = splitme (separator, index);
1292                                 len = len > -1 ? len : this.length - index;
1293                                 if (len == 0) {
1294                                         list.Add (String.Empty);
1295                                 } else {
1296                                         char[] str;
1297                                         int i;
1298
1299                                         str = new char [len];
1300                                         for (i = 0; i < len; i++)
1301                                                 str[i] = this.c_str[index + i];
1302
1303                                         list.Add (new String (str));
1304                                 }
1305                                 used++;
1306                         }
1307
1308                         /* fit the remaining chunk of the @this into it's own element */
1309                         if (index != this.length) {
1310                                 char[] str;
1311                                 int i;
1312
1313                                 str = new char [this.length - index];
1314                                 for (i = index; i < this.length; i++)
1315                                         str[i - index] = this.c_str[i];
1316
1317                                 list.Add (new String (str));
1318                         }
1319
1320                         strings = new string [list.Count];
1321                         if (list.Count == 1) {
1322                                 /* special case for an array holding @this */
1323                                 strings[0] = this;
1324                         } else {
1325                                 for (index = 0; index < list.Count; index++)
1326                                         strings[index] = (string) list[index];
1327                         }
1328
1329                         return strings;
1330                 }
1331
1332                 public bool StartsWith (string value)
1333                 {
1334                         bool startswith = true;
1335                         int i;
1336
1337                         if (value == null)
1338                                 throw new ArgumentNullException ();
1339
1340                         if (value.length > this.length)
1341                                 return false;
1342
1343                         for (i = 0; i < value.length && startswith; i++)
1344                                 startswith = startswith && value.c_str[i] == this.c_str[i];
1345
1346                         return startswith;
1347                 }
1348
1349                 public string Substring (int startIndex)
1350                 {
1351                         char[] str;
1352                         int i, len;
1353
1354                         if (startIndex < 0 || startIndex > this.length)
1355                                 throw new ArgumentOutOfRangeException ();
1356
1357                         len = this.length - startIndex;
1358                         if (len == 0)
1359                                 return String.Empty;
1360                         String res = new String (len);
1361                         str = res.c_str;
1362                         for (i = startIndex; i < this.length; i++)
1363                                 str[i - startIndex] = this.c_str[i];
1364
1365                         return res;
1366                 }
1367
1368                 public string Substring (int startIndex, int length)
1369                 {
1370                         char[] str;
1371                         int i;
1372
1373                         if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1374                                 throw new ArgumentOutOfRangeException ();
1375
1376                         if (length == 0)
1377                                 return String.Empty;
1378                         
1379                         String res = new String (length);
1380                         str = res.c_str;
1381                         for (i = startIndex; i < startIndex + length; i++)
1382                                 str[i - startIndex] = this.c_str[i];
1383
1384                         return res;
1385                 }
1386
1387                 [MonoTODO]
1388                 public bool ToBoolean (IFormatProvider provider)
1389                 {
1390                         // FIXME: implement me
1391                         throw new NotImplementedException ();
1392                 }
1393                 
1394                 [MonoTODO]
1395                 public byte ToByte (IFormatProvider provider)
1396                 {
1397                         // FIXME: implement me
1398                         throw new NotImplementedException ();
1399                 }
1400                 
1401                 [MonoTODO]
1402                 public char ToChar (IFormatProvider provider)
1403                 {
1404                         // FIXME: implement me
1405                         throw new NotImplementedException ();
1406                 }
1407
1408                 public char[] ToCharArray ()
1409                 {
1410                         return ToCharArray (0, this.length);
1411                 }
1412
1413                 public char[] ToCharArray (int startIndex, int length)
1414                 {
1415                         char[] chars;
1416                         int i;
1417
1418                         if (startIndex < 0 || length < 0 || startIndex + length > this.length)
1419                                 throw new ArgumentOutOfRangeException ();
1420
1421                         chars = new char [length];
1422                         for (i = startIndex; i < length; i++)
1423                                 chars[i - startIndex] = this.c_str[i];
1424
1425                         return chars;
1426                 }
1427
1428                 [MonoTODO]
1429                 public DateTime ToDateTime (IFormatProvider provider)
1430                 {
1431                         // FIXME: implement me
1432                         // return new DateTime (0);
1433                         throw new NotImplementedException ();
1434                 }
1435
1436                 [MonoTODO]
1437                 public decimal ToDecimal (IFormatProvider provider)
1438                 {
1439                         // FIXME: implement me
1440                         throw new NotImplementedException ();
1441                 }
1442
1443                 [MonoTODO]
1444                 public double ToDouble (IFormatProvider provider)
1445                 {
1446                         // FIXME: implement me
1447                         throw new NotImplementedException ();
1448                 }
1449
1450                 [MonoTODO]
1451                 public short ToInt16 (IFormatProvider provider)
1452                 {
1453                         // FIXME: implement me
1454                         throw new NotImplementedException ();
1455                 }
1456
1457                 [MonoTODO]
1458                 public int ToInt32 (IFormatProvider provider)
1459                 {
1460                         // FIXME: implement me
1461                         throw new NotImplementedException ();
1462                 }
1463
1464                 [MonoTODO]
1465                 public long ToInt64 (IFormatProvider provider)
1466                 {
1467                         // FIXME: implement me
1468                         throw new NotImplementedException ();
1469                 }
1470
1471                 public string ToLower ()
1472                 {
1473                         char[] str;
1474                         int i;
1475
1476                         String res = new String (length);
1477                         str = res.c_str;
1478                         for (i = 0; i < this.length; i++)
1479                                 str[i] = Char.ToLower (this.c_str[i]);
1480
1481                         return res;
1482                 }
1483
1484                 [MonoTODO]
1485                 public string ToLower (CultureInfo culture)
1486                 {
1487                         // FIXME: implement me
1488                         throw new NotImplementedException ();
1489
1490                 }
1491
1492                 [CLSCompliant(false)][MonoTODO]
1493                 public sbyte ToSByte (IFormatProvider provider)
1494                 {
1495                         // FIXME: implement me
1496                         throw new NotImplementedException ();
1497                 }
1498
1499                 [MonoTODO]
1500                 public float ToSingle (IFormatProvider provider)
1501                 {
1502                         // FIXME: implement me
1503                         throw new NotImplementedException ();
1504                 }
1505
1506                 public override string ToString ()
1507                 {
1508                         return this;
1509                 }
1510
1511                 [MonoTODO]
1512                 public string ToString (IFormatProvider format)
1513                 {
1514                         // FIXME: implement me
1515                         throw new NotImplementedException ();
1516                 }
1517
1518                 [MonoTODO]
1519                 public object ToType (Type conversionType, IFormatProvider provider)
1520                 {
1521                         // FIXME: implement me
1522                         throw new NotImplementedException ();
1523                 }
1524
1525                 [CLSCompliant(false)][MonoTODO]
1526                 public ushort ToUInt16 (IFormatProvider provider)
1527                 {
1528                         // FIXME: implement me
1529                         throw new NotImplementedException ();
1530                 }
1531
1532                 [CLSCompliant(false)][MonoTODO]
1533                 public uint ToUInt32 (IFormatProvider provider)
1534                 {
1535                         // FIXME: implement me
1536                         throw new NotImplementedException ();
1537                 }
1538
1539                 [CLSCompliant(false)][MonoTODO]
1540                 public ulong ToUInt64 (IFormatProvider provider)
1541                 {
1542                         // FIXME: implement me
1543                         throw new NotImplementedException ();
1544                 }
1545
1546                 public string ToUpper ()
1547                 {
1548                         char[] str;
1549                         int i;
1550
1551                         String res = new String (length);
1552                         str = res.c_str;
1553                         for (i = 0; i < this.length; i++)
1554                                 str[i] = Char.ToUpper (this.c_str[i]);
1555
1556                         return res;
1557                 }
1558
1559                 [MonoTODO]
1560                 public string ToUpper (CultureInfo culture)
1561                 {
1562                         // FIXME: implement me
1563                         throw new NotImplementedException ();
1564                 }
1565
1566                 public string Trim ()
1567                 {
1568                         return Trim (null);
1569                 }
1570
1571                 public string Trim (params char[] trimChars)
1572                 {
1573                         int begin, end;
1574                         bool matches;
1575
1576                         matches = true;
1577                         for (begin = 0; matches && begin < this.length; begin++) {
1578                                 if (trimChars != null) {
1579                                         matches = false;
1580                                         foreach (char c in trimChars) {
1581                                                 matches = this.c_str[begin] == c;
1582                                                 if (matches)
1583                                                         break;
1584                                         }
1585                                 } else {
1586                                         matches = is_lwsp (this.c_str[begin]);
1587                                 }
1588                         }
1589
1590                         matches = true;
1591                         for (end = this.length - 1; matches && end > begin; end--) {
1592                                 if (trimChars != null) {
1593                                         matches = false;
1594                                         foreach (char c in trimChars) {
1595                                                 matches = this.c_str[end] == c;
1596                                                 if (matches)
1597                                                         break;
1598                                         }
1599                                 } else {
1600                                         matches = is_lwsp (this.c_str[end]);
1601                                 }
1602                         }
1603
1604                         if (begin >= end)
1605                                 return String.Empty;
1606
1607                         return Substring (begin, end - begin);
1608                 }
1609
1610                 public string TrimEnd (params char[] trimChars)
1611                 {
1612                         bool matches = true;
1613                         int end;
1614
1615                         for (end = this.length; end > 0; end--) {
1616                                 if (trimChars != null) {
1617                                         matches = false;
1618                                         foreach (char c in trimChars) {
1619                                                 matches = this.c_str[end] == c;
1620                                                 if (matches)
1621                                                         break;
1622                                         }
1623                                 } else {
1624                                         matches = is_lwsp (this.c_str[end]);
1625                                 }
1626                         }
1627
1628                         if (end == 0)
1629                                 return String.Empty;
1630
1631                         return Substring (0, end);
1632                 }
1633
1634                 public string TrimStart (params char[] trimChars)
1635                 {
1636                         bool matches = true;
1637                         int begin;
1638
1639                         for (begin = 0; matches && begin < this.length; begin++) {
1640                                 if (trimChars != null) {
1641                                         matches = false;
1642                                         foreach (char c in trimChars) {
1643                                                 matches = this.c_str[begin] == c;
1644                                                 if (matches)
1645                                                         break;
1646                                         }
1647                                 } else {
1648                                         matches = is_lwsp (this.c_str[begin]);
1649                                 }
1650                         }
1651
1652                         if (begin == this.length)
1653                                 return String.Empty;
1654
1655                         return Substring (begin, this.length - begin);
1656                 }
1657
1658                 // Operators
1659                 public static bool operator ==(string a, string b)
1660                 {
1661                         if ((object)a == null) {
1662                                 if ((object)b == null)
1663                                         return true;
1664                                 return false;
1665                         }
1666                         if ((object)b == null)
1667                                 return false;
1668         
1669                         if (a.length != b.length)
1670                                 return false;
1671
1672                         int l = a.length;
1673                         for (int i = 0; i < l; i++)
1674                                 if (a.c_str[i] != b.c_str[i])
1675                                         return false;
1676
1677                         return true;
1678                 }
1679
1680                 public static bool operator !=(string a, string b)
1681                 {
1682                         return !(a == b);
1683                 }
1684         }
1685 }