digitalmars.D.learn - byte to char safe?
- Harry (5/5) Jul 30 2009 Again hello,
- BCS (3/11) Jul 30 2009 I think this will also work and you can be shure it's safe.
- Harry (6/22) Jul 30 2009 again thank you !
- Daniel Keep (9/12) Jul 30 2009 I have no idea what you're asking. To take a blind stab: writef expects
- Sergey Gromov (5/30) Jul 31 2009 No, writef does not escape non-printing characters, if that's what you
- Ary Borenszweig (5/8) Jul 30 2009 If you want the result to be "again7hello", then no. You must do:
- Harry (7/19) Jul 30 2009 Hello Ary,
- Sergey Gromov (22/42) Jul 31 2009 If you use only your own write function then you can put just anything
- Harry (7/57) Aug 01 2009 thank you!
- Sergey Gromov (11/71) Aug 02 2009 Well, sure, standard writef simply outputs those characters to the
- Sergey Gromov (4/6) Aug 02 2009 Sorry, this sentence has a typo:
- Daniel Keep (4/12) Jul 30 2009 I think a more significant problem is that "again\x07hello" can't
Again hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello"; use only own write functions is ok? thank you!
Jul 30 2009
Reply to Harry,Again hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello"; use only own write functions is ok? thank you!I think this will also work and you can be shure it's safe. r"again" ~ '\x07' ~ r"hello"
Jul 30 2009
BCS Wrote:Reply to Harry,again thank you ! D writef not print utf8 control? \x00 .. \x1f and \x7f .. \x9f safe for data? where \n \t? sorry so many questionsAgain hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello"; use only own write functions is ok? thank you!I think this will also work and you can be shure it's safe. r"again" ~ '\x07' ~ r"hello"
Jul 30 2009
Harry wrote:D writef not print utf8 control?I have no idea what you're asking. To take a blind stab: writef expects any char[] you give it to be in utf8 format. Actually, EVERYTHING assumes that char[] is in utf8.\x00 .. \x1f and \x7f .. \x9f safe for data?Again, I'm not sure what you're asking. char[] is utf8, which means that ANY code unit in the range \x80..\xff is invalid by itself. If you're storing binary data, use ubyte[].where \n \t?const NEWLINE = "\n"; What's the issue?
Jul 30 2009
Thu, 30 Jul 2009 18:29:09 -0400, Harry wrote:BCS Wrote: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));Reply to Harry,again thank you ! D writef not print utf8 control? \x00 .. \x1f and \x7f .. \x9f safe for data? where \n \t? sorry so many questionsAgain hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello"; use only own write functions is ok? thank you!I think this will also work and you can be shure it's safe. r"again" ~ '\x07' ~ r"hello"
Jul 31 2009
Harry escribió:Again hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello";If you want the result to be "again7hello", then no. You must do: char[6] t = r"again" ~ '7' ~ r"hello"; or: char[6] t = r"again" ~ (cast(char)('0' + 7)) ~ r"hello";
Jul 30 2009
Ary Borenszweig Wrote:Harry escribió:Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ? thank youAgain hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello";If you want the result to be "again7hello", then no. You must do: char[6] t = r"again" ~ '7' ~ r"hello"; or: char[6] t = r"again" ~ (cast(char)('0' + 7)) ~ r"hello";
Jul 30 2009
Thu, 30 Jul 2009 19:14:56 -0400, Harry wrote:Ary Borenszweig Wrote: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: '\uXXXX' or '\UXXXXXXXX', where XXXX and XXXXXXXX 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 0x10FFFF. Any other character values will throw a run-time exception if passed to standard functions.Harry escribií¦ í»Š> > Again hello,Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ?char[6] t = r"again" ~ cast(char)7 ~ r"hello";If you want the result to be "again7hello", then no. You must do: char[6] t = r"again" ~ '7' ~ r"hello"; or: char[6] t = r"again" ~ (cast(char)('0' + 7)) ~ r"hello";
Jul 31 2009
Sergey Gromov Wrote:Thu, 30 Jul 2009 19:14:56 -0400, Harry wrote: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"Ary Borenszweig Wrote: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: '\uXXXX' or '\UXXXXXXXX', where XXXX and XXXXXXXX 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 0x10FFFF. Any other character values will throw a run-time exception if passed to standard functions.Harry escribií¦ í»Š> > Again hello,Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ?char[6] t = r"again" ~ cast(char)7 ~ r"hello";If you want the result to be "again7hello", then no. You must do: char[6] t = r"again" ~ '7' ~ r"hello"; or: char[6] t = r"again" ~ (cast(char)('0' + 7)) ~ r"hello";
Aug 01 2009
Sat, 01 Aug 2009 19:58:20 -0400, Harry wrote:Sergey Gromov Wrote: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.Thu, 30 Jul 2009 19:14:56 -0400, Harry wrote: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!Ary Borenszweig Wrote: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: '\uXXXX' or '\UXXXXXXXX', where XXXX and XXXXXXXX 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 0x10FFFF. Any other character values will throw a run-time exception if passed to standard functions.Harry escribií¦ í»Š> > Again hello,Hello Ary, 7 is data not string. It makes own write function need style data in char[] Not sure if safe ?char[6] t = r"again" ~ cast(char)7 ~ r"hello";If you want the result to be "again7hello", then no. You must do: char[6] t = r"again" ~ '7' ~ r"hello"; or: char[6] t = r"again" ~ (cast(char)('0' + 7)) ~ r"hello";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";
Aug 02 2009
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.
Aug 02 2009
Harry wrote:Again hello, char[6] t = r"again" ~ cast(char)7 ~ r"hello"; 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.
Jul 30 2009