**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / System.Globalization / TextInfo.cs
blobfab41ac0d227a9d927ce21c645fb8dfa362d2abd
1 //
2 // System.Globalization.TextInfo.cs
3 //
4 // Author:
5 // Dick Porter (dick@ximian.com)
6 // Duncan Mak (duncan@ximian.com)
7 //
8 // (C) 2002 Ximian, Inc.
9 //
10 // TODO:
11 // Missing the various code page mappings.
12 // Missing the OnDeserialization implementation.
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 //
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 //
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System;
36 using System.Globalization;
37 using System.Runtime.Serialization;
39 namespace System.Globalization {
41 [Serializable]
42 public class TextInfo: IDeserializationCallback
44 int m_win32LangID;
45 int m_nDataItem;
46 bool m_useUserOverride;
48 [NonSerialized]
49 CultureInfo ci;
51 internal TextInfo ()
55 internal TextInfo (CultureInfo ci, int lcid)
57 this.m_win32LangID = lcid;
58 this.ci = ci;
61 [MonoTODO]
62 public virtual int ANSICodePage
64 get {
65 return 0;
69 [MonoTODO]
70 public virtual int EBCDICCodePage
72 get {
73 return 0;
77 [MonoTODO]
78 public virtual string ListSeparator
80 get {
81 return ",";
85 [MonoTODO]
86 public virtual int MacCodePage
88 get {
89 return 0;
93 [MonoTODO]
94 public virtual int OEMCodePage
96 get {
97 return 0;
101 public override bool Equals (object obj)
103 if (obj == null)
104 return false;
105 TextInfo other = obj as TextInfo;
106 if (other == null)
107 return false;
108 if (other.m_win32LangID != m_win32LangID)
109 return false;
110 if (other.ci != ci)
111 return false;
112 return true;
115 public override int GetHashCode()
117 return (m_win32LangID);
120 public virtual char ToLower(char c)
122 return Char.ToLower (c);
125 public virtual string ToLower(string str)
127 if(str==null)
128 throw new ArgumentNullException("string is null");
130 return str.ToLower (ci);
133 public override string ToString()
135 return "TextInfo - " + m_win32LangID;
138 public string ToTitleCase (string str)
140 if(str == null)
141 throw new ArgumentNullException("string is null");
143 Text.StringBuilder s = new Text.StringBuilder ();
144 bool space_seen = true;
146 for (int i = 0; i < str.Length; i ++){
147 char c = str [i];
148 if (Char.IsLetter (c)){
149 if (space_seen)
150 s.Append (Char.ToUpper (c, ci));
151 else
152 s.Append (Char.ToLower (c, ci));
153 space_seen = false;
154 } else {
155 s.Append (c);
156 if (Char.IsWhiteSpace (c))
157 space_seen = true;
161 return s.ToString ();
164 public virtual char ToUpper (char c)
166 return Char.ToUpper (c, ci);
169 public virtual string ToUpper (string str)
171 if(str==null)
172 throw new ArgumentNullException("string is null");
174 return str.ToUpper (ci);
177 /* IDeserialization interface */
178 [MonoTODO]
179 void IDeserializationCallback.OnDeserialization(object sender)