www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - More on StringToken

reply Ben Hanson <Ben.Hanson tfbplc.co.uk> writes:
It seems like the best way to go is to use dchar for strings (i.e. not have
the struct as a template) as I need real characters for intersection purposes.
When it comes to lookup, any input will need converting to dchars (I expect
this can be done on the fly).

In C++ you would use iterators to do this kind of input conversion. I don't
know what the technique is in D.

Regards,

Ben
Jun 24 2010
next sibling parent Jesse Phillips <jessekphillips+d gmail.com> writes:
On Thu, 24 Jun 2010 11:35:50 +0000, Ben Hanson wrote:

 It seems like the best way to go is to use dchar for strings (i.e. not
 have the struct as a template) as I need real characters for
 intersection purposes. When it comes to lookup, any input will need
 converting to dchars (I expect this can be done on the fly).
 
 In C++ you would use iterators to do this kind of input conversion. I
 don't know what the technique is in D.
 
 Regards,
 
 Ben

import std.conv; void charDoThing(charT)(charT[] stuff) { dchar[] sameStuff = to!(dchar[])(stuff); }
Jun 24 2010
prev sibling next sibling parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 06/24/2010 06:35 AM, Ben Hanson wrote:
 It seems like the best way to go is to use dchar for strings (i.e. not have
 the struct as a template) as I need real characters for intersection purposes.
 When it comes to lookup, any input will need converting to dchars (I expect
 this can be done on the fly).

 In C++ you would use iterators to do this kind of input conversion. I don't
 know what the technique is in D.

 Regards,

 Ben

like import std.array; string s; dchar first = s.front; dchar last = s.back; or import std.utf string s; int old_offset; int offset = stride(s, old_offset) dchar d = decode(s, old_offset + offset); ?
Jun 24 2010
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Ben Hanson <Ben.Hanson tfbplc.co.uk> wrote:

 It seems like the best way to go is to use dchar for strings (i.e. not  
 have
 the struct as a template) as I need real characters for intersection  
 purposes.
 When it comes to lookup, any input will need converting to dchars (I  
 expect
 this can be done on the fly).

 In C++ you would use iterators to do this kind of input conversion. I  
 don't
 know what the technique is in D.

import std.range; auto s = "Hello world!"; s.front; // Returns dchars Is this what you want? -- Simen
Jun 24 2010