2007-01-07 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Mime.cs
index 103ce5aae363a0941827e67476cd5ec4fb7f1d16..d4e1a3e067c40ce5ed16d437e8a5949d527c6f42 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006 Alexander Olk
 //
 // Authors:
 //
-//  Alexander Olk      xenomorph2@onlinehome.de
+//  Alexander Olk      alex.olk@googlemail.com
 //
 
 using System;
@@ -88,6 +88,8 @@ namespace System.Windows.Forms
                
                private int bytes_read = 0;
                
+               private bool mime_available = false;
+               
                public static NameValueCollection Aliases;
                public static NameValueCollection SubClasses;
                
@@ -101,12 +103,22 @@ namespace System.Windows.Forms
                
                private Mime( )
                {
+#if NET_2_0
+                       Aliases = new NameValueCollection (StringComparer.CurrentCultureIgnoreCase);
+                       SubClasses = new NameValueCollection (StringComparer.CurrentCultureIgnoreCase);
+                       GlobalPatternsShort = new NameValueCollection (StringComparer.CurrentCultureIgnoreCase);
+                       GlobalPatternsLong = new NameValueCollection (StringComparer.CurrentCultureIgnoreCase);
+                       GlobalLiterals = new NameValueCollection (StringComparer.CurrentCultureIgnoreCase);
+                       GlobalSufPref = new NameValueCollection (StringComparer.CurrentCultureIgnoreCase);
+#else
                        Aliases = new NameValueCollection (new CaseInsensitiveHashCodeProvider (), new Comparer (System.Globalization.CultureInfo.CurrentUICulture));
                        SubClasses = new NameValueCollection (new CaseInsensitiveHashCodeProvider (), new Comparer (System.Globalization.CultureInfo.CurrentUICulture));
                        GlobalPatternsShort = new NameValueCollection (new CaseInsensitiveHashCodeProvider (), new Comparer (System.Globalization.CultureInfo.CurrentUICulture));
                        GlobalPatternsLong = new NameValueCollection (new CaseInsensitiveHashCodeProvider (), new Comparer (System.Globalization.CultureInfo.CurrentUICulture));
                        GlobalLiterals = new NameValueCollection (new CaseInsensitiveHashCodeProvider (), new Comparer (System.Globalization.CultureInfo.CurrentUICulture));
                        GlobalSufPref = new NameValueCollection (new CaseInsensitiveHashCodeProvider (), new Comparer (System.Globalization.CultureInfo.CurrentUICulture));
+#endif
+                       
                        Matches80Plus = new ArrayList ();
                        MatchesBelow80 = new ArrayList ();
                        
@@ -115,6 +127,14 @@ namespace System.Windows.Forms
                        
                        if (buffer_length != -1) {
                                buffer = new byte[ buffer_length ];
+                               mime_available = true;
+                       }
+               }
+               
+               public static bool MimeAvailable
+               {
+                       get {
+                               return Instance.mime_available;
                        }
                }
                
@@ -480,18 +500,20 @@ namespace System.Windows.Forms
                                
                                if ( extension.Length != 0 )
                                {
-                                       global_result = GlobalPatternsShort[ extension ];
+                                       string global_result_tmp = GlobalPatternsShort[ extension ];
                                        
-                                       if ( global_result != null )
+                                       if ( global_result_tmp != null )
                                        {
+                                               global_result = global_result_tmp;
                                                CheckGlobalResult( );
                                                return true;
                                        }
                                        
-                                       global_result = GlobalPatternsShort[ extension.ToLower( ) ];
+                                       global_result_tmp = GlobalPatternsShort[ extension.ToLower( ) ];
                                        
-                                       if ( global_result != null )
+                                       if ( global_result_tmp != null )
                                        {
+                                               global_result = global_result_tmp;
                                                CheckGlobalResult( );
                                                return true;
                                        }
@@ -505,7 +527,7 @@ namespace System.Windows.Forms
                                
                                if ( key[0] == '*' )
                                {
-                                       if (FastEndsWidth(filename, key.Replace( "*", "" )))
+                                       if (FastEndsWidth(filename, key.Replace( "*", String.Empty )))
                                        {
                                                global_result = GlobalSufPref[ i ];
                                                CheckGlobalResult( );
@@ -514,7 +536,7 @@ namespace System.Windows.Forms
                                }
                                else
                                {
-                                       if ( FastStartsWith(filename, key.Replace( "*", "" ) ) )
+                                       if ( FastStartsWith(filename, key.Replace( "*", String.Empty ) ) )
                                        {
                                                global_result = GlobalSufPref[ i ];
                                                CheckGlobalResult( );
@@ -720,7 +742,7 @@ namespace System.Windows.Forms
                        {
                                index += 13; // Length of string "Content-type:"
                                
-                               global_result = "";
+                               global_result = String.Empty;
                                
                                while ( search_string[ index ] != ';' )
                                {
@@ -840,7 +862,7 @@ namespace System.Windows.Forms
                                                // indent
                                                char c;
                                                if (br.PeekChar () != '>') {
-                                                       string indent_string = "";
+                                                       string indent_string = String.Empty;
                                                        while (true) {
                                                                if (br.PeekChar () == '>')
                                                                        break;
@@ -1076,7 +1098,7 @@ namespace System.Windows.Forms
                
                private int ReadValue ()
                {
-                       string result_string = "";
+                       string result_string = String.Empty;
                        int result = 0;
                        char c;
                        
@@ -1096,7 +1118,7 @@ namespace System.Windows.Forms
                private string ReadPriorityAndMimeType (ref int priority)
                {
                        if (br.ReadChar () == '[') {
-                               string priority_string = "";
+                               string priority_string = String.Empty;
                                while (true) {
                                        char c = br.ReadChar ();
                                        if (c == ':')
@@ -1106,7 +1128,7 @@ namespace System.Windows.Forms
                                
                                priority = System.Convert.ToInt32 (priority_string);
                                
-                               string mime_type_result = "";
+                               string mime_type_result = String.Empty;
                                while (true) {
                                        char c = br.ReadChar ();
                                        if (c == ']')