Eike Rathke wrote:
But you are right, reverse-iterating code does look more awkward. Would
it help if postIncrementCodePoints actually acted as
preIncrementCodePoints if it is negative? Is not that what we want?
It is.
Or is it to confusing?
I don't think so. Well, maybe at the beginning, but it does what we want :-)
it just reverses the entire behavior.
sal_Int32 i = s.getLength();
while (i != 0) {
sal_uInt32 c = s.iterateCodePoints(&i, -1);
}
would then neatly reverse-iterate through any string, and we would get
rid of the ugly SAL_MAX_UINT32 special-case return value.
What if 'i' is 0, and maybe 's' also an empty string? This wouldn't
happen in a proper loop, but a call to iterateCodePoints() in these
cases would result in what?
s.iterateCodePoints(&i, +1) => i== 0 ? because getLength()==0
s.iterateCodePoints(&i, 0) => i== 0 ? because not iterating
s.iterateCodePoints(&i, -1) => i==-1 ? because preincremented past the
beginning
And the return value?
All three cases would be undefined behavior. I would change the
preconditions for
iterateCodePoints(
sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints)
as follows:
- indexUtf16 must not be null
- if incrementCodePoints >= 0:
- *indexUtf16 must be in [0 .. length[
- *indexUtf16 + incrementCodePoints must be in [0 .. length]
- if incrementCodePoints < 0:
- *indexUtf16 must be in [0 .. length]
- *indexUtf16 + incrementCodePoints must be in [0 .. length[
-Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]