diff options
author | Marck | 2011-02-12 20:02:42 +0100 |
---|---|---|
committer | Marck | 2011-02-13 11:11:49 +0100 |
commit | 19d3792278643af0d45dd09f338a33ad78a138b7 (patch) | |
tree | 8d44938f58c24f998a5a80562e76c534c073c287 /OpenSim | |
parent | Typo (diff) | |
download | opensim-SC-19d3792278643af0d45dd09f338a33ad78a138b7.zip opensim-SC-19d3792278643af0d45dd09f338a33ad78a138b7.tar.gz opensim-SC-19d3792278643af0d45dd09f338a33ad78a138b7.tar.bz2 opensim-SC-19d3792278643af0d45dd09f338a33ad78a138b7.tar.xz |
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.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index d731ac5..1feeeb3 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Collections.Specialized; | 31 | using System.Collections.Specialized; |
32 | using System.Globalization; | ||
32 | using System.IO; | 33 | using System.IO; |
33 | using System.Net; | 34 | using System.Net; |
34 | using System.Net.Security; | 35 | using System.Net.Security; |
@@ -557,34 +558,27 @@ namespace OpenSim.Framework | |||
557 | { | 558 | { |
558 | float qx = GetQ(x); | 559 | float qx = GetQ(x); |
559 | float qy = GetQ(y); | 560 | float qy = GetQ(y); |
560 | if (qx < qy) | 561 | return qy.CompareTo(qx); // descending order |
561 | return -1; | ||
562 | if (qx == qy) | ||
563 | return 0; | ||
564 | return 1; | ||
565 | } | 562 | } |
566 | 563 | ||
567 | private float GetQ(Object o) | 564 | private float GetQ(Object o) |
568 | { | 565 | { |
569 | // Example: image/png;q=0.9 | 566 | // Example: image/png;q=0.9 |
570 | 567 | ||
568 | float qvalue = 1F; | ||
571 | if (o is String) | 569 | if (o is String) |
572 | { | 570 | { |
573 | string mime = (string)o; | 571 | string mime = (string)o; |
574 | string[] parts = mime.Split(new char[] { ';' }); | 572 | string[] parts = mime.Split(';'); |
575 | if (parts.Length > 1) | 573 | if (parts.Length > 1) |
576 | { | 574 | { |
577 | string[] kvp = parts[1].Split(new char[] { '=' }); | 575 | string[] kvp = parts[1].Split('='); |
578 | if (kvp.Length == 2 && kvp[0] == "q") | 576 | if (kvp.Length == 2 && kvp[0] == "q") |
579 | { | 577 | float.TryParse(kvp[1], NumberStyles.Number, CultureInfo.InvariantCulture, out qvalue); |
580 | float qvalue = 1F; | ||
581 | float.TryParse(kvp[1], out qvalue); | ||
582 | return qvalue; | ||
583 | } | ||
584 | } | 578 | } |
585 | } | 579 | } |
586 | 580 | ||
587 | return 1F; | 581 | return qvalue; |
588 | } | 582 | } |
589 | } | 583 | } |
590 | 584 | ||