Re: byte to char safe?
Sat, 01 Aug 2009 19:58:20 -0400, Harry wrote: Sergey Gromov Wrote: Thu, 30 Jul 2009 19:14:56 -0400, Harry wrote: Ary Borenszweig Wrote: Harry escribi�� Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; If you want the result to be again7hello, then no. You must do: char[6] t = ragain ~ '7' ~ rhello; or: char[6] t = ragain ~ (cast(char)('0' + 7)) ~ rhello; Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ? If you use only your own write function then you can put just anything into char[]. But if you pass that char[] to any standard function, or even foreach, and there are non-UTF-8 sequences in there, the standard function will fail. Also note that values from 0 to 0x7F are valid UTF-8 codes and can be safely inserted into char[]. If you want to safely put a larger constant into char[] you can use unicode escape sequences: '\u' or '\U', where and are 4 or 8 hexadecimal digits respectively: char[] foo = hello ~ \u017e ~ \U00105614; foreach (dchar ch; foo) writefln(%x, cast(uint) ch); Finally, if you want to encode a variable into char[], you can use std.utf.encode function: char[] foo; uint value = 0x00100534; std.utf.encode(foo, value); Unfortunately all std.utf functions accept only valid UTF characters. Currently they're everything from 0 to 0xD7FF and from 0xE000 to 0x10. Any other character values will throw a run-time exception if passed to standard functions. thank you! non-print utf8 is print with writef start of text \x02 is smile end of text \x03 is heart newline \x0a is newline! Well, sure, standard writef simply outputs those characters to the console. Then console prints them according to its own rules. Therefore special characters will have different representation on different consoles. If you want consistent output you should those special characters to some printable form. is difference? utf.encode(foo,value) foo~\U00100534 A little. The code: uint value = 0x00100534; std.utf.encode(foo, value); is the same as: foo ~= \U00100534;
Re: byte to char safe?
Mon, 3 Aug 2009 04:11:31 +0400, Sergey Gromov wrote: If you want consistent output you should those special characters to some printable form. Sorry, this sentence has a typo: If you want consistent output you should *convert* those special characters to some printable form.
Re: byte to char safe?
Sergey Gromov Wrote: Thu, 30 Jul 2009 19:14:56 -0400, Harry wrote: Ary Borenszweig Wrote: Harry escribií¦ í» Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; If you want the result to be again7hello, then no. You must do: char[6] t = ragain ~ '7' ~ rhello; or: char[6] t = ragain ~ (cast(char)('0' + 7)) ~ rhello; Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ? If you use only your own write function then you can put just anything into char[]. But if you pass that char[] to any standard function, or even foreach, and there are non-UTF-8 sequences in there, the standard function will fail. Also note that values from 0 to 0x7F are valid UTF-8 codes and can be safely inserted into char[]. If you want to safely put a larger constant into char[] you can use unicode escape sequences: '\u' or '\U', where and are 4 or 8 hexadecimal digits respectively: char[] foo = hello ~ \u017e ~ \U00105614; foreach (dchar ch; foo) writefln(%x, cast(uint) ch); Finally, if you want to encode a variable into char[], you can use std.utf.encode function: char[] foo; uint value = 0x00100534; std.utf.encode(foo, value); Unfortunately all std.utf functions accept only valid UTF characters. Currently they're everything from 0 to 0xD7FF and from 0xE000 to 0x10. Any other character values will throw a run-time exception if passed to standard functions. thank you! non-print utf8 is print with writef start of text \x02 is smile end of text \x03 is heart newline \x0a is newline! is difference? utf.encode(foo,value) foo~\U00100534
Re: byte to char safe?
Thu, 30 Jul 2009 18:29:09 -0400, Harry wrote: BCS Wrote: Reply to Harry, Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; use only own write functions is ok? thank you! I think this will also work and you can be shure it's safe. ragain ~ '\x07' ~ rhello again thank you ! D writef not print utf8 control? \x00 .. \x1f and \x7f .. \x9f safe for data? where \n \t? sorry so many questions No, writef does not escape non-printing characters, if that's what you mean. It prints them as is. You can escape them using std.uri.encode for instance: writefln(std.uri.encode(str));
byte to char safe?
Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; use only own write functions is ok? thank you!
Re: byte to char safe?
Reply to Harry, Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; use only own write functions is ok? thank you! I think this will also work and you can be shure it's safe. ragain ~ '\x07' ~ rhello
Re: byte to char safe?
Harry escribió: Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; If you want the result to be again7hello, then no. You must do: char[6] t = ragain ~ '7' ~ rhello; or: char[6] t = ragain ~ (cast(char)('0' + 7)) ~ rhello;
Re: byte to char safe?
Ary Borenszweig Wrote: Harry escribió: Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; If you want the result to be again7hello, then no. You must do: char[6] t = ragain ~ '7' ~ rhello; or: char[6] t = ragain ~ (cast(char)('0' + 7)) ~ rhello; Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ? thank you
Re: byte to char safe?
Harry wrote: Again hello, char[6] t = ragain ~ cast(char)7 ~ rhello; use only own write functions is ok? thank you! I think a more significant problem is that again\x07hello can't possibly fit in six characters, unless you're using some crazy numbering system I'm not familiar with.