View source code
Display the source code in std/string.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.string.assumeUTF
Assume the given array of integers arr
is a well-formed UTF string and
return it typed as a UTF string.
auto auto assumeUTF(T)
(
T[] arr
)
if (staticIndexOf!(Unqual!T, ubyte, ushort, uint) != -1);
ubyte
becomes char
, ushort
becomes wchar
and uint
becomes dchar
. Type qualifiers are preserved.
When compiled with debug mode, this function performs an extra check to make sure the return value is a valid Unicode string.
Parameters
Name | Description |
---|---|
arr | array of bytes, ubytes, shorts, ushorts, ints, or uints |
Returns
arr retyped as an array of chars, wchars, or dchars
Throws
In debug mode AssertError
, when the result is not a well-formed UTF string.
See Also
Example
string a = "Hölo World";
immutable(ubyte)[] b = a .representation;
string c = b .assumeUTF;
writeln(c); // "Hölo World"
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.