@@ -253,9 +253,10 @@ CStringTests.test("String.cString.with.Array.CChar.input") {
253
253
do {
254
254
let ( u8p, dealloc) = getASCIIUTF8 ( )
255
255
defer { dealloc ( ) }
256
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: CChar . self)
257
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
258
- let str = String ( cString: Array ( buffer) )
256
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
257
+ let str = buffer. withMemoryRebound ( to: CChar . self) {
258
+ String ( cString: Array ( $0) )
259
+ }
259
260
str. withCString {
260
261
$0. withMemoryRebound ( to: UInt8 . self, capacity: buffer. count) {
261
262
expectEqualCString ( u8p, $0)
@@ -318,9 +319,10 @@ CStringTests.test("String.validatingUTF8.with.Array.input") {
318
319
do {
319
320
let ( u8p, dealloc) = getASCIIUTF8 ( )
320
321
defer { dealloc ( ) }
321
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: CChar . self)
322
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
323
- let str = String ( validatingUTF8: Array ( buffer) )
322
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
323
+ let str = buffer. withMemoryRebound ( to: CChar . self) {
324
+ String ( validatingUTF8: Array ( $0) )
325
+ }
324
326
expectNotNil ( str)
325
327
str? . withCString {
326
328
$0. withMemoryRebound ( to: UInt8 . self, capacity: buffer. count) {
@@ -373,9 +375,10 @@ CStringTests.test("String.decodeCString.with.Array.input") {
373
375
do {
374
376
let ( u8p, dealloc) = getASCIIUTF8 ( )
375
377
defer { dealloc ( ) }
376
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: Unicode . UTF8. CodeUnit. self)
377
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
378
- let result = String . decodeCString ( Array ( buffer) , as: Unicode . UTF8. self)
378
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
379
+ let result = buffer. withMemoryRebound ( to: Unicode . UTF8. CodeUnit. self) {
380
+ String . decodeCString ( Array ( $0) , as: Unicode . UTF8. self)
381
+ }
379
382
expectNotNil ( result)
380
383
expectEqual ( result? . repairsMade, false )
381
384
result? . result. withCString {
@@ -436,9 +439,10 @@ CStringTests.test("String.init.decodingCString.with.Array.input") {
436
439
do {
437
440
let ( u8p, dealloc) = getASCIIUTF8 ( )
438
441
defer { dealloc ( ) }
439
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: Unicode . UTF8. CodeUnit. self)
440
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
441
- let str = String ( decodingCString: Array ( buffer) , as: Unicode . UTF8. self)
442
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
443
+ let str = buffer. withMemoryRebound ( to: Unicode . UTF8. CodeUnit. self) {
444
+ String ( decodingCString: Array ( $0) , as: Unicode . UTF8. self)
445
+ }
442
446
str. withCString {
443
447
$0. withMemoryRebound ( to: UInt8 . self, capacity: buffer. count) {
444
448
expectEqualCString ( u8p, $0)
0 commit comments