return SliceUtf8.substring(text, 0, resultLength);
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "UTF-8 does not contain 10 code points") public void testSubstringInvalidStart() { substring(utf8Slice(STRING_HELLO), 10, 2); }
private static void assertSubstring(String string) { Slice utf8 = utf8Slice(string); int[] codePoints = string.codePoints().toArray(); for (int start = 0; start < codePoints.length / 2; start++) { int count = Math.min(20, codePoints.length - start - start - 1); Slice actual = substring(utf8, start, count); Slice expected = wrappedBuffer(new String(codePoints, start, count).getBytes(UTF_8)); assertEquals(actual, expected); } assertEquals(substring(utf8, 0, codePoints.length), utf8); assertEquals(substring(utf8, 0, 0), EMPTY_SLICE); }
private static void assertSubstring(String string) { Slice utf8 = utf8Slice(string); int[] codePoints = string.codePoints().toArray(); for (int start = 0; start < codePoints.length / 2; start++) { int count = Math.min(20, codePoints.length - start - start - 1); Slice actual = substring(utf8, start, count); Slice expected = wrappedBuffer(new String(codePoints, start, count).getBytes(UTF_8)); assertEquals(actual, expected); } assertEquals(substring(utf8, 0, codePoints.length), utf8); assertEquals(substring(utf8, 0, 0), EMPTY_SLICE); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "UTF-8 does not contain 10 code points") public void testSubstringInvalidStart() { substring(utf8Slice(STRING_HELLO), 10, 2); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "UTF-8 does not contain 7 code points") public void testSubstringInvalidLength() { substring(utf8Slice(STRING_HELLO), 0, 7); }
@Test(expectedExceptions = InvalidUtf8Exception.class, expectedExceptionsMessageRegExp = "UTF-8 is not well formed") public void testSubstringInvalidUtf8() { substring(wrappedBuffer((byte) 'f', (byte) 'o', (byte) 'o', START_3_BYTE, CONTINUATION_BYTE), 0, 4); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "UTF-8 does not contain 7 code points") public void testSubstringInvalidLength() { substring(utf8Slice(STRING_HELLO), 0, 7); }
@Test(expectedExceptions = InvalidUtf8Exception.class, expectedExceptionsMessageRegExp = "UTF-8 is not well formed") public void testSubstringInvalidUtf8() { substring(wrappedBuffer((byte) 'f', (byte) 'o', (byte) 'o', START_3_BYTE, CONTINUATION_BYTE), 0, 4); }
@Benchmark public Slice benchmarkSubstring(BenchmarkData data) { Slice slice = data.getSlice(); int length = data.getLength(); return substring(slice, (length / 2) - 1, length / 2); }
@Benchmark public Slice benchmarkSubstring(BenchmarkData data) { Slice slice = data.getSlice(); int length = data.getLength(); return substring(slice, (length / 2) - 1, length / 2); }
return SliceUtf8.substring(text, 0, resultLength);
return SliceUtf8.substring(text, 0, resultLength);
return SliceUtf8.substring(text, 0, resultLength);