// 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;
private int bytes_read = 0;
+ private bool mime_available = false;
+
public static NameValueCollection Aliases;
public static NameValueCollection SubClasses;
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 ();
if (buffer_length != -1) {
buffer = new byte[ buffer_length ];
+ mime_available = true;
+ }
+ }
+
+ public static bool MimeAvailable
+ {
+ get {
+ return Instance.mime_available;
}
}
GoByFileName( );
// }
-// if ( !mime_file_cache.ContainsKey( current_file_name ) )
mime_file_cache.Add( current_file_name, global_result );
- // not tested
- if ( mime_file_cache.Count > mime_file_cache_max_size )
- {
- IEnumerator enumerator = mime_file_cache.GetEnumerator( );
+ if (mime_file_cache.Count > mime_file_cache_max_size) {
+ IEnumerator enumerator = mime_file_cache.GetEnumerator ();
- for ( int i = 0; i < mime_file_cache_max_size - 1000; i++ )
- {
- mime_file_cache.Remove( enumerator.Current.ToString( ) );
+ int counter = mime_file_cache_max_size - 1000;
+
+ while (enumerator.MoveNext ()) {
+ mime_file_cache.Remove (enumerator.Current.ToString ());
+ counter--;
+
+ if (counter == 0)
+ break;
}
}
}
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;
}
if ( key[0] == '*' )
{
- if (FastEndsWidth(filename, key.Replace( "*", "" )))
+ if (FastEndsWidth(filename, key.Replace( "*", String.Empty )))
{
global_result = GlobalSufPref[ i ];
CheckGlobalResult( );
}
else
{
- if ( FastStartsWith(filename, key.Replace( "*", "" ) ) )
+ if ( FastStartsWith(filename, key.Replace( "*", String.Empty ) ) )
{
global_result = GlobalSufPref[ i ];
CheckGlobalResult( );
{
index += 13; // Length of string "Content-type:"
- global_result = "";
+ global_result = String.Empty;
while ( search_string[ index ] != ';' )
{
// indent
char c;
if (br.PeekChar () != '>') {
- string indent_string = "";
+ string indent_string = String.Empty;
while (true) {
if (br.PeekChar () == '>')
break;
private int ReadValue ()
{
- string result_string = "";
+ string result_string = String.Empty;
int result = 0;
char c;
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 == ':')
priority = System.Convert.ToInt32 (priority_string);
- string mime_type_result = "";
+ string mime_type_result = String.Empty;
while (true) {
char c = br.ReadChar ();
if (c == ']')