lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mhern...@apache.org
Subject [4/9] adding resharper & ghostdoc settings. refactoring code for consistency.
Date Wed, 20 Aug 2014 02:32:08 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/785acd7d/src/Lucene.Net.Core/Util/UnicodeUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/UnicodeUtil.cs b/src/Lucene.Net.Core/Util/UnicodeUtil.cs
index 564e3f5..4e46ef9 100644
--- a/src/Lucene.Net.Core/Util/UnicodeUtil.cs
+++ b/src/Lucene.Net.Core/Util/UnicodeUtil.cs
@@ -17,14 +17,12 @@
 
 namespace Lucene.Net.Util
 {
-    using System;
     using System.Collections.Generic;
     using System.Diagnostics;
     using System.Linq;
-    using System.Text;
 
     /// <summary>
-    /// Utility methods for dealing with unicode.
+    ///     Utility methods for dealing with unicode.
     /// </summary>
     public static class UnicodeUtil
     {
@@ -40,128 +38,144 @@ namespace Lucene.Net.Util
         private const long HALF_SHIFT = 10;
         private const long HALF_MASK = 0x3FFL;
 
-        private static readonly int SURROGATE_OFFSET = MIN_SUPPLEMENTARY_CODE_POINT - (UNI_SUR_HIGH_START
<< (int)HALF_SHIFT) - UNI_SUR_LOW_START;
+        private const int SURROGATE_OFFSET =
+            MIN_SUPPLEMENTARY_CODE_POINT - (UNI_SUR_HIGH_START << (int) HALF_SHIFT)
- UNI_SUR_LOW_START;
 
         /// <summary>
-        /// 
         /// </summary>
         /// <param name="chars"></param>
         /// <param name="offset"></param>
         /// <param name="length"></param>
         /// <param name="result"></param>
-        public static void UTF16toUTF8(IEnumerable<char> chars, int offset, int length,
BytesRef result)
+        public static void Utf16ToUtf8(IEnumerable<char> chars, int offset, int length,
BytesRef result)
         {
-            int end = offset + length;
+            var end = offset + length;
 
-            byte[] @out = result.Bytes;
+            var @out = result.Bytes;
             result.Offset = 0;
             // Pre-allocate for worst case 4-for-1
-            int maxLen = length * 4;
+            var maxLen = length*4;
             if (@out.Length < maxLen)
             {
                 @out = result.Bytes = new byte[maxLen];
             }
 
-            int upto = 0;
-            for (int i = offset; i < end; i++)
-            {
-                int code = (int)chars.ElementAt(i);
+            var currentOffset = 0;
 
-                if (code < 0x80)
-                {
-                    @out[upto++] = (byte)code;
-                }
-                else if (code < 0x800)
-                {
-                    @out[upto++] = unchecked((byte)(0xC0 | (code >> 6)));
-                    @out[upto++] = unchecked((byte)(0x80 | (code & 0x3F)));
-                }
-                else if (code < 0xD800 || code > 0xDFFF)
-                {
-                    @out[upto++] = unchecked((byte)(0xE0 | (code >> 12)));
-                    @out[upto++] = unchecked((byte)(0x80 | ((code >> 6) & 0x3F)));
-                    @out[upto++] = unchecked((byte)(0x80 | (code & 0x3F)));
-                }
-                else
+            var move = offset < end;
+
+            if (move)
+            {
+                var list = chars.ToList();
+         
+                for (int i = offset; i < end; i++)
                 {
-                    // surrogate pair
-                    // confirm valid high surrogate
-                    if (code < 0xDC00 && (i < end - 1))
+                    var code = list[i];
+                    
+
+                    if (code < 0x80)
                     {
-                        int utf32 = (int)chars.ElementAt(i + 1);
-                        // confirm valid low surrogate and write pair
-                        if (utf32 >= 0xDC00 && utf32 <= 0xDFFF)
+                        @out[currentOffset++] = (byte)code;
+                    }
+                    else if (code < 0x800)
+                    {
+                        @out[currentOffset++] = unchecked((byte)(0xC0 | (code >> 6)));
+                        @out[currentOffset++] = unchecked((byte)(0x80 | (code & 0x3F)));
+                    }
+                    else if (code < 0xD800 || code > 0xDFFF)
+                    {
+                        @out[currentOffset++] = unchecked((byte)(0xE0 | (code >> 12)));
+                        @out[currentOffset++] = unchecked((byte)(0x80 | ((code >> 6)
& 0x3F)));
+                        @out[currentOffset++] = unchecked((byte)(0x80 | (code & 0x3F)));
+                    }
+                    else
+                    {
+                        // surrogate pair
+                        // confirm valid high surrogate
+                        if (code < 0xDC00 && (i < end - 1))
                         {
-                            utf32 = (code << 10) + utf32 + SURROGATE_OFFSET;
-                            i++;
-                            @out[upto++] = unchecked((byte)(0xF0 | (utf32 >> 18)));
-                            @out[upto++] = unchecked((byte)(0x80 | ((utf32 >> 12) &
0x3F)));
-                            @out[upto++] = unchecked((byte)(0x80 | ((utf32 >> 6) &
0x3F)));
-                            @out[upto++] = unchecked((byte)(0x80 | (utf32 & 0x3F)));
-                            continue;
+                            int utf32 = list[i + 1];
+                            // confirm valid low surrogate and write pair
+                            if (utf32 >= 0xDC00 && utf32 <= 0xDFFF)
+                            {
+                                utf32 = (code << 10) + utf32 + SURROGATE_OFFSET;
+                                i++;
+                                @out[currentOffset++] = unchecked((byte)(0xF0 | (utf32 >>
18)));
+                                @out[currentOffset++] = unchecked((byte)(0x80 | ((utf32 >>
12) & 0x3F)));
+                                @out[currentOffset++] = unchecked((byte)(0x80 | ((utf32 >>
6) & 0x3F)));
+                                @out[currentOffset++] = unchecked((byte)(0x80 | (utf32 &
0x3F)));
+                                continue;
+                            }
                         }
+                        // replace unpaired surrogate or out-of-order low surrogate
+                        // with substitution character
+                        @out[currentOffset++] = 0xEF;
+                        @out[currentOffset++] = 0xBF;
+                        @out[currentOffset++] = 0xBD;
                     }
-                    // replace unpaired surrogate or out-of-order low surrogate
-                    // with substitution character
-                    @out[upto++] = (byte)0xEF;
-                    @out[upto++] = (byte)0xBF;
-                    @out[upto++] = (byte)0xBD;
                 }
             }
-            //assert matches(s, offset, length, out, upto);
-            result.Length = upto;
-        }
 
+            
+            //assert matches(s, offset, length, out, otheroffset);
+            result.Length = currentOffset;
+        }
 
 
         /// <summary>
-        /// Interprets the given byte array as UTF-8 and converts to UTF-16. The <seealso
cref="CharsRef"/> will be extended if
-        /// it doesn't provide enough space to hold the worst case of each byte becoming
a UTF-16 codepoint.
-        /// <p>
-        /// NOTE: Full characters are read, even if this reads past the length passed (and
-        /// can result in an ArrayOutOfBoundsException if invalid UTF-8 is passed).
-        /// Explicit checks for valid UTF-8 are not performed.
+        ///     Interprets the given byte array as UTF-8 and converts to UTF-16. The <seealso
cref="CharsRef" /> will be extended
+        ///     if
+        ///     it doesn't provide enough space to hold the worst case of each byte becoming
a UTF-16 code point.
         /// </summary>
+        /// <remarks>
+        ///     <para>
+        ///         NOTE: Full characters are read, even if this reads past the length passed
(and
+        ///         can result in an ArrayOutOfBoundsException if invalid UTF-8 is passed).
+        ///         Explicit checks for valid UTF-8 are not performed.
+        ///     </para>
+        /// </remarks>
         // TODO: broken if chars.offset != 0
-        public static int UTF8toUTF16(byte[] utf8, int offset, int length, CharsRef chars)
+        public static int Utf8ToUtf16(byte[] utf8, int offset, int length, CharsRef chars)
         {
             int outOffset = chars.Offset = 0,
                 limit = offset + length;
 
-            char[] @out = chars.Chars = ArrayUtil.Grow(chars.Chars, length);
-  
+            var @out = chars.Chars = chars.Chars.Grow(length);
+
             while (offset < limit)
             {
-                int b = utf8[offset++] & 0xff;
+                var b = utf8[offset++] & 0xff;
                 if (b < 0xc0)
                 {
                     Debug.Assert(b < 0x80);
-                    @out[outOffset++] = (char)b;
+                    @out[outOffset++] = (char) b;
                 }
                 else if (b < 0xe0)
                 {
-                    @out[outOffset++] = (char)(((b & 0x1f) << 6) + (utf8[offset++]
& 0x3f));
+                    @out[outOffset++] = (char) (((b & 0x1f) << 6) + (utf8[offset++]
& 0x3f));
                 }
                 else if (b < 0xf0)
                 {
-                    @out[outOffset++] = (char)(((b & 0xf) << 12) + ((utf8[offset]
& 0x3f) << 6) + (utf8[offset + 1] & 0x3f));
+                    @out[outOffset++] =
+                        (char) (((b & 0xf) << 12) + ((utf8[offset] & 0x3f)
<< 6) + (utf8[offset + 1] & 0x3f));
                     offset += 2;
                 }
                 else
                 {
                     Debug.Assert(b < 0xf8, "b = 0x" + b.ToString("x"));
 
-                    int ch = ((b & 0x7) << 18) + ((utf8[offset] & 0x3f) <<
12) + ((utf8[offset + 1] & 0x3f) << 6) + (utf8[offset + 2] & 0x3f);
+                    var ch = ((b & 0x7) << 18) + ((utf8[offset] & 0x3f) <<
12) + ((utf8[offset + 1] & 0x3f) << 6) +
+                             (utf8[offset + 2] & 0x3f);
                     offset += 3;
                     if (ch < UNI_MAX_BMP)
                     {
-                        @out[outOffset++] = (char)ch;
+                        @out[outOffset++] = (char) ch;
                     }
                     else
                     {
-                        int chHalf = ch - 0x0010000;
-                        @out[outOffset++] = (char)((chHalf >> 10) + 0xD800);
-                        @out[outOffset++] = (char)((chHalf & HALF_MASK) + 0xDC00);
+                        var chHalf = ch - 0x0010000;
+                        @out[outOffset++] = (char) ((chHalf >> 10) + 0xD800);
+                        @out[outOffset++] = (char) ((chHalf & HALF_MASK) + 0xDC00);
                     }
                 }
             }
@@ -170,4 +184,4 @@ namespace Lucene.Net.Util
             return chars.Length;
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/785acd7d/src/Lucene.Net.Core/Util/Version.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Version.cs b/src/Lucene.Net.Core/Util/Version.cs
index 92c362c..c4246a0 100644
--- a/src/Lucene.Net.Core/Util/Version.cs
+++ b/src/Lucene.Net.Core/Util/Version.cs
@@ -19,7 +19,6 @@ namespace Lucene.Net.Util
 {
     using Lucene.Net.Support;
     using System;
-    using System.Text.RegularExpressions;
 
 
     /// <summary> Use by certain classes to match version compatibility
@@ -35,6 +34,7 @@ namespace Lucene.Net.Util
     ///         Java <see href="https://github.com/apache/lucene-solr/blob/trunk/lucene/core/src/test/org/apache/lucene/util/TestVersion.java">Source</see>
     ///     </para>
     /// </remarks>
+    // ReSharper disable InconsistentNaming
     [Flags]
     public enum Version
     {
@@ -46,7 +46,8 @@ namespace Lucene.Net.Util
         /// etc, for Lucene.
         /// </para>
         /// </summary>
-        [Obsolete()]
+        [Obsolete]
+
         LUCENE_4_3,
 
 
@@ -115,7 +116,6 @@ namespace Lucene.Net.Util
         /// Parses the string value and converts it to the version. Some examples are: "4.3",
"LUCENE_43", and "LUCENE_4_3" 
         /// </summary>
         /// <param name="version">The string representation of the version.</param>
-        /// <param name="version">The string representation of the version.</param>
         /// <returns><see cref="Lucene.Net.Util.Version"/></returns>
         public static Version ParseLeniently(string version)
         { 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/785acd7d/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/WeakIdentityMap.cs b/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
index cfa456e..5d72a97 100644
--- a/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
+++ b/src/Lucene.Net.Core/Util/WeakIdentityMap.cs
@@ -101,7 +101,7 @@ namespace Lucene.Net.Util
                     if (target == null)
                         continue;
                     
-                    if (Object.ReferenceEquals(target, NULL_VALUE))
+                    if (ReferenceEquals(target, NULL_VALUE))
                         yield return null;
                     else
                         yield return (TKey)target;
@@ -123,7 +123,7 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
<seealso cref="ConcurrentHashMap"/>.
+        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
ConcurrentHashMap.
         /// The map <a href="#reapInfo">cleans up the reference queue on every read
operation</a>.
         /// </summary>
         public static WeakIdentityMap<TKey, TValue> NewConcurrentHashMap()
@@ -132,7 +132,7 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
<seealso cref="ConcurrentHashMap"/>. </summary>
+        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
ConcurrentHashMap. </summary>
         /// <param name="reapOnRead"> controls if the map <a href="#reapInfo">cleans
up the reference queue on every read operation</a>. </param>
         public static WeakIdentityMap<TKey, TValue> NewConcurrentHashMap(bool reapOnRead)
         {
@@ -140,7 +140,7 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
non-synchronized <seealso cref="HashMap"/>.
+        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
non-synchronized HashMap.
         /// The map <a href="#reapInfo">cleans up the reference queue on every read
operation</a>.
         /// </summary>
         public static WeakIdentityMap<TKey, TValue> NewHashMap()
@@ -149,7 +149,7 @@ namespace Lucene.Net.Util
         }
 
         /// <summary>
-        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
non-synchronized <seealso cref="HashMap"/>. </summary>
+        /// Initializes a new <see cref="WeakIdentityMap{TKey,TValue}"/> based on a
non-synchronized HashMap. </summary>
         /// <param name="reapOnRead"> controls if the map <a href="#reapInfo">cleans
up the reference queue on every read operation</a>. </param>
         public static WeakIdentityMap<TKey, TValue> NewHashMap(bool reapOnRead)
         {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/785acd7d/src/Lucene.Net.Core/packages.config
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/packages.config b/src/Lucene.Net.Core/packages.config
index 9c1a013..786c80f 100644
--- a/src/Lucene.Net.Core/packages.config
+++ b/src/Lucene.Net.Core/packages.config
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="Microsoft.Framework.ConfigurationModel" version="1.0.0-alpha4-10193" targetFramework="portable-net451+win81+wpa81"
/>
+  <package id="Microsoft.Framework.ConfigurationModel" version="1.0.0-alpha4-10193" targetFramework="portable-net451+win81+wpa81"
requireReinstallation="True" />
 </packages>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/785acd7d/test/Lucene.Net.Core.Tests/Util/TestCharsRef.cs
----------------------------------------------------------------------
diff --git a/test/Lucene.Net.Core.Tests/Util/TestCharsRef.cs b/test/Lucene.Net.Core.Tests/Util/TestCharsRef.cs
index 0516186..02f5b34 100644
--- a/test/Lucene.Net.Core.Tests/Util/TestCharsRef.cs
+++ b/test/Lucene.Net.Core.Tests/Util/TestCharsRef.cs
@@ -44,7 +44,7 @@ namespace Lucene.Net.Util
 
             Array.Sort(utf8);
 #pragma warning disable 0612, 0618
-            Array.Sort(utf16, CharsRef.UTF16SortedAsUTF8Comparer);
+            Array.Sort(utf16, CharsRef.Utf16SortedAsUtf8Comparer);
 #pragma warning restore 0612, 0618
 
             iterations.Times((i) => Equal(utf8[i].Utf8ToString(), utf16[i].ToString()));


Mime
View raw message