mirror of https://github.com/apache/lucene.git
LUCENE-9085: Fix assertion in CharacterUtils (#1067)
This commit is contained in:
parent
df508ffe01
commit
79007128e3
|
@ -53,7 +53,7 @@ public final class CharacterUtils {
|
||||||
*/
|
*/
|
||||||
public static void toLowerCase(final char[] buffer, final int offset, final int limit) {
|
public static void toLowerCase(final char[] buffer, final int offset, final int limit) {
|
||||||
assert buffer.length >= limit;
|
assert buffer.length >= limit;
|
||||||
assert offset <=0 && offset <= buffer.length;
|
assert 0 <= offset && offset <= buffer.length;
|
||||||
for (int i = offset; i < limit;) {
|
for (int i = offset; i < limit;) {
|
||||||
i += Character.toChars(
|
i += Character.toChars(
|
||||||
Character.toLowerCase(
|
Character.toLowerCase(
|
||||||
|
@ -70,7 +70,7 @@ public final class CharacterUtils {
|
||||||
*/
|
*/
|
||||||
public static void toUpperCase(final char[] buffer, final int offset, final int limit) {
|
public static void toUpperCase(final char[] buffer, final int offset, final int limit) {
|
||||||
assert buffer.length >= limit;
|
assert buffer.length >= limit;
|
||||||
assert offset <=0 && offset <= buffer.length;
|
assert 0 <= offset && offset <= buffer.length;
|
||||||
for (int i = offset; i < limit;) {
|
for (int i = offset; i < limit;) {
|
||||||
i += Character.toChars(
|
i += Character.toChars(
|
||||||
Character.toUpperCase(
|
Character.toUpperCase(
|
||||||
|
|
|
@ -32,6 +32,17 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class TestCharacterUtils extends LuceneTestCase {
|
public class TestCharacterUtils extends LuceneTestCase {
|
||||||
|
|
||||||
|
public void testLowerUpper() throws IOException {
|
||||||
|
Reader reader = new StringReader("ABc");
|
||||||
|
CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(3);
|
||||||
|
assertTrue(CharacterUtils.fill(buffer, reader));
|
||||||
|
assertEquals(3, buffer.getLength());
|
||||||
|
CharacterUtils.toLowerCase(buffer.getBuffer(), 1, 3);
|
||||||
|
assertEquals("Abc", new String(buffer.getBuffer()));
|
||||||
|
CharacterUtils.toUpperCase(buffer.getBuffer(), 1, 3);
|
||||||
|
assertEquals("ABC", new String(buffer.getBuffer()));
|
||||||
|
}
|
||||||
|
|
||||||
public void testConversions() {
|
public void testConversions() {
|
||||||
final char[] orig = TestUtil.randomUnicodeString(random(), 100).toCharArray();
|
final char[] orig = TestUtil.randomUnicodeString(random(), 100).toCharArray();
|
||||||
final int[] buf = new int[orig.length];
|
final int[] buf = new int[orig.length];
|
||||||
|
|
Loading…
Reference in New Issue