from bytes to string
Coder
coder at nospam.org
Sat Nov 27 15:24:43 UTC 2021
On Saturday, 27 November 2021 at 13:56:46 UTC, Adam D Ruppe wrote:
> On Saturday, 27 November 2021 at 13:54:11 UTC, Coder wrote:
>> My application is receiving data over a socket as
>> immutable(ubyte)[].
>> How to validate them and transform them to utf8 string? What
>> is the best way?
>
> If they're already supposed to be utf8, just cast it to char[]
> then you can call std.utf.validate on it if you want and idup
> it into a string to keep.
>
> If it is some other encoding... then it depends on what
> encoding.
Thank you Adam,
Question, why a function can not be nothrow if I catch in the
body?
void foo() nothrow {
import std.utf : validate, UTFException;
try {
validate("a");
}
catch(UTFException){
}
}
Error: function `std.utf.validate!string.validate` is not
`nothrow`
Error: `nothrow` function `foo` may throw
More information about the Digitalmars-d-learn
mailing list