You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2022/10/14 11:17:48 UTC

[GitHub] [lucenenet] NightOwl888 commented on a diff in pull request #654: fix: Aligned DeleteButSuffixFromElseReplace with Java code (FrenchStemmer.cs)

NightOwl888 commented on code in PR #654:
URL: https://github.com/apache/lucenenet/pull/654#discussion_r995587910


##########
src/Lucene.Net.Analysis.Common/Analysis/Fr/FrenchStemmer.cs:
##########
@@ -483,21 +483,21 @@ private void DeleteButSuffixFromElseReplace(string source, string[] search, stri
                 {
                     if (source.EndsWith(prefix + search[i], StringComparison.Ordinal))
                     {
-                        sb.Remove(sb.Length - (prefix.Length + search[i].Length), sb.Length - sb.Length - (prefix.Length + search[i].Length));
+                        sb.Remove(sb.Length - (prefix.Length + search[i].Length), sb.Length);

Review Comment:
   The reason why this differs is because in Java the parameters are `startIndex` and `endIndex`, but in .NET we have `startIndex` and `length`. 
   
   https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#delete-int-int-
   https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.remove?view=net-7.0
   
   Therefore, we need to do some light math to correct this:
   
   ```
   length = endIndex - startIndex
   ```
   
   This correction is common across many method conversions from Java to .NET.
   
   That being said, we are missing a set of parentheses here and in the other methods in this class to force the order of precedence, which is a very subtle bug:
   
   ```c#
   sb.Remove(sb.Length - (prefix.Length + search[i].Length), sb.Length - (sb.Length - (prefix.Length + search[i].Length)));
   ```



-- 
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-unsubscribe@lucenenet.apache.org

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