@@ -477,7 +477,7 @@ pub const Utf16LeIterator = struct {
477
477
bytes : []const u8 ,
478
478
i : usize ,
479
479
480
- pub fn init (s : []const u16 ) Utf16LeIterator {
480
+ pub fn init (s : []align ( 1 ) const u16 ) Utf16LeIterator {
481
481
return Utf16LeIterator {
482
482
.bytes = mem .sliceAsBytes (s ),
483
483
.i = 0 ,
@@ -917,7 +917,8 @@ test fmtUtf8 {
917
917
918
918
fn utf16LeToUtf8ArrayListImpl (
919
919
result : * std .ArrayList (u8 ),
920
- utf16le : []const u16 ,
920
+ comptime alignment : std.mem.Alignment ,
921
+ utf16le : []align (alignment .toByteUnits ()) const u16 ,
921
922
comptime surrogates : Surrogates ,
922
923
) (switch (surrogates ) {
923
924
.cannot_encode_surrogate_half = > Utf16LeToUtf8AllocError ,
@@ -969,7 +970,7 @@ pub const Utf16LeToUtf8AllocError = mem.Allocator.Error || Utf16LeToUtf8Error;
969
970
970
971
pub fn utf16LeToUtf8ArrayList (result : * std .ArrayList (u8 ), utf16le : []const u16 ) Utf16LeToUtf8AllocError ! void {
971
972
try result .ensureUnusedCapacity (utf16le .len );
972
- return utf16LeToUtf8ArrayListImpl (result , utf16le , .cannot_encode_surrogate_half );
973
+ return utf16LeToUtf8ArrayListImpl (result , . of ( u16 ), utf16le , .cannot_encode_surrogate_half );
973
974
}
974
975
975
976
/// Caller must free returned memory.
@@ -978,17 +979,26 @@ pub fn utf16LeToUtf8Alloc(allocator: mem.Allocator, utf16le: []const u16) Utf16L
978
979
var result = try std .ArrayList (u8 ).initCapacity (allocator , utf16le .len );
979
980
errdefer result .deinit ();
980
981
981
- try utf16LeToUtf8ArrayListImpl (& result , utf16le , .cannot_encode_surrogate_half );
982
+ try utf16LeToUtf8ArrayListImpl (& result , . of ( u16 ), utf16le , .cannot_encode_surrogate_half );
982
983
return result .toOwnedSlice ();
983
984
}
984
985
985
986
/// Caller must free returned memory.
986
987
pub fn utf16LeToUtf8AllocZ (allocator : mem.Allocator , utf16le : []const u16 ) Utf16LeToUtf8AllocError ! [:0 ]u8 {
988
+ return alignedUtf16LeToUtf8AllocZ (allocator , .of (u16 ), utf16le );
989
+ }
990
+
991
+ /// Caller must free returned memory.
992
+ pub fn alignedUtf16LeToUtf8AllocZ (
993
+ allocator : mem.Allocator ,
994
+ comptime alignment : mem.Alignment ,
995
+ utf16le : []align (alignment .toByteUnits ()) const u16 ,
996
+ ) Utf16LeToUtf8AllocError ! [:0 ]u8 {
987
997
// optimistically guess that it will all be ascii (and allocate space for the null terminator)
988
998
var result = try std .ArrayList (u8 ).initCapacity (allocator , utf16le .len + 1 );
989
999
errdefer result .deinit ();
990
1000
991
- try utf16LeToUtf8ArrayListImpl (& result , utf16le , .cannot_encode_surrogate_half );
1001
+ try utf16LeToUtf8ArrayListImpl (& result , alignment , utf16le , .cannot_encode_surrogate_half );
992
1002
return result .toOwnedSliceSentinel (0 );
993
1003
}
994
1004
@@ -1752,7 +1762,7 @@ pub const Wtf8Iterator = struct {
1752
1762
1753
1763
pub fn wtf16LeToWtf8ArrayList (result : * std .ArrayList (u8 ), utf16le : []const u16 ) mem .Allocator .Error ! void {
1754
1764
try result .ensureUnusedCapacity (utf16le .len );
1755
- return utf16LeToUtf8ArrayListImpl (result , utf16le , .can_encode_surrogate_half );
1765
+ return utf16LeToUtf8ArrayListImpl (result , . of ( u16 ), utf16le , .can_encode_surrogate_half );
1756
1766
}
1757
1767
1758
1768
/// Caller must free returned memory.
@@ -1761,7 +1771,7 @@ pub fn wtf16LeToWtf8Alloc(allocator: mem.Allocator, wtf16le: []const u16) mem.Al
1761
1771
var result = try std .ArrayList (u8 ).initCapacity (allocator , wtf16le .len );
1762
1772
errdefer result .deinit ();
1763
1773
1764
- try utf16LeToUtf8ArrayListImpl (& result , wtf16le , .can_encode_surrogate_half );
1774
+ try utf16LeToUtf8ArrayListImpl (& result , . of ( u16 ), wtf16le , .can_encode_surrogate_half );
1765
1775
return result .toOwnedSlice ();
1766
1776
}
1767
1777
@@ -1771,7 +1781,7 @@ pub fn wtf16LeToWtf8AllocZ(allocator: mem.Allocator, wtf16le: []const u16) mem.A
1771
1781
var result = try std .ArrayList (u8 ).initCapacity (allocator , wtf16le .len + 1 );
1772
1782
errdefer result .deinit ();
1773
1783
1774
- try utf16LeToUtf8ArrayListImpl (& result , wtf16le , .can_encode_surrogate_half );
1784
+ try utf16LeToUtf8ArrayListImpl (& result , . of ( u16 ), wtf16le , .can_encode_surrogate_half );
1775
1785
return result .toOwnedSliceSentinel (0 );
1776
1786
}
1777
1787
@@ -1979,7 +1989,7 @@ pub const Wtf16LeIterator = struct {
1979
1989
bytes : []const u8 ,
1980
1990
i : usize ,
1981
1991
1982
- pub fn init (s : []const u16 ) Wtf16LeIterator {
1992
+ pub fn init (s : []align ( 1 ) const u16 ) Wtf16LeIterator {
1983
1993
return Wtf16LeIterator {
1984
1994
.bytes = mem .sliceAsBytes (s ),
1985
1995
.i = 0 ,
0 commit comments