Copilot commented on code in PR #1057:
URL: https://github.com/apache/lucenenet/pull/1057#discussion_r2286865556


##########
src/Lucene.Net/Util/UnicodeUtil.cs:
##########
@@ -825,86 +801,41 @@ public static void UTF8toUTF32(BytesRef utf8, Int32sRef 
utf32)
 
         /// <summary>
         /// Value that all lead surrogate starts with. </summary>
-        private const int LEAD_SURROGATE_OFFSET_ = LEAD_SURROGATE_MIN_VALUE - 
(SUPPLEMENTARY_MIN_VALUE >> LEAD_SURROGATE_SHIFT_);
+        private const int LEAD_SURROGATE_OFFSET_ =
+            LEAD_SURROGATE_MIN_VALUE - (SUPPLEMENTARY_MIN_VALUE >> 
LEAD_SURROGATE_SHIFT_);
 
         /// <summary>
         /// Cover JDK 1.5 API. Create a String from an array of <paramref 
name="codePoints"/>.
         /// </summary>
-        /// <param name="codePoints"> The code array. </param>
+        /// <param name="codePoints"> The code point array. </param>
         /// <param name="offset"> The start of the text in the code point 
array. </param>
         /// <param name="count"> The number of code points. </param>
         /// <returns> a String representing the code points between offset and 
count. </returns>
         /// <exception cref="ArgumentException"> If an invalid code point is 
encountered. </exception>
-        /// <exception cref="ArgumentOutOfRangeException"> If the offset or 
count are out of bounds. </exception>
+        /// <exception cref="IndexOutOfRangeException"> If the offset or count 
are out of bounds. </exception>

Review Comment:
   The exception type in the documentation comment is inconsistent with the 
actual implementation. The method uses Character.ToString() which throws 
ArgumentOutOfRangeException, not IndexOutOfRangeException.
   ```suggestion
           /// <exception cref="ArgumentOutOfRangeException"> If the offset or 
count are out of bounds. </exception>
   ```



##########
src/Lucene.Net/Support/ObsoleteAPI/UnicodeUtil.cs:
##########
@@ -0,0 +1,175 @@
+using Lucene.Net.Support;
+using System;
+
+#nullable enable
+
+namespace Lucene.Net.Util
+{
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
+
+    /*
+     * Some of this code came from the excellent Unicode
+     * conversion examples from:
+     *
+     *   http://www.unicode.org/Public/PROGRAMS/CVTUTF
+     *
+     * Full Copyright for that code follows:
+    */
+
+    /*
+     * Copyright 2001-2004 Unicode, Inc.
+     *
+     * Disclaimer
+     *
+     * this source code is provided as is by Unicode, Inc. No claims are
+     * made as to fitness for any particular purpose. No warranties of any
+     * kind are expressed or implied. The recipient agrees to determine
+     * applicability of information provided. If this file has been
+     * purchased on magnetic or optical media from Unicode, Inc., the
+     * sole remedy for any claim will be exchange of defective media
+     * within 90 days of receipt.
+     *
+     * Limitations on Rights to Redistribute this Code
+     *
+     * Unicode, Inc. hereby grants the right to freely use the information
+     * supplied in this file in the creation of products supporting the
+     * Unicode Standard, and to make copies of this file in any form
+     * for internal or external distribution as long as this notice
+     * remains attached.
+     */
+
+    /*
+     * Additional code came from the IBM ICU library.
+     *
+     *  http://www.icu-project.org
+     *
+     * Full Copyright for that code follows.
+     */
+
+    /*
+     * Copyright (C) 1999-2010, International Business Machines
+     * Corporation and others.  All Rights Reserved.
+     *
+     * 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, and/or sell copies of 
the
+     * Software, and to permit persons to whom the Software is furnished to do 
so,
+     * provided that the above copyright notice(s) and this permission notice 
appear
+     * in all copies of the Software and that both the above copyright 
notice(s) and
+     * this permission notice appear in supporting documentation.
+     *
+     * 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 OF THIRD PARTY 
RIGHTS.
+     * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN this 
NOTICE BE
+     * LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, 
OR
+     * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
WHETHER
+     * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 
OUT
+     * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF this SOFTWARE.
+     *
+     * Except as contained in this notice, the name of a copyright holder 
shall not
+     * be used in advertising or otherwise to promote the sale, use or other
+     * dealings in this Software without prior written authorization of the
+     * copyright holder.
+     */
+
+    public static partial class UnicodeUtil
+    {
+        /// <summary>
+        /// Generates char array that represents the provided input code 
points.
+        /// <para/>
+        /// LUCENENET specific.
+        /// </summary>
+        /// <param name="codePoints"> The code array. </param>
+        /// <param name="offset"> The start of the text in the code point 
array. </param>
+        /// <param name="count"> The number of code points. </param>
+        /// <returns> a char array representing the code points between offset 
and count. </returns>
+        // LUCENENET NOTE: This code was originally in the NewString() method.
+        // It has been refactored from the original to remove the exception 
throw/catch and
+        // instead proactively resizes the array instead of relying on 
exceptions + copy operations
+        [Obsolete("Use NewString method instead. This method will be removed 
in 4.8.0 release candidate."), 
System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static char[] ToCharArray(int[] codePoints, int offset, int 
count)
+        {
+            return ToCharArray(codePoints.AsSpan(offset), count);
+        }
+
+        /// <summary>
+        /// Generates char array that represents the provided input code 
points.
+        /// <para/>
+        /// LUCENENET specific.
+        /// </summary>
+        /// <param name="codePoints"> The code span. </param>
+        /// <param name="count"> The number of code points. </param>
+        /// <returns> a char array representing the code points between offset 
and count. </returns>
+        // LUCENENET NOTE: This code was originally in the NewString() method.
+        // It has been refactored from the original to remove the exception 
throw/catch and
+        // instead proactively resizes the array instead of relying on 
exceptions + copy operations
+        [Obsolete("Use NewString method instead. This method will be removed 
in 4.8.0 release candidate."), 
System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
+        public static char[] ToCharArray(ReadOnlySpan<int> codePoints, int 
count)
+        {
+            if (count < 0)
+            {
+                throw new ArgumentOutOfRangeException(nameof(count), "count 
must be >= 0"); // LUCENENET specific - changed from IllegalArgumentException 
to ArgumentOutOfRangeException (.NET convention)
+            }
+            const int countThreshold = 1024; // If the number of chars exceeds 
this, we count them instead of allocating count * 2

Review Comment:
   The comment contains a typo: 'threashold' should be 'threshold'. The 
variable name has been corrected but the comment still contains the misspelling.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to