+//
+// SortKeyBuffer.cs : buffer implementation for GetSortKey()
+//
+// Author:
+// Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
using System.IO;
using System.Globalization;
l1b = l2b = l3b = l4sb = l4tb = l4kb = l4wb = l5b = null;
}
- internal void Initialize (CompareOptions options, string s, bool frenchSort)
+ internal void Initialize (CompareOptions options, int lcid, string s, bool frenchSort)
{
+ this.source = s;
+ this.lcid = lcid;
this.options = options;
int len = s.Length;
processLevel2 = (options & CompareOptions.IgnoreNonSpace) == 0;
// non-primary diacritical weight is added to that of
// the previous character (and does not reset level 3
// weight).
- if (processLevel2 &&category == 1 && l1 > 0) {
+ if (processLevel2 && category == 1 && l1 > 0) {
lv2 = (byte) (lv2 + l2b [--l2]);
lv3 = l3b [--l3];
}
// If it strictly matches to Windows, offsetValue is always l2.
int offsetValue = l2 - level5LastPos;
// If it strictly matches ti Windows, no 0xFF here.
- for (; offsetValue > 8064; offsetValue -= 8064)
+ for (; offsetValue > 8192; offsetValue -= 8192)
AppendBufferPrimitive (0xFF, ref l5b, ref l5);
#else
// LAMESPEC: Windows cannot compute lv5 values for
// those string that has length larger than 8064.
// (It reminds me of SQL Server varchar length).
- int offsetValue = l2 % 8064;
+ int offsetValue = (l2 + 1) % 8192;
#endif
- AppendBufferPrimitive ((byte) ((offsetValue / 63) * 4 + 0x80), ref l5b, ref l5);
- AppendBufferPrimitive ((byte) (offsetValue % 63 * 4 + 7), ref l5b, ref l5);
+ AppendBufferPrimitive ((byte) ((offsetValue / 64) + 0x80), ref l5b, ref l5);
+ AppendBufferPrimitive ((byte) (offsetValue % 64 * 4 + 3), ref l5b, ref l5);
level5LastPos = l2;
public SortKey GetResult ()
{
- if (frenchSort && !frenchSorted) {
+ if (frenchSort && !frenchSorted && l2b != null) {
int i = 0;
for (; i < l2b.Length; i++)
if (l2b [i] == 0)
l2 = GetOptimizedLength (l2b, l2, 2);
l3 = GetOptimizedLength (l3b, l3, 2);
- bool hasJapaneseWeight = (l4s > 0);
+ bool hasJapaneseWeight = (l4s > 0); // snapshot before being optimized
l4s = GetOptimizedLength (l4sb, l4s, 0xE4);
l4t = GetOptimizedLength (l4tb, l4t, 3);
l4k = GetOptimizedLength (l4kb, l4k, 0xE4);