www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - decodeReverse

reply "HaraldZealot" <harald_zealot tut.by> writes:
For my particular project (it binds with something like finite 
state machine) I will write some counterpart of decode function 
from std.utf. Future function will decode string backward, return 
dchar and change index passed by reference.

Is it interesting for community that I code this feature in 
general way targeting in phobos for future?
Jan 05 2015
next sibling parent reply "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Tuesday, 6 January 2015 at 06:43:13 UTC, HaraldZealot wrote:
 For my particular project (it binds with something like finite 
 state machine) I will write some counterpart of decode function 
 from std.utf. Future function will decode string backward, 
 return dchar and change index passed by reference.

 Is it interesting for community that I code this feature in 
 general way targeting in phobos for future?
For UTF, there's already std.utf.strideBack which does most of the work. I don't know why there is no std.utf.decodeBack - should be very simple to wrap over strideBack. However, for grapheme clusters, there isn't yet a counterpart for std.uni.graphemeStride/decodeGrapheme, which notably affects std.uni.byGrapheme, which is currently not a bidirectional range. Any improvement would be much appreciated.
Jan 06 2015
parent reply Jonathan M Davis via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Tuesday, January 06, 2015 08:09:57 Jakob Ovrum via Digitalmars-d wrote:
 On Tuesday, 6 January 2015 at 06:43:13 UTC, HaraldZealot wrote:
 For my particular project (it binds with something like finite
 state machine) I will write some counterpart of decode function
 from std.utf. Future function will decode string backward,
 return dchar and change index passed by reference.

 Is it interesting for community that I code this feature in
 general way targeting in phobos for future?
For UTF, there's already std.utf.strideBack which does most of the work. I don't know why there is no std.utf.decodeBack - should be very simple to wrap over strideBack.
I'm pretty sure that you basically have to do what strideBack does before you can decode a code point, so all decodeBack would do would be to do exactly what back already does for strings, which is to use strideBack followed by decode. - Jonathan M Davis
Jan 06 2015
parent "HaraldZealot" <harald_zealot tut.by> writes:
 I'm pretty sure that you basically have to do what strideBack 
 does before
 you can decode a code point, so all decodeBack would do would 
 be to do
 exactly what back already does for strings, which is to use 
 strideBack
 followed by decode.

 - Jonathan M Davis
I have to read more attentively std.utf, but strideBack seems very suitable for me. Thanks you both!!!
Jan 06 2015
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/5/15 10:43 PM, HaraldZealot wrote:
 For my particular project (it binds with something like finite state
 machine) I will write some counterpart of decode function from std.utf.
 Future function will decode string backward, return dchar and change
 index passed by reference.

 Is it interesting for community that I code this feature in general way
 targeting in phobos for future?
back() and popBack() for narrow strings do reverse decode. -- Andrei
Jan 06 2015
parent "HaraldZealot" <harald_zealot tut.by> writes:
On Tuesday, 6 January 2015 at 16:58:24 UTC, Andrei Alexandrescu 
wrote:
 On 1/5/15 10:43 PM, HaraldZealot wrote:
 For my particular project (it binds with something like finite 
 state
 machine) I will write some counterpart of decode function from 
 std.utf.
 Future function will decode string backward, return dchar and 
 change
 index passed by reference.

 Is it interesting for community that I code this feature in 
 general way
 targeting in phobos for future?
back() and popBack() for narrow strings do reverse decode. -- Andrei
I need reverse decode from any position, not only from the last. I have coded a litle with stideBack allready, it works. But usage isn't clear as could: first strideBack, then decode, and decode move index forward, then I have to strideBack again :) Perhaps i will wrap such algorithm in some function, but an other side i will be forced to optimize that and write real decodeBack function.
Jan 06 2015