uschindler commented on PR #15900:
URL: https://github.com/apache/lucene/pull/15900#issuecomment-4183984203

   I rewrote the code according to ICU4J and now looks like this:
   
   ``java
   final char[] a = termAttribute.buffer();
   final int len = termAttribute.length();
   int ofs = 0, remaining = truncateAfter;
   while (ofs < len && remaining > 0) {
     if (Character.isHighSurrogate(a[ofs++]) && ofs < len && 
Character.isLowSurrogate(a[ofs])) {
       ofs++;
     }
     remaining--;
   }
   // check if we actually reached the limit and set new length based on 
calculated offset:
   if (remaining == 0) {
     termAttribute.setLength(ofs);
   }
   ```
   
   I thinks that's ok to use. It is also easier to understand because it counts 
down to 0 and only sets the new length is we were able to consume enough 
characters ("remaining").


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to