Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 19d3792278643af0d45dd09f338a33ad78a138b7 1 parent c169a62
@Marck00 Marck00 authored
Showing with 7 additions and 13 deletions.
  1. +7 −13 OpenSim/Framework/WebUtil.cs
View
20 OpenSim/Framework/WebUtil.cs
@@ -29,6 +29,7 @@
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 @@ public int Compare(Object x, Object y)
{
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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.