5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 // Note about the ToString()'s. ECMA says there's only a ToString() method,
11 // BUT it is just a wrapper for ToString(null). However there is no other ToString
12 // in the docs. Turning to the NET framework sdk reveals that there is a
13 // ToString(formatprovider) method, as well as a 'static ToString (char c)' method,
14 // which appears to just be a Convert.ToString(char c) type method. ECMA also
15 // doesn't list this class as implementing IFormattable.
17 using System.Globalization;
18 using System.Runtime.CompilerServices;
22 public struct Char : IComparable { //, IFormattable, IConvertible {
23 public const char MaxValue = (char) 0xffff;
24 public const char MinValue = (char) 0;
26 // VES needs to know about value. public is workaround
27 // so source will compile
30 public int CompareTo (object v)
35 if (!(v is System.Char))
36 throw new ArgumentException (Locale.GetText ("Value is not a System.Char"));
48 public override bool Equals (object o)
50 if (!(o is System.Char))
53 return ((Char) o) == value;
56 public override int GetHashCode ()
61 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
62 public static extern double GetNumericValue (char c);
64 public static double GetNumericValue (string str, int index)
67 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
69 if (index < 0 || index >= str.Length)
70 throw new ArgumentOutOfRangeException (Locale.GetText (
71 "The value of index is less than zero, or greater than or equal to the length of str"));
74 return GetNumericValue (str[index]);
77 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
78 public static extern UnicodeCategory GetUnicodeCategory (char c);
80 public static UnicodeCategory GetUnicodeCategory (string str, int index) {
82 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
84 if (index < 0 || index >= str.Length)
85 throw new ArgumentOutOfRangeException (Locale.GetText ("The value of index is less "+
86 "than zero, or greater than or equal to the length of str"));
88 return GetUnicodeCategory (str[index]);
91 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
92 public static extern bool IsControl (char c);
94 public static bool IsControl (string str, int index)
97 throw new ArgumentNullException (Locale.GetText ("Str is a null reference"));
99 if (index < 0 || index >= str.Length)
100 throw new ArgumentOutOfRangeException (Locale.GetText (
101 "The value of index is less than zero, or greater than or equal to the length of str"));
103 return IsControl (str[index]);
106 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
107 public static extern bool IsDigit (char c);
109 public static bool IsDigit (string str, int index)
112 throw new ArgumentNullException (Locale.GetText ("Str is a null reference"));
114 if (index < 0 || index >= str.Length)
115 throw new ArgumentOutOfRangeException (Locale.GetText (
116 "The value of index is less than zero, or greater than or equal to the length of str"));
118 return IsDigit (str[index]);
121 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
122 public static extern bool IsLetter (char c);
124 public static bool IsLetter (string str, int index)
127 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
129 if (index < 0 || index >= str.Length)
130 throw new ArgumentOutOfRangeException (Locale.GetText (
131 "The value of index is less than zero, or greater than or equal to the length of str"));
133 return IsLetter (str[index]);
136 public static bool IsLetterOrDigit (char c)
138 if (IsLetter (c) == false && IsDigit (c) == false)
144 public static bool IsLetterOrDigit (string str, int index)
147 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
149 if (index < 0 || index >= str.Length)
150 throw new ArgumentOutOfRangeException (Locale.GetText (
151 "The value of index is less than zero, or greater than or equal to the length of str"));
153 return IsLetterOrDigit (str[index]);
156 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
157 public static extern bool IsLower (char c);
159 public static bool IsLower (string str, int index)
162 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
164 if (index < 0 || index >= str.Length)
165 throw new ArgumentOutOfRangeException (Locale.GetText (
166 "The value of index is less than zero, or greater than or equal to the length of str"));
168 return IsLower (str[index]);
171 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
172 public static extern bool IsNumber (char c);
174 public static bool IsNumber (string str, int index)
177 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
179 if (index < 0 || index >= str.Length)
180 throw new ArgumentOutOfRangeException (Locale.GetText (
181 "The value of index is less than zero, or greater than or equal to the length of str"));
183 return IsNumber (str[index]);
186 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
187 public static extern bool IsPunctuation (char c);
189 public static bool IsPunctuation (string str, int index)
192 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
194 if (index < 0 || index >= str.Length)
195 throw new ArgumentOutOfRangeException (Locale.GetText (
196 "The value of index is less than zero, or greater than or equal to the length of str"));
198 return IsPunctuation (str[index]);
201 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
202 public static extern bool IsSeparator (char c);
204 public static bool IsSeparator (string str, int index)
207 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
209 if (index < 0 || index >= str.Length)
210 throw new ArgumentOutOfRangeException (Locale.GetText (
211 "The value of index is less than zero, or greater than or equal to the length of str"));
213 return IsSeparator (str[index]);
216 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
217 public static extern bool IsSurrogate (char c);
219 public static bool IsSurrogate (string str, int index)
222 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
224 if (index < 0 || index >= str.Length)
225 throw new ArgumentOutOfRangeException (Locale.GetText (
226 "The value of index is less than zero, or greater than or equal to the length of str"));
228 return IsSurrogate (str[index]);
231 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
232 public static extern bool IsSymbol (char c);
234 public static bool IsSymbol (string str, int index)
237 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
239 if (index < 0 || index >= str.Length)
240 throw new ArgumentOutOfRangeException (Locale.GetText (
241 "The value of index is less than zero, or greater than or equal to the length of str"));
243 return IsSymbol (str[index]);
246 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
247 public static extern bool IsUpper (char c);
249 public static bool IsUpper (string str, int index)
252 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
254 if (index < 0 || index >= str.Length)
255 throw new ArgumentOutOfRangeException (Locale.GetText (
256 "The value of index is less than zero, or greater than or equal to the length of str"));
258 return IsUpper (str[index]);
261 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
262 public static extern bool IsWhiteSpace (char c);
264 public static bool IsWhiteSpace (string str, int index)
267 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
269 if (index < 0 || index >= str.Length)
270 throw new ArgumentOutOfRangeException (Locale.GetText (
271 "The value of index is less than zero, or greater than or equal to the length of str"));
273 return IsWhiteSpace (str[index]);
276 public static char Parse (string str)
279 throw new ArgumentNullException (Locale.GetText ("str is a null reference"));
281 int len = str.Length;
284 throw new ArgumentNullException ();
286 throw new FormatException ();
291 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
292 public static extern char ToLower (char c);
294 [MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
295 public static extern char ToUpper (char c);
297 public override string ToString ()
299 // LAMESPEC: ECMA draft lists this as returning ToString (null),
300 // However it doesn't list another ToString() method.
301 return new String (value, 1);
304 public string ToString (IFormatProvider fp)
306 // LAMESPEC: ECMA draft doesn't say Char implements IFormattable
307 return new String (value, 1);
310 // =========== IConvertible Methods =========== //
312 public TypeCode GetTypeCode ()
314 return TypeCode.Char;