lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mhern...@apache.org
Subject [Lucene.Net] svn commit: r1162468 [1/2] - in /incubator/lucene.net/branches/Lucene.Net_4e: packages/PortableLibrary/ src/Lucene.Net/ src/Lucene.Net/Support/ src/Lucene.Net/Util/
Date Sun, 28 Aug 2011 02:12:34 GMT
Author: mherndon
Date: Sun Aug 28 02:12:33 2011
New Revision: 1162468

URL: http://svn.apache.org/viewvc?rev=1162468&view=rev
Log:
updating the portable library assemblies to the latest update in June. Working towards porting BytesRef which requires CharsRef and UnicodeUtil as well as creating an interface that suppliment's java's CharSequence interface. The work for the ICharSequence includes wrapper classes for string, char[], list of char, and ienumerable of char.

Added:
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Windows.dll
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharArrayCharSequenceWrapper.cs
      - copied, changed from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharEnumerableCharSequenceWrapper.cs
      - copied, changed from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharListCharSequenceWrapper.cs
      - copied, changed from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharSequenceExtensions.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/EnumerableExtensions.cs
      - copied, changed from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/ICharSequence.cs
      - copied, changed from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringCharSequenceWrapper.cs
      - copied, changed from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/CharsRef.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/UnicodeUtil.cs
Modified:
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ComponentModel.Composition.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Core.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Net.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Runtime.Serialization.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ServiceModel.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.Serialization.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.dll
    incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/mscorlib.dll
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/ArrayUtil.cs
    incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ComponentModel.Composition.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ComponentModel.Composition.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ComponentModel.Composition.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ComponentModel.Composition.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Core.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Core.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Core.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Core.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Net.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Net.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Net.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Net.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Runtime.Serialization.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Runtime.Serialization.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Runtime.Serialization.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Runtime.Serialization.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ServiceModel.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ServiceModel.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ServiceModel.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.ServiceModel.dll Sun Aug 28 02:12:33 2011 differ

Added: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Windows.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Windows.dll?rev=1162468&view=auto
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Windows.dll (added) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Windows.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.Serialization.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.Serialization.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.Serialization.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.Serialization.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.Xml.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/System.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/mscorlib.dll
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/mscorlib.dll?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
Files incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/mscorlib.dll (original) and incubator/lucene.net/branches/Lucene.Net_4e/packages/PortableLibrary/mscorlib.dll Sun Aug 28 02:12:33 2011 differ

Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj Sun Aug 28 02:12:33 2011
@@ -74,10 +74,17 @@
     <Compile Include="Index\TermsHashPerField.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Support\BaseDictionaryOfTKeyTValue.cs" />
+    <Compile Include="Support\CharArrayCharSequenceWrapper.cs" />
+    <Compile Include="Support\CharEnumerableCharSequenceWrapper.cs" />
+    <Compile Include="Support\CharListCharSequenceWrapper.cs" />
+    <Compile Include="Support\CharSequenceExtensions.cs" />
+    <Compile Include="Support\EnumerableExtensions.cs" />
+    <Compile Include="Support\ICharSequence.cs" />
     <Compile Include="Support\ICloneable.cs" />
     <Compile Include="Support\DictionaryExtensions.cs" />
     <Compile Include="Support\ICloneableOfT.cs" />
     <Compile Include="Support\ICloseable.cs" />
+    <Compile Include="Support\StringCharSequenceWrapper.cs" />
     <Compile Include="Support\StringExtensions.cs" />
     <Compile Include="Support\Threading\LocalDataStoreSlot.cs" />
     <Compile Include="Support\Threading\ThreadData.cs" />
@@ -93,8 +100,10 @@
     <Compile Include="Util\AttributeSource.cs" />
     <Compile Include="Util\AttributeSourceState.cs" />
     <Compile Include="Util\BytesRef.cs" />
+    <Compile Include="Util\CharsRef.cs" />
     <Compile Include="Util\IAttribute.cs" />
     <Compile Include="Util\RamUsageEstimator.cs" />
+    <Compile Include="Util\UnicodeUtil.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="Lucene.Net.snk" />

Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharArrayCharSequenceWrapper.cs (from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharArrayCharSequenceWrapper.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharArrayCharSequenceWrapper.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs&r1=1157316&r2=1162468&rev=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharArrayCharSequenceWrapper.cs Sun Aug 28 02:12:33 2011
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-// <copyright company="Apache" file="BytesRef.cs">
+// <copyright company="Apache" file="CharArrayCharSequenceWrapper.cs">
 //
 //      Licensed to the Apache Software Foundation (ASF) under one or more
 //      contributor license agreements.  See the NOTICE file distributed with
@@ -19,7 +19,7 @@
 // </copyright>
 // -----------------------------------------------------------------------
 
-namespace Lucene.Net.Util
+namespace Lucene.Net.Support
 {
     using System;
     using System.Collections.Generic;
@@ -27,88 +27,88 @@ namespace Lucene.Net.Util
     using System.Text;
 
     /// <summary>
-    /// TODO: port
-    /// this class has methods that are not valid to void FxCop.
+    /// Creates a <see cref="ICharSequence"/> wrapper for a <c>char[]</c>. 
     /// </summary>
-    public sealed class BytesRef : IComparable<BytesRef>
+    internal class CharArrayCharSequenceWrapper : ICharSequence
     {
-        private byte[] reference = new byte[] { };
+        private readonly char[] value;
 
         /// <summary>
-        /// Implements the operator !=.
+        /// Initializes a new instance of the <see cref="CharArrayCharSequenceWrapper"/> class.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator !=(BytesRef left, BytesRef right)
+        /// <param name="value">The value.</param>
+        public CharArrayCharSequenceWrapper(char[] value)
         {
-            return left.reference != right.reference;
+            this.value = value;
         }
 
         /// <summary>
-        /// Implements the operator ==.
+        /// Gets the length.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator ==(BytesRef left, BytesRef right)
+        /// <value>The length.</value>
+        public int Length
         {
-            return left.reference == right.reference;
+            get { return this.value.Length; }
         }
 
         /// <summary>
-        /// Implements the operator &lt;.
+        /// Finds the <see cref="char"/> at the specified index.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator <(BytesRef left, BytesRef right)
+        /// <param name="index">The index.</param>
+        /// <returns>An instance of <see cref="Char"/>.</returns>
+        public char CharAt(int index)
         {
-            return left.reference.Length < right.reference.Length;
+            return this.value[index];
         }
 
         /// <summary>
-        /// Implements the operator &gt;.
+        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator >(BytesRef left, BytesRef right)
+        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+        /// <returns>
+        ///    <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// </returns>
+        public override bool Equals(object obj)
         {
-            return left.reference.Length < right.reference.Length;
+            return CharSequenceExtensions.IsCharSequenceEqual(this, obj);
         }
 
         /// <summary>
-        /// Compares this instance to the other <see cref="BytesRef"/> instance.
+        /// Returns a hash code for this instance.
         /// </summary>
-        /// <param name="other">The other.</param>
-        /// <returns>An instance of <see cref="Int32"/>.</returns>
-        public int CompareTo(BytesRef other)
+        /// <returns>
+        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// </returns>
+        public override int GetHashCode()
         {
-            throw new NotImplementedException();
+            return CharSequenceExtensions.CreateHashCode(this);
         }
 
         /// <summary>
-        /// Returns a hash code for this instance.
+        /// Gets the subset sequence of characters from the current sequence.
         /// </summary>
+        /// <param name="start">The start.</param>
+        /// <param name="end">The end.</param>
         /// <returns>
-        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// An instance of <see cref="ICharSequence"/>.
         /// </returns>
-        public override int GetHashCode()
+        public ICharSequence SubSequence(int start, int end)
         {
-            return this.reference.GetHashCode();
+           char[] copy = new char[end - start];
+           Array.Copy(this.value, start, copy, 0, end);
+
+           return new CharArrayCharSequenceWrapper(copy);
         }
 
         /// <summary>
-        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+        /// Returns a <see cref="System.String"/> that represents this instance.
         /// </summary>
-        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
         /// <returns>
-        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// A <see cref="System.String"/> that represents this instance.
         /// </returns>
-        public override bool Equals(object obj)
+        public override string ToString()
         {
-            return this.reference.Equals(obj);
+            return new string(this.value);
         }
     }
-}
\ No newline at end of file
+}

Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharEnumerableCharSequenceWrapper.cs (from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharEnumerableCharSequenceWrapper.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharEnumerableCharSequenceWrapper.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs&r1=1157316&r2=1162468&rev=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharEnumerableCharSequenceWrapper.cs Sun Aug 28 02:12:33 2011
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-// <copyright company="Apache" file="BytesRef.cs">
+// <copyright company="Apache" file="CharEnumerableCharSequenceWrapper.cs">
 //
 //      Licensed to the Apache Software Foundation (ASF) under one or more
 //      contributor license agreements.  See the NOTICE file distributed with
@@ -19,7 +19,7 @@
 // </copyright>
 // -----------------------------------------------------------------------
 
-namespace Lucene.Net.Util
+namespace Lucene.Net.Support
 {
     using System;
     using System.Collections.Generic;
@@ -27,88 +27,88 @@ namespace Lucene.Net.Util
     using System.Text;
 
     /// <summary>
-    /// TODO: port
-    /// this class has methods that are not valid to void FxCop.
+    /// Creates an <see cref="char"/> <see cref="IEnumerable{T}"/> wrapper for <see cref="ICharSequence"/>.
     /// </summary>
-    public sealed class BytesRef : IComparable<BytesRef>
+    internal class CharEnumerableCharSequenceWrapper : ICharSequence
     {
-        private byte[] reference = new byte[] { };
+        private readonly IEnumerable<char> value;
 
         /// <summary>
-        /// Implements the operator !=.
+        /// Initializes a new instance of the <see cref="CharEnumerableCharSequenceWrapper"/> class.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator !=(BytesRef left, BytesRef right)
+        /// <param name="value">The value.</param>
+        public CharEnumerableCharSequenceWrapper(IEnumerable<char> value)
         {
-            return left.reference != right.reference;
+            this.value = value;
         }
 
         /// <summary>
-        /// Implements the operator ==.
+        /// Gets the length.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator ==(BytesRef left, BytesRef right)
+        /// <value>The length.</value>
+        public int Length
         {
-            return left.reference == right.reference;
+            get { return this.value.Count(); }
         }
 
         /// <summary>
-        /// Implements the operator &lt;.
+        /// Finds the <see cref="char"/> at the specified index.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator <(BytesRef left, BytesRef right)
+        /// <param name="index">The index.</param>
+        /// <returns>An instance of <see cref="Char"/>.</returns>
+        public char CharAt(int index)
         {
-            return left.reference.Length < right.reference.Length;
+            return this.value.ElementAt(index);
         }
 
         /// <summary>
-        /// Implements the operator &gt;.
+        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator >(BytesRef left, BytesRef right)
+        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+        /// <returns>
+        ///  <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// </returns>
+        public override bool Equals(object obj)
         {
-            return left.reference.Length < right.reference.Length;
+            return CharSequenceExtensions.IsCharSequenceEqual(this, obj);
         }
 
         /// <summary>
-        /// Compares this instance to the other <see cref="BytesRef"/> instance.
+        /// Returns a hash code for this instance.
         /// </summary>
-        /// <param name="other">The other.</param>
-        /// <returns>An instance of <see cref="Int32"/>.</returns>
-        public int CompareTo(BytesRef other)
+        /// <returns>
+        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// </returns>
+        public override int GetHashCode()
         {
-            throw new NotImplementedException();
+            return CharSequenceExtensions.CreateHashCode(this);
         }
 
+        
+
         /// <summary>
-        /// Returns a hash code for this instance.
+        /// Gets the subset sequence of characters from the current sequence.
         /// </summary>
+        /// <param name="start">The start.</param>
+        /// <param name="end">The end.</param>
         /// <returns>
-        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// An instance of <see cref="ICharSequence"/>.
         /// </returns>
-        public override int GetHashCode()
+        public ICharSequence SubSequence(int start, int end)
         {
-            return this.reference.GetHashCode();
+            var enumerable = this.value.Skip(start).Take(end - start);
+            return new CharEnumerableCharSequenceWrapper(enumerable);
         }
 
         /// <summary>
-        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+        /// Returns a <see cref="System.String"/> that represents this instance.
         /// </summary>
-        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
         /// <returns>
-        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// A <see cref="System.String"/> that represents this instance.
         /// </returns>
-        public override bool Equals(object obj)
+        public override string ToString()
         {
-            return this.reference.Equals(obj);
+            return new string(this.value.ToArray());
         }
     }
 }
\ No newline at end of file

Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharListCharSequenceWrapper.cs (from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharListCharSequenceWrapper.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharListCharSequenceWrapper.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs&r1=1157316&r2=1162468&rev=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharListCharSequenceWrapper.cs Sun Aug 28 02:12:33 2011
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-// <copyright company="Apache" file="BytesRef.cs">
+// <copyright company="Apache" file="CharListCharSequenceWrapper.cs">
 //
 //      Licensed to the Apache Software Foundation (ASF) under one or more
 //      contributor license agreements.  See the NOTICE file distributed with
@@ -19,7 +19,7 @@
 // </copyright>
 // -----------------------------------------------------------------------
 
-namespace Lucene.Net.Util
+namespace Lucene.Net.Support
 {
     using System;
     using System.Collections.Generic;
@@ -27,88 +27,86 @@ namespace Lucene.Net.Util
     using System.Text;
 
     /// <summary>
-    /// TODO: port
-    /// this class has methods that are not valid to void FxCop.
+    /// Creates a <see cref="Char"/> <see cref="List{T}"/> wrapper for <see cref="ICharSequence"/>.
     /// </summary>
-    public sealed class BytesRef : IComparable<BytesRef>
+    public class CharListCharSequenceWrapper : ICharSequence
     {
-        private byte[] reference = new byte[] { };
+        private readonly IList<char> value;
 
         /// <summary>
-        /// Implements the operator !=.
+        /// Initializes a new instance of the <see cref="CharListCharSequenceWrapper"/> class.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator !=(BytesRef left, BytesRef right)
+        /// <param name="value">The value.</param>
+        public CharListCharSequenceWrapper(IList<char> value)
         {
-            return left.reference != right.reference;
+            this.value = value;
         }
 
         /// <summary>
-        /// Implements the operator ==.
+        /// Gets the length.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator ==(BytesRef left, BytesRef right)
+        /// <value>The length.</value>
+        public int Length
         {
-            return left.reference == right.reference;
+            get { return this.value.Count; }
         }
 
         /// <summary>
-        /// Implements the operator &lt;.
+        /// Finds the <see cref="char"/> at the specified index.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator <(BytesRef left, BytesRef right)
+        /// <param name="index">The index.</param>
+        /// <returns>An instance of <see cref="Char"/>.</returns>
+        public char CharAt(int index)
         {
-            return left.reference.Length < right.reference.Length;
+            return this.value[index];
         }
 
         /// <summary>
-        /// Implements the operator &gt;.
+        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator >(BytesRef left, BytesRef right)
+        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+        /// <returns>
+        ///  <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// </returns>
+        public override bool Equals(object obj)
         {
-            return left.reference.Length < right.reference.Length;
+            return CharSequenceExtensions.IsCharSequenceEqual(this, obj);
         }
 
         /// <summary>
-        /// Compares this instance to the other <see cref="BytesRef"/> instance.
+        /// Returns a hash code for this instance.
         /// </summary>
-        /// <param name="other">The other.</param>
-        /// <returns>An instance of <see cref="Int32"/>.</returns>
-        public int CompareTo(BytesRef other)
+        /// <returns>
+        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// </returns>
+        public override int GetHashCode()
         {
-            throw new NotImplementedException();
+            return CharSequenceExtensions.CreateHashCode(this);
         }
 
         /// <summary>
-        /// Returns a hash code for this instance.
+        /// Gets the subset sequence of characters from the current sequence.
         /// </summary>
+        /// <param name="start">The start.</param>
+        /// <param name="end">The end.</param>
         /// <returns>
-        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// An instance of <see cref="ICharSequence"/>.
         /// </returns>
-        public override int GetHashCode()
+        public ICharSequence SubSequence(int start, int end)
         {
-            return this.reference.GetHashCode();
+            var list = this.value.Skip(start).Take(end - start).ToList();
+            return new CharListCharSequenceWrapper(list);
         }
 
         /// <summary>
-        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+        /// Returns a <see cref="System.String"/> that represents this instance.
         /// </summary>
-        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
         /// <returns>
-        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// A <see cref="System.String"/> that represents this instance.
         /// </returns>
-        public override bool Equals(object obj)
+        public override string ToString()
         {
-            return this.reference.Equals(obj);
+            return new string(this.value.ToArray());
         }
     }
-}
\ No newline at end of file
+}

Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharSequenceExtensions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharSequenceExtensions.cs?rev=1162468&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharSequenceExtensions.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/CharSequenceExtensions.cs Sun Aug 28 02:12:33 2011
@@ -0,0 +1,52 @@
+// -----------------------------------------------------------------------
+// <copyright file="CharSequenceExtensions.cs" company="Microsoft">
+// TODO: Update copyright text.
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Lucene.Net.Support
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Text;
+
+    /// <summary>
+    /// Extension and static methods for the ICharSequence interface. 
+    /// </summary>
+    internal static class CharSequenceExtensions
+    {
+        public static bool IsCharSequence(this object value)
+        {
+            return value is ICharSequence || value is string || value is IEnumerable<char>;
+        }
+
+        internal static int CreateHashCode(ICharSequence value)
+        {
+            int result = 0;
+            int end = value.Length;
+            for (int i = 0; i < end; i++)
+                result = (31 * result) + value.CharAt(i);
+
+            return result;
+        }
+
+        internal static bool IsCharSequenceEqual(ICharSequence value, object obj)
+        {
+            ICharSequence sequence = obj as ICharSequence;
+            if (sequence == null)
+                return false;
+
+            if (value.Length != sequence.Length)
+                return false;
+
+            for (int i = 0; i < value.Length; i++)
+            {
+                if (value.CharAt(i) != sequence.CharAt(i))
+                    return false;
+            }
+
+            return true;
+        }
+    }
+}

Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/EnumerableExtensions.cs (from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/EnumerableExtensions.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/EnumerableExtensions.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs&r1=1157316&r2=1162468&rev=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/EnumerableExtensions.cs Sun Aug 28 02:12:33 2011
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-// <copyright company="Apache" file="StringExtensions.cs">
+// <copyright company="Apache" file="EnumerableExtensions.cs">
 //
 //      Licensed to the Apache Software Foundation (ASF) under one or more
 //      contributor license agreements.  See the NOTICE file distributed with
@@ -19,31 +19,39 @@
 // </copyright>
 // -----------------------------------------------------------------------
 
-
-
 namespace Lucene.Net.Support
 {
     using System;
     using System.Collections.Generic;
-    using System.Globalization;
     using System.Linq;
     using System.Text;
 
     /// <summary>
-    /// Extension methods for strings
+    /// TODO: Update summary.
     /// </summary>
-    internal static class StringExtensions
+    public static class EnumerableExtensions
     {
         /// <summary>
-        /// Alias for string.Format that uses <see cref="CultureInfo.InvariantCulture"/>
-        /// for formatting strings.
+        /// Transforms the <see cref="IEnumerable{T}"/> into a <see cref="ICharSequence"/> object.
         /// </summary>
-        /// <param name="obj">The obj.</param>
-        /// <param name="args">The args.</param>
-        /// <returns>an instance of <see cref="string"/></returns>
-        public static string Inject(this string obj, params object[] args)
+        /// <param name="enumerable">The enumerable.</param>
+        /// <returns>
+        /// An instance of <see cref="ICharSequence"/>.
+        /// </returns>
+        public static ICharSequence ToCharSequence(this IEnumerable<char> enumerable)
         {
-            return string.Format(System.Globalization.CultureInfo.InvariantCulture, obj, args);            
+            // TODO: uncomment when PCL System.String implements IEnumerable<char>
+            // if(enumerable is string)
+            //    return new StringCharSquenceWrapper((string)enumerable); */
+            char[] array = enumerable as char[];
+            if (array != null)
+                return new CharArrayCharSequenceWrapper(array);
+
+            List<char> list = enumerable as List<char>;
+            if (list != null)
+                return new CharListCharSequenceWrapper(list);
+
+            return new CharEnumerableCharSequenceWrapper(enumerable);
         }
     }
-}
\ No newline at end of file
+}

Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/ICharSequence.cs (from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/ICharSequence.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/ICharSequence.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs&r1=1157316&r2=1162468&rev=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/ICharSequence.cs Sun Aug 28 02:12:33 2011
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-// <copyright company="Apache" file="StringExtensions.cs">
+// <copyright company="Apache" file="ICharSequence.cs">
 //
 //      Licensed to the Apache Software Foundation (ASF) under one or more
 //      contributor license agreements.  See the NOTICE file distributed with
@@ -19,31 +19,49 @@
 // </copyright>
 // -----------------------------------------------------------------------
 
-
-
 namespace Lucene.Net.Support
 {
     using System;
     using System.Collections.Generic;
-    using System.Globalization;
     using System.Linq;
     using System.Text;
 
     /// <summary>
-    /// Extension methods for strings
+    /// TODO: Update summary.
     /// </summary>
-    internal static class StringExtensions
+    public interface ICharSequence
     {
         /// <summary>
-        /// Alias for string.Format that uses <see cref="CultureInfo.InvariantCulture"/>
-        /// for formatting strings.
+        /// Gets the length.
+        /// </summary>
+        /// <value>The length.</value>
+        int Length { get;  }
+
+        /// <summary>
+        /// Finds the <see cref="char"/> at the specified index.
+        /// </summary>
+        /// <param name="index">The index.</param>
+        /// <returns>An instance of <see cref="Char"/>.</returns>
+        char CharAt(int index);
+
+
+        /// <summary>
+        /// Gets the subset sequence of characters from the current sequence.
+        /// </summary>
+        /// <param name="start">The start.</param>
+        /// <param name="end">The end.</param>
+        /// <returns>
+        /// An instance of <see cref="ICharSequence"/>.
+        /// </returns>
+        ICharSequence SubSequence(int start, int end);
+
+
+        /// <summary>
+        /// Returns a <see cref="System.String"/> that represents this instance.
         /// </summary>
-        /// <param name="obj">The obj.</param>
-        /// <param name="args">The args.</param>
-        /// <returns>an instance of <see cref="string"/></returns>
-        public static string Inject(this string obj, params object[] args)
-        {
-            return string.Format(System.Globalization.CultureInfo.InvariantCulture, obj, args);            
-        }
+        /// <returns>
+        /// A <see cref="System.String"/> that represents this instance.
+        /// </returns>
+        string ToString();
     }
-}
\ No newline at end of file
+}

Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringCharSequenceWrapper.cs (from r1157316, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringCharSequenceWrapper.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringCharSequenceWrapper.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs&r1=1157316&r2=1162468&rev=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringCharSequenceWrapper.cs Sun Aug 28 02:12:33 2011
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-// <copyright company="Apache" file="BytesRef.cs">
+// <copyright company="Apache" file="StringCharSequenceWrapper.cs">
 //
 //      Licensed to the Apache Software Foundation (ASF) under one or more
 //      contributor license agreements.  See the NOTICE file distributed with
@@ -19,7 +19,7 @@
 // </copyright>
 // -----------------------------------------------------------------------
 
-namespace Lucene.Net.Util
+namespace Lucene.Net.Support
 {
     using System;
     using System.Collections.Generic;
@@ -27,88 +27,85 @@ namespace Lucene.Net.Util
     using System.Text;
 
     /// <summary>
-    /// TODO: port
-    /// this class has methods that are not valid to void FxCop.
+    /// Creates a <see cref="string"/> wrapper for <see cref="ICharSequence"/>
     /// </summary>
-    public sealed class BytesRef : IComparable<BytesRef>
+    internal class StringCharSequenceWrapper : ICharSequence
     {
-        private byte[] reference = new byte[] { };
+        private readonly string value;
 
         /// <summary>
-        /// Implements the operator !=.
+        /// Initializes a new instance of the <see cref="StringCharSequenceWrapper"/> class.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator !=(BytesRef left, BytesRef right)
+        /// <param name="value">The value.</param>
+        public StringCharSequenceWrapper(string value)
         {
-            return left.reference != right.reference;
+            this.value = value;
         }
 
         /// <summary>
-        /// Implements the operator ==.
+        /// Gets the length.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator ==(BytesRef left, BytesRef right)
+        /// <value>The length.</value>
+        public int Length
         {
-            return left.reference == right.reference;
+            get { return this.value.Length; }
         }
 
         /// <summary>
-        /// Implements the operator &lt;.
+        /// Finds the <see cref="char"/> at the specified index.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator <(BytesRef left, BytesRef right)
+        /// <param name="index">The index.</param>
+        /// <returns>An instance of <see cref="Char"/>.</returns>
+        public char CharAt(int index)
         {
-            return left.reference.Length < right.reference.Length;
+            return this.value[index];
         }
 
         /// <summary>
-        /// Implements the operator &gt;.
+        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
         /// </summary>
-        /// <param name="left">The x.</param>
-        /// <param name="right">The y.</param>
-        /// <returns>The result of the operator.</returns>
-        public static bool operator >(BytesRef left, BytesRef right)
+        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+        /// <returns>
+        ///  <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// </returns>
+        public override bool Equals(object obj)
         {
-            return left.reference.Length < right.reference.Length;
+            return CharSequenceExtensions.IsCharSequenceEqual(this, obj);
         }
 
         /// <summary>
-        /// Compares this instance to the other <see cref="BytesRef"/> instance.
+        /// Returns a hash code for this instance.
         /// </summary>
-        /// <param name="other">The other.</param>
-        /// <returns>An instance of <see cref="Int32"/>.</returns>
-        public int CompareTo(BytesRef other)
+        /// <returns>
+        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// </returns>
+        public override int GetHashCode()
         {
-            throw new NotImplementedException();
+            return CharSequenceExtensions.CreateHashCode(this);
         }
 
         /// <summary>
-        /// Returns a hash code for this instance.
+        /// Gets the subset sequence of characters from the current sequence.
         /// </summary>
+        /// <param name="start">The start.</param>
+        /// <param name="end">The end.</param>
         /// <returns>
-        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
+        /// An instance of <see cref="ICharSequence"/>.
         /// </returns>
-        public override int GetHashCode()
+        public ICharSequence SubSequence(int start, int end)
         {
-            return this.reference.GetHashCode();
+            return new StringCharSequenceWrapper(this.value.Substring(start, end));
         }
 
         /// <summary>
-        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+        /// Returns a <see cref="System.String"/> that represents this instance.
         /// </summary>
-        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
         /// <returns>
-        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+        /// A <see cref="System.String"/> that represents this instance.
         /// </returns>
-        public override bool Equals(object obj)
+        public override string ToString()
         {
-            return this.reference.Equals(obj);
+            return this.value;
         }
     }
-}
\ No newline at end of file
+}

Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Support/StringExtensions.cs Sun Aug 28 02:12:33 2011
@@ -45,5 +45,10 @@ namespace Lucene.Net.Support
         {
             return string.Format(System.Globalization.CultureInfo.InvariantCulture, obj, args);            
         }
+
+        public static ICharSequence ToCharSequence(this string value)
+        {
+            return new StringCharSequenceWrapper(value);
+        }
     }
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/ArrayUtil.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/ArrayUtil.cs?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/ArrayUtil.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/ArrayUtil.cs Sun Aug 28 02:12:33 2011
@@ -156,5 +156,74 @@ namespace Lucene.Net.Util
                     return newSize;
             }
         }
+
+        /// <summary>
+        /// Grows the specified <paramref name="source"/> by a minimum of 1.
+        /// </summary>
+        /// <typeparam name="T">The type of the array.</typeparam>
+        /// <param name="source">The source.</param>
+        /// <returns>an <c>array</c> of <typeparamref name="T"/>. </returns>
+        public static T[] Grow<T>(T[] source)
+        {
+            return Grow(source, source.Length + 1);
+        }
+
+        /// <summary>
+        /// Grows the specified <paramref name="source"/> to the specified length.
+        /// </summary>
+        /// <typeparam name="T">The type of the array.</typeparam>
+        /// <param name="source">The source.</param>
+        /// <param name="length">The length.</param>
+        /// <param name="bytesPerElement">The bytes per element.</param>
+        /// <returns>
+        ///     a new array if the length of the <paramref name="source"/> was less than or equal
+        ///     to the specified <paramref name="length"/>, otherwise it returns the <paramref name="source"/>.
+        /// </returns>
+        /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> is null.</exception>
+        /// <exception cref="ArgumentException">
+        ///     Thrown when <paramref name="length"/> is less than 0.
+        /// </exception>
+        public static T[] Grow<T>(T[] source, int length, int bytesPerElement = 1)
+        {
+            if (source == null)
+                throw new ArgumentNullException("source");
+
+            if (length < 0)
+                throw new ArgumentException("length must be greater than or equal to 0");
+
+            if (source.Length >= length)
+                return source;
+
+            T[] destination = new T[Oversize(length, bytesPerElement)];
+            Array.Copy(source, 0, destination, 0, source.Length);
+
+            return destination;
+        }
+
+        /// <summary>
+        /// Grows the specified array by 1.
+        /// </summary>
+        /// <param name="source">The array.</param>
+        /// <returns>a <c>char[]</c>.</returns>
+        /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> is null.</exception>
+        public static char[] Grow(char[] source)
+        {
+            return Grow(source, source.Length + 1);
+        }
+
+        /// <summary>
+        /// Grows the specified array to the minimum length specified.
+        /// </summary>
+        /// <param name="source">The array.</param>
+        /// <param name="length">The length.</param>
+        /// <returns>an <c>char[]</c></returns>
+        /// <exception cref="ArgumentNullException">Thrown when <paramref name="source"/> is null.</exception>
+        /// <exception cref="ArgumentException">
+        ///     Thrown when <paramref name="length"/> is less than 0.
+        /// </exception>
+        public static char[] Grow(char[] source, int length)
+        {
+            return Grow(source, length, RamUsageEstimator.NumberOfBytesChar);
+        }
     }
 }
\ No newline at end of file

Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs?rev=1162468&r1=1162467&r2=1162468&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs Sun Aug 28 02:12:33 2011
@@ -25,14 +25,142 @@ namespace Lucene.Net.Util
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
+    using Lucene.Net.Support;
 
     /// <summary>
     /// TODO: port
-    /// this class has methods that are not valid to void FxCop.
+    /// Still missing methods that have to do with CharRef and ArrayUtil.Grow
     /// </summary>
-    public sealed class BytesRef : IComparable<BytesRef>
+    public sealed class BytesRef : IComparable<BytesRef>,
+        ICloneable<BytesRef>
     {
-        private byte[] reference = new byte[] { };
+        /// <summary>
+        /// Returns an array of empty bytes. 
+        /// </summary>
+        public static readonly byte[] EmptyBytes = new byte[0];
+
+        private static readonly UTF16Comparer utf16Comparer = new UTF16Comparer();
+        private static readonly UnicodeComparer unicodeComparer = new UnicodeComparer();
+ 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="BytesRef"/> class.
+        /// </summary>
+        public BytesRef()
+        {
+            this.Bytes = EmptyBytes;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="BytesRef"/> class.
+        /// </summary>
+        /// <param name="bytes">The bytes.</param>
+        /// <param name="offset">The offset.</param>
+        /// <param name="length">The length.</param>
+        public BytesRef(byte[] bytes, int offset = 0, int length = 0)
+        {
+            if (bytes == null)
+                throw new ArgumentNullException("bytes");
+
+            if (length == 0)
+                length = bytes.Length;
+
+            this.Bytes = bytes;
+            this.Offset = offset;
+            this.Length = length;
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="BytesRef"/> class.
+        /// </summary>
+        /// <param name="capacity">The capacity.</param>
+        public BytesRef(int capacity)
+        {
+            if (capacity < 0)
+                throw new ArgumentException("capacity can not be less than 0", "capacity");
+
+            this.Bytes = new byte[capacity];
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="BytesRef"/> class.
+        /// </summary>
+        /// <param name="text">The text.</param>
+        /// <param name="offset">The offset.</param>
+        /// <param name="length">The length.</param>
+        public BytesRef(char[] text, int offset = 0, int length = 0)
+        {
+            if (text == null)
+                throw new ArgumentNullException("text");
+
+            if (length == 0)
+                length = text.Length;
+
+            this.Bytes = new byte[length];
+
+            this.Copy(text, offset, length);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="BytesRef"/> class.
+        /// </summary>
+        /// <param name="text">The text.</param>
+        public BytesRef(string text)
+            : this()
+        {
+            if (text == null)
+                throw new ArgumentNullException("text");
+
+            this.Copy(text);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="BytesRef"/> class.
+        /// </summary>
+        /// <param name="target">The target.</param>
+        public BytesRef(BytesRef target)
+            : this()
+        {
+            if (target == null)
+                throw new ArgumentNullException("target");
+
+            this.Copy(target);
+        }
+
+        /// <summary>
+        /// Gets the UTF8 sorted as UTF16 comparer.
+        /// </summary>
+        /// <value>The UTF8 sorted as UTF16 comparer.</value>
+        public static IComparer<BytesRef> Utf8SortedAsUtf16Comparer
+        {
+            get { return utf16Comparer; }
+        }
+
+        /// <summary>
+        /// Gets the UTF8 sorted as Unicode comparer.
+        /// </summary>
+        /// <value>The UTF8 sorted as Unicode comparer.</value>
+        public static IComparer<BytesRef> Utf8SortedAsUnicodeComparer
+        {
+            get { return unicodeComparer; }
+        }
+
+        /// <summary>
+        /// Gets or sets the bytes.
+        /// </summary>
+        /// <value>The bytes.</value>
+        public byte[] Bytes { get; set; }
+
+        /// <summary>
+        /// Gets or sets the length.
+        /// </summary>
+        /// <value>The length.</value>
+        public int Length { get; set; }
+
+        /// <summary>
+        /// Gets or sets the offset.
+        /// </summary>
+        /// <value>The offset.</value>
+        public int Offset { get; set; }
 
         /// <summary>
         /// Implements the operator !=.
@@ -42,7 +170,10 @@ namespace Lucene.Net.Util
         /// <returns>The result of the operator.</returns>
         public static bool operator !=(BytesRef left, BytesRef right)
         {
-            return left.reference != right.reference;
+            if (left == null)
+                return right != null;
+
+            return !left.Equals(right);
         }
 
         /// <summary>
@@ -53,7 +184,10 @@ namespace Lucene.Net.Util
         /// <returns>The result of the operator.</returns>
         public static bool operator ==(BytesRef left, BytesRef right)
         {
-            return left.reference == right.reference;
+            if (left == null)
+                return right == null;
+
+            return left.Equals(right);
         }
 
         /// <summary>
@@ -64,7 +198,7 @@ namespace Lucene.Net.Util
         /// <returns>The result of the operator.</returns>
         public static bool operator <(BytesRef left, BytesRef right)
         {
-            return left.reference.Length < right.reference.Length;
+            return left.CompareTo(right) < 0;
         }
 
         /// <summary>
@@ -75,7 +209,80 @@ namespace Lucene.Net.Util
         /// <returns>The result of the operator.</returns>
         public static bool operator >(BytesRef left, BytesRef right)
         {
-            return left.reference.Length < right.reference.Length;
+            return left.CompareTo(right) > 0;
+        }
+
+        /// <summary>
+        /// Byteses the equal.
+        /// </summary>
+        /// <param name="target">The target.</param>
+        /// <returns>An instance of <see cref="Boolean"/>.</returns>
+        public bool BytesEqual(BytesRef target)
+        {
+            if (this.Length != target.Length)
+                return false;
+
+            int targetOffset = target.Offset, 
+                end = this.Offset + this.Length;
+
+            byte[] targetBytes = target.Bytes;
+
+            for (int i = this.Offset; i < end; i++, targetOffset++)
+            {
+                if (this.Bytes[i] != targetBytes[targetOffset])
+                    return false;
+            }
+
+            return true;
+        }
+
+        /// <summary>
+        /// Copies the specified source.
+        /// </summary>
+        /// <param name="source">The source.</param>
+        public void Copy(BytesRef source)
+        {
+            if (this.Bytes.Length < source.Length)
+                this.Bytes = new byte[source.Length];
+
+            Array.Copy(source.Bytes, source.Offset, this.Bytes, 0, source.Length);
+
+            this.Length = source.Length;
+            this.Offset = 0;
+        }
+
+        /// <summary>
+        /// Copies the specified source.
+        /// </summary>
+        /// <param name="source">The source.</param>
+        public void Copy(string source)
+        {
+            UnicodeUtil.UTF16toUTF8(source, 0, source.Length, this);   
+        }
+
+        /// <summary>
+        /// Copies the specified source.
+        /// </summary>
+        /// <param name="source">The source.</param>
+        /// <param name="offset">The offset.</param>
+        /// <param name="length">The length.</param>
+        public void Copy(char[] source, int offset = 0, int length = 0)
+        {
+            if (length == 0)
+                length = source.Length;
+
+            UnicodeUtil.UTF16toUTF8(source, offset, length, this);
+        }
+
+    
+
+        /// <summary>
+        /// Clones this instance.
+        /// </summary>
+        /// <returns>a <see cref="BytesRef"/> clone.</returns>
+        public BytesRef Clone()
+        {
+            return new BytesRef(this);
         }
 
         /// <summary>
@@ -85,7 +292,29 @@ namespace Lucene.Net.Util
         /// <returns>An instance of <see cref="Int32"/>.</returns>
         public int CompareTo(BytesRef other)
         {
-            throw new NotImplementedException();
+            if (this == other)
+                return 0;
+
+            byte[] leftBytes = this.Bytes,
+                    rightBytes = other.Bytes;
+
+            int leftOffset = this.Offset,
+                rightOffset = other.Offset,
+                leftStop;
+
+            leftStop = leftOffset + Math.Min(this.Length, other.Length);
+
+            while (leftOffset < leftStop)
+            {
+                int leftByte = leftBytes[leftOffset++] & 0xff;
+                int rightByte = rightBytes[rightOffset++] & 0xff;
+                int difference = leftByte - rightByte;
+
+                if (difference != 0)
+                    return difference;
+            }
+
+            return this.Length - other.Length;
         }
 
         /// <summary>
@@ -96,7 +325,23 @@ namespace Lucene.Net.Util
         /// </returns>
         public override int GetHashCode()
         {
-            return this.reference.GetHashCode();
+            int hashCode = 0, end = this.Offset + this.Length;
+
+            for (int i = this.Offset; i < end; i++) 
+            {
+               hashCode = (31 * hashCode) + this.Bytes[i];
+            }
+
+            return hashCode;
+        }
+
+        /// <summary>
+        /// Grows the <see cref="BytesRef"/> to the specified length.
+        /// </summary>
+        /// <param name="length">The length.</param>
+        public void Grow(int length)
+        {
+            this.Bytes = ArrayUtil.Grow(this.Bytes, length);
         }
 
         /// <summary>
@@ -108,7 +353,176 @@ namespace Lucene.Net.Util
         /// </returns>
         public override bool Equals(object obj)
         {
-            return this.reference.Equals(obj);
+            BytesRef bytesRef = obj as BytesRef;
+            
+            if (bytesRef == null)
+                return false;
+
+            return this.BytesEqual(bytesRef);
+        }
+
+        /// <summary>
+        /// Starts with the specified <see cref="BytesRef"/>.
+        /// </summary>
+        /// <param name="other">The other.</param>
+        /// <returns>An instance of <see cref="Boolean"/>.</returns>
+        public bool StartsWith(BytesRef other)
+        {
+            return this.SliceEquals(other, 0);
+        }
+
+        /// <summary>
+        /// Ends with the specified <see cref="BytesRef"/>.
+        /// </summary>
+        /// <param name="other">The other.</param>
+        /// <returns>An instance of <see cref="Boolean"/>.</returns>
+        public bool EndsWith(BytesRef other)
+        {
+            return this.SliceEquals(other, this.Length - other.Length);
+        }
+
+        /// <summary>
+        /// Returns a <see cref="System.String"/> that represents this instance. Should return
+        /// hex encoded bytes that looks something like: [0x6c 0x75 0x63 0x65 0x6e 0x65]
+        /// </summary>
+        /// <returns>
+        /// A <see cref="System.String"/> that represents this instance.
+        /// </returns>
+        public override string ToString()
+        {
+            var sb = new StringBuilder();
+            int end = this.Offset + this.Length;
+
+            sb.Append('[');
+
+            for (int i = this.Offset; i < end; i++)
+            {
+                if (i > this.Offset)
+                    sb.Append(' ');
+
+                sb.Append((this.Bytes[i] & 0xf).ToString("X"));
+            }
+
+            sb.Append(']');
+
+            return sb.ToString();
+        }
+
+
+        object ICloneable.Clone()
+        {
+            return this.Clone();
+        }
+
+        private bool SliceEquals(BytesRef other, int position)
+        {
+            if (position < 0 || this.Length - position < other.Length)
+                return false;
+
+            int leftOffset = this.Offset + position;
+            int rightOffset = other.Offset;
+            int rightStop = other.Offset + other.Length;
+
+            while (rightOffset < rightStop)
+            {
+                if (this.Bytes[leftOffset++] != other.Bytes[rightOffset++])
+                    return false;
+            }
+
+            return true;
+        }
+
+        private class UnicodeComparer : IComparer<BytesRef>
+        {
+            /// <summary>
+            /// Compares the two <see cref="BytesRef"/> objects to determine if they
+            /// are equal or to see if the <paramref name="left"/> is greater than or less than the <paramref name="right"/>.
+            /// </summary>
+            /// <param name="left">The left.</param>
+            /// <param name="right">The right.</param>
+            /// <returns>a int the represents the comparison.</returns>
+            public int Compare(BytesRef left, BytesRef right)
+            {
+                byte[] leftBytes = left.Bytes, 
+                       rightBytes = right.Bytes;
+
+                int leftOffset = left.Offset, 
+                    rightOffset = right.Offset, 
+                    leftStop;
+
+                leftStop = leftOffset + (left.Length < right.Length ? left.Length : right.Length);
+
+                while (leftOffset < leftStop)
+                {
+                    int leftByte = leftBytes[leftOffset++] & 0xff;
+                    int rightByte = rightBytes[rightOffset++] & 0xff;
+
+                    int difference = leftByte - rightByte;
+
+                    if (difference != 0)
+                        return difference;
+                }
+
+                return left.Length - right.Length;
+            }
+        }
+
+        
+
+        private class UTF16Comparer : IComparer<BytesRef>
+        {
+            /// <summary>
+            /// Compares the two <see cref="BytesRef"/> parameters using a UTF16Sorted Comparison. 
+            /// </summary>
+            /// <remarks>
+            ///     <para>
+            ///         See http://icu-project.org/docs/papers/utf16_code_point_order.html#utf-8-in-utf-16-order
+            ///         We know the terms are not equal, but, we may have to carefully 
+            ///         fixup the bytes at the difference to match UTF16's sort order.
+            ///      </para>
+            ///      <para>
+            ///         NOTE: instead of moving supplementary code points (0xee and 0xef) to the unused 0xfe and 0xff, 
+            ///         we move them to the unused 0xfc and 0xfd [reserved for future 6-byte character sequences]
+            ///         this reserves 0xff for preflex's term reordering (surrogate dance), and if Unicode grows such
+            ///         that 6-byte sequences are needed we have much bigger problems anyway.
+            ///     </para>
+            /// </remarks>
+            /// <param name="left">The left value that is being compared.</param>
+            /// <param name="right">The right value that is being compared.</param>
+            /// <returns>the comparison int.</returns>
+            public int Compare(BytesRef left, BytesRef right)
+            {
+                byte[] leftBytes = left.Bytes,
+                       rightBytes = right.Bytes;
+
+                int leftOffset = left.Offset,
+                    rightOffset = right.Offset,
+                    leftStop = 0;
+
+                leftStop = leftOffset + (left.Length < right.Length ? left.Length : right.Length);
+
+                while (leftOffset < leftStop)
+                {
+                    int leftByte = leftBytes[leftOffset++] & 0xff;
+                    int rightByte = rightBytes[rightOffset++] & 0xff;
+
+                    if (leftByte != rightByte)
+                    {
+                        if (leftByte >= 0xee & rightByte >= 0xee)
+                        {
+                            if ((leftByte & 0xfe) == 0xee)
+                                leftByte += 0xe;
+
+                            if ((rightByte & 0xfe) == 0xee)
+                                rightByte += 0xe;
+
+                            return leftByte - rightByte;
+                        }
+                    }
+                }
+
+                return right.Length - left.Length;
+            }
         }
     }
 }
\ No newline at end of file



Mime
View raw message