@@ -254,9 +254,10 @@ CStringTests.test("String.cString.with.Array.CChar.input") {
254
254
do {
255
255
let ( u8p, dealloc) = getASCIIUTF8 ( )
256
256
defer { dealloc ( ) }
257
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: CChar . self)
258
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
259
- let str = String ( cString: Array ( buffer) )
257
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
258
+ let str = buffer. withMemoryRebound ( to: CChar . self) {
259
+ String ( cString: Array ( $0) )
260
+ }
260
261
str. withCString {
261
262
$0. withMemoryRebound ( to: UInt8 . self, capacity: buffer. count) {
262
263
expectEqualCString ( u8p, $0)
@@ -324,9 +325,10 @@ CStringTests.test("String.validatingUTF8.with.Array.input") {
324
325
do {
325
326
let ( u8p, dealloc) = getASCIIUTF8 ( )
326
327
defer { dealloc ( ) }
327
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: CChar . self)
328
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
329
- let str = String ( validatingUTF8: Array ( buffer) )
328
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
329
+ let str = buffer. withMemoryRebound ( to: CChar . self) {
330
+ String ( validatingUTF8: Array ( $0) )
331
+ }
330
332
expectNotNil ( str)
331
333
str? . withCString {
332
334
$0. withMemoryRebound ( to: UInt8 . self, capacity: buffer. count) {
@@ -382,9 +384,10 @@ CStringTests.test("String.decodeCString.with.Array.input") {
382
384
do {
383
385
let ( u8p, dealloc) = getASCIIUTF8 ( )
384
386
defer { dealloc ( ) }
385
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: Unicode . UTF8. CodeUnit. self)
386
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
387
- let result = String . decodeCString ( Array ( buffer) , as: Unicode . UTF8. self)
387
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
388
+ let result = buffer. withMemoryRebound ( to: Unicode . UTF8. CodeUnit. self) {
389
+ String . decodeCString ( Array ( $0) , as: Unicode . UTF8. self)
390
+ }
388
391
expectNotNil ( result)
389
392
expectEqual ( result? . repairsMade, false )
390
393
result? . result. withCString {
@@ -448,9 +451,10 @@ CStringTests.test("String.init.decodingCString.with.Array.input") {
448
451
do {
449
452
let ( u8p, dealloc) = getASCIIUTF8 ( )
450
453
defer { dealloc ( ) }
451
- let cstr = UnsafeRawPointer ( u8p) . assumingMemoryBound ( to: Unicode . UTF8. CodeUnit. self)
452
- let buffer = UnsafeBufferPointer ( start: cstr, count: getUTF8Length ( u8p) + 1 )
453
- let str = String ( decodingCString: Array ( buffer) , as: Unicode . UTF8. self)
454
+ let buffer = UnsafeBufferPointer ( start: u8p, count: getUTF8Length ( u8p) + 1 )
455
+ let str = buffer. withMemoryRebound ( to: Unicode . UTF8. CodeUnit. self) {
456
+ String ( decodingCString: Array ( $0) , as: Unicode . UTF8. self)
457
+ }
454
458
str. withCString {
455
459
$0. withMemoryRebound ( to: UInt8 . self, capacity: buffer. count) {
456
460
expectEqualCString ( u8p, $0)
0 commit comments