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;
21 public struct Char : IComparable { //, IFormattable, IConvertible {
22 public const char MaxValue = (char) 0xffff;
23 public const char MinValue = (char) 0;
25 // VES needs to know about value. public is workaround
26 // so source will compile
29 public int CompareTo (object v)
31 if (!(v is System.Byte))
32 throw new ArgumentException ("Value is not a System.Byte");
34 return value - ((byte) v);
37 public override bool Equals (object o)
39 if (!(o is System.Byte))
42 return ((byte) o) == value;
45 public override int GetHashCode ()
50 public static double GetNumericValue (char c)
52 if ((c >= 48) && (c <= 57))
53 return (double) (c - '0');
57 public static double GetNumericValue (string str, int index)
60 throw new ArgumentNullException ("Str is a null reference");
62 if (index < 0 || index >= str.Length)
63 throw new ArgumentOutOfRangeException
64 ("The value of index is less than zero, or greater than or equal to the length of str");
66 return GetNumericValue (str[index]);
69 public static UnicodeCategory GetUnicodeCategory (char c)
72 return UnicodeCategory.OtherSymbol;
75 public static UnicodeCategory GetUnicodeCategory (string str, int index) {
77 throw new ArgumentNullException ("Str is a null reference");
79 if (index < 0 || index >= str.Length)
80 throw new ArgumentOutOfRangeException
81 ("The value of index is less than zero, or greater than or equal to the length of str");
83 return GetUnicodeCategory (str[index]);
86 public static bool IsControl (char c)
88 // TODO: Make me Unicode aware
89 return ((c > 1) && (c < 32));
92 public static bool IsControl (string str, int index)
95 throw new ArgumentNullException ("Str is a null reference");
97 if (index < 0 || index >= str.Length)
98 throw new ArgumentOutOfRangeException
99 ("The value of index is less than zero, or greater than or equal to the length of str");
101 return IsControl (str[index]);
104 public static bool IsDigit (char c)
106 return ((c >= '0') && (c <= '9'));
109 public static bool IsDigit (string str, int index)
112 throw new ArgumentNullException ("Str is a null reference");
114 if (index < 0 || index >= str.Length)
115 throw new ArgumentOutOfRangeException
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 public static bool IsLetter (char c)
123 // TODO: Make me Unicode aware
124 return ((c >= 65) && (c <= 126));
127 public static bool IsLetter (string str, int index)
130 throw new ArgumentNullException ("Str is a null reference");
132 if (index < 0 || index >= str.Length)
133 throw new ArgumentOutOfRangeException
134 ("The value of index is less than zero, or greater than or equal to the length of str");
136 return IsLetter (str[index]);
139 public static bool IsLetterOrDigit (char c)
141 // TODO: Implement me
145 public static bool IsLetterOrDigit (string str, int index)
148 throw new ArgumentNullException ("Str is a null reference");
150 if (index < 0 || index >= str.Length)
151 throw new ArgumentOutOfRangeException
152 ("The value of index is less than zero, or greater than or equal to the length of str");
154 return IsLetterOrDigit (str[index]);
157 public static bool IsLower (char c)
159 // TODO: Implement me
163 public static bool IsLower (string str, int index)
166 throw new ArgumentNullException ("Str is a null reference");
168 if (index < 0 || index >= str.Length)
169 throw new ArgumentOutOfRangeException
170 ("The value of index is less than zero, or greater than or equal to the length of str");
172 return IsLower (str[index]);
175 public static bool IsNumber (char c)
177 // TODO: Implement me
181 public static bool IsNumber (string str, int index)
184 throw new ArgumentNullException ("Str is a null reference");
186 if (index < 0 || index >= str.Length)
187 throw new ArgumentOutOfRangeException
188 ("The value of index is less than zero, or greater than or equal to the length of str");
190 return IsNumber (str[index]);
193 public static bool IsPunctuation (char c)
195 // TODO: Implement me
199 public static bool IsPunctuation (string str, int index)
202 throw new ArgumentNullException ("Str is a null reference");
204 if (index < 0 || index >= str.Length)
205 throw new ArgumentOutOfRangeException
206 ("The value of index is less than zero, or greater than or equal to the length of str");
208 return IsPunctuation (str[index]);
211 public static bool IsSeparator (char c)
213 // TODO: Implement me
217 public static bool IsSeparator (string str, int index)
220 throw new ArgumentNullException ("Str is a null reference");
222 if (index < 0 || index >= str.Length)
223 throw new ArgumentOutOfRangeException
224 ("The value of index is less than zero, or greater than or equal to the length of str");
226 return IsSeparator (str[index]);
229 public static bool IsSurrogate (char c)
231 // TODO: Implement me
235 public static bool IsSurrogate (string str, int index)
238 throw new ArgumentNullException ("Str is a null reference");
240 if (index < 0 || index >= str.Length)
241 throw new ArgumentOutOfRangeException
242 ("The value of index is less than zero, or greater than or equal to the length of str");
244 return IsSurrogate (str[index]);
247 public static bool IsSymbol (char c)
249 // TODO: Implement me
253 public static bool IsSymbol (string str, int index)
256 throw new ArgumentNullException ("Str is a null reference");
258 if (index < 0 || index >= str.Length)
259 throw new ArgumentOutOfRangeException
260 ("The value of index is less than zero, or greater than or equal to the length of str");
262 return IsSymbol (str[index]);
265 public static bool IsUpper (char c)
267 // TODO: Implement me
271 public static bool IsUpper (string str, int index)
274 throw new ArgumentNullException ("Str is a null reference");
276 if (index < 0 || index >= str.Length)
277 throw new ArgumentOutOfRangeException
278 ("The value of index is less than zero, or greater than or equal to the length of str");
280 return IsUpper (str[index]);
283 public static bool IsWhiteSpace (char c)
285 // TODO: Implement me
289 public static bool IsWhiteSpace (string str, int index)
292 throw new ArgumentNullException ("Str is a null reference");
294 if (index < 0 || index >= str.Length)
295 throw new ArgumentOutOfRangeException
296 ("The value of index is less than zero, or greater than or equal to the length of str");
298 return IsWhiteSpace (str[index]);
301 public static char Parse (string str)
303 // TODO: Implement me
307 public static char ToLower (char c)
309 // TODO: make me unicode aware
310 return (c >= 'A' && c <= 'Z') ? (char) (c + 33) : c;
313 public static char ToUpper (char c)
315 // TODO: make me unicode aware
316 return (char) ((c >= 'a' && c <= 'z') ? c - 33 : c);
319 public override string ToString ()
321 // LAMESPEC: ECMA draft lists this as returning ToString (null),
322 // However it doesn't list another ToString() method.
323 return ToString (null);
326 public string ToString (IFormatProvider fp)
328 // LAMESPEC: ECMA draft doesn't say Char implements IFormattable
332 // =========== IConvertible Methods =========== //
334 public TypeCode GetTypeCode ()
336 return TypeCode.Byte;