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

   I implemented an Exception-free algorithm, but as it is heavily based on the 
OpenJDK code, so I am not sure if this is legally OK to add it in an ASF2 
licensed project. I rewrote the loop a bit:
   
   ```java
   final char[] a = termAttribute.buffer();
   final int len = termAttribute.length();
   int ofs = 0, nCodePoints = 0;
   for (; ofs < len && nCodePoints < truncateAfter; nCodePoints++) {
     if (Character.isHighSurrogate(a[ofs++]) && ofs < len && 
Character.isLowSurrogate(a[ofs])) {
       ofs++;
     }
   }
   // check if we actually reached the limit and set new length based on 
calculated offset:
   if (nCodePoints == truncateAfter) {
     termAttribute.setLength(ofs);
   }
   ```
   
   What do you think?


-- 
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