Fix and simplify QBasedComparer.

Make parsing of qvalues independent from a system's language setting and ensure that the comparison adheres to a descending order.
0.7.1-dev
Marck 2011-02-12 20:02:42 +01:00
parent c169a62f55
commit 19d3792278
1 changed files with 7 additions and 13 deletions

View File

@ -29,6 +29,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Security;
@ -557,34 +558,27 @@ namespace OpenSim.Framework
{
float qx = GetQ(x);
float qy = GetQ(y);
if (qx < qy)
return -1;
if (qx == qy)
return 0;
return 1;
return qy.CompareTo(qx); // descending order
}
private float GetQ(Object o)
{
// Example: image/png;q=0.9
float qvalue = 1F;
if (o is String)
{
string mime = (string)o;
string[] parts = mime.Split(new char[] { ';' });
string[] parts = mime.Split(';');
if (parts.Length > 1)
{
string[] kvp = parts[1].Split(new char[] { '=' });
string[] kvp = parts[1].Split('=');
if (kvp.Length == 2 && kvp[0] == "q")
{
float qvalue = 1F;
float.TryParse(kvp[1], out qvalue);
return qvalue;
}
float.TryParse(kvp[1], NumberStyles.Number, CultureInfo.InvariantCulture, out qvalue);
}
}
return 1F;
return qvalue;
}
}