www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: recognizing asciiz, utf ...

reply newbee <newbee newbee.com> writes:
Jarrett Billingsley Wrote:

 On Fri, Mar 13, 2009 at 3:04 PM, newbee <newbee newbee.com> wrote:
 Hi all,

 How does one check for asciiz, utf ...?
 I do get a buffer with characters as parameter in a function, but i don’t know
if it is asciiz or utf or wchar. Is it possible to find out in dmd1 and dmd2?

 Any help is appreciated.

How are you getting this buffer? What type is it, char[]? D strings are supposed to be Unicode, always. If you read the data in from a file, there's little to no guarantee as to what encoding it is (unless it started with a Unicode BOM). If you have a zero-terminated char* that a C function gives you, you can turn it into a D string with std.string.toString (Phobos) or tango.stdc.stringz.fromStringz (Tango).

i get it from a tcp buffer and do not know in advace if it is char[], asciiz or wchar. is it possible to check for that?
Mar 13 2009
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
newbee wrote:
 Jarrett Billingsley Wrote:
 
 On Fri, Mar 13, 2009 at 3:04 PM, newbee <newbee newbee.com> wrote:
 Hi all,

 How does one check for asciiz, utf ...?
 I do get a buffer with characters as parameter in a function, but i don�t
know if it is asciiz or utf or wchar. Is it possible to find out in dmd1 and
dmd2?

 Any help is appreciated.

are supposed to be Unicode, always. If you read the data in from a file, there's little to no guarantee as to what encoding it is (unless it started with a Unicode BOM). If you have a zero-terminated char* that a C function gives you, you can turn it into a D string with std.string.toString (Phobos) or tango.stdc.stringz.fromStringz (Tango).

i get it from a tcp buffer and do not know in advace if it is char[], asciiz or wchar. is it possible to check for that?

If you're getting data from a network connection and you have no idea what it is, then the language certainly isn't going to help you with that. Perhaps reading the documentation for the network protocol is in order? :P -- Daniel
Mar 13 2009