@@ -270,6 +270,27 @@ public void testStrCpyUtf8() {
270270 }
271271 }
272272
273+ @ Test
274+ public void testStrCpyUtf8FromOffset () {
275+ final int bufSize = 64 ;
276+ long mem = Unsafe .malloc (bufSize , MemoryTag .NATIVE_DEFAULT );
277+ try {
278+ final byte sentinel = 0x5A ;
279+ String value = "ascii-prefixé世\uD83D \uDE00 \uD800 x" ;
280+ int lo = "ascii-prefix" .length ();
281+ int expectedBytes = Utf8s .utf8Bytes (value , lo , value .length ());
282+
283+ fill (mem , bufSize , sentinel );
284+ Assert .assertEquals (expectedBytes , Utf8s .strCpyUtf8 (value , lo , mem , expectedBytes ));
285+ Assert .assertEquals ("é世\uD83D \uDE00 ?x" , readUtf8 (mem , expectedBytes ));
286+ for (int i = expectedBytes ; i < bufSize ; i ++) {
287+ Assert .assertEquals ("write past copied bytes at offset " + i , sentinel , Unsafe .getUnsafe ().getByte (mem + i ));
288+ }
289+ } finally {
290+ Unsafe .free (mem , bufSize , MemoryTag .NATIVE_DEFAULT );
291+ }
292+ }
293+
273294 @ Test
274295 public void testStrCpyUtf8DoesNotSplitCharactersAtLimit () {
275296 final int bufSize = 16 ;
@@ -319,6 +340,14 @@ public void testUtf8Bytes() {
319340 Assert .assertEquals (1 , Utf8s .utf8Bytes ("\uDE00 " ));
320341 }
321342
343+ @ Test
344+ public void testUtf8BytesRange () {
345+ String value = "xxAé世\uD83D \uDE00 yy" ;
346+ Assert .assertEquals (10 , Utf8s .utf8Bytes (value , 2 , 7 ));
347+ Assert .assertEquals (1 , Utf8s .utf8Bytes (value , 5 , 6 ));
348+ Assert .assertEquals (4 , Utf8s .utf8Bytes (value , 5 , 7 ));
349+ }
350+
322351 @ Test
323352 public void testUtf8BytesWithLimit () {
324353 Assert .assertEquals (0 , Utf8s .utf8Bytes ("hello" , 0 ));
0 commit comments