digitalmars.D.learn - from bytes to string
- Coder (6/6) Nov 27 2021 I'm lost, std.utf, std.conv, std.encoding, std.uni
- Adam D Ruppe (5/9) Nov 27 2021 If they're already supposed to be utf8, just cast it to char[]
- Coder (15/25) Nov 27 2021 Thank you Adam,
- H. S. Teoh (6/18) Nov 27 2021 Because it may throw some other kind of Exception besides UTFException.
- Adam D Ruppe (13/23) Nov 27 2021 Ever play Pokemon? You can't just catch the cute Bulbasaur and
- Coder (2/25) Nov 27 2021 Thumbs Up!
I'm lost, std.utf, std.conv, std.encoding, std.uni 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? Thank you!
Nov 27 2021
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.
Nov 27 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: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 throwMy 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.
Nov 27 2021
On Sat, Nov 27, 2021 at 03:24:43PM +0000, Coder via Digitalmars-d-learn wrote: [...]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 throwBecause it may throw some other kind of Exception besides UTFException. T -- Stop staring at me like that! It's offens... no, you'll hurt your eyes!
Nov 27 2021
On Saturday, 27 November 2021 at 15:24:43 UTC, Coder wrote:Question, why a function can not be nothrow if I catch in the body?Ever play Pokemon? You can't just catch the cute Bulbasaur and call it done (even though the grass type is like playing on easy mode). You gotta catch 'em all!void foo() nothrow { import std.utf : validate, UTFException; try { validate("a"); } catch(Exception){ // make that Exception } }cuz nothrow doesn't know about specific exception types, it only looks at Exception as a whole. It doesn't actually know what validate throws. All right, we gotta rap some pokemon like its 1998. electro diglet nidoran mankey venosaur
Nov 27 2021
On Saturday, 27 November 2021 at 15:29:45 UTC, Adam D Ruppe wrote:On Saturday, 27 November 2021 at 15:24:43 UTC, Coder wrote:Thumbs Up!Question, why a function can not be nothrow if I catch in the body?Ever play Pokemon? You can't just catch the cute Bulbasaur and call it done (even though the grass type is like playing on easy mode). You gotta catch 'em all!void foo() nothrow { import std.utf : validate, UTFException; try { validate("a"); } catch(Exception){ // make that Exception } }cuz nothrow doesn't know about specific exception types, it only looks at Exception as a whole. It doesn't actually know what validate throws. All right, we gotta rap some pokemon like its 1998. electro diglet nidoran mankey venosaur
Nov 27 2021