Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Issue 12094056: Runes, a bi-directional code-point iterator/iterable. (Closed)

Created:
7 years, 10 months ago by Lasse Reichstein Nielsen
Modified:
7 years, 10 months ago
Reviewers:
erikcorry, floitsch
CC:
erikcorry
Visibility:
Public.

Description

Bi-directional iterator for runes of a string. Committed: https://code.google.com/p/dart/source/detail?r=18382

Patch Set 1 #

Total comments: 3

Patch Set 2 : Updated based on comments and new ideas. #

Patch Set 3 : Make set rawIndex read next char. Add reset. Fix bugs. #

Patch Set 4 : Fix index bug in split-surrogate test. #

Patch Set 5 : Specialized first/last on Runes. #

Patch Set 6 : Hooked up to String and added tests. #

Total comments: 23

Patch Set 7 : Address review comments. #

Patch Set 8 : Make rawIndex return null if there is no current rune. #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+295 lines, -8 lines) Patch
M runtime/lib/string_base.dart View 1 2 3 4 5 1 chunk +1 line, -3 lines 0 comments Download
M sdk/lib/_collection_dev/iterable.dart View 1 2 3 4 5 1 chunk +5 lines, -0 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/js_string.dart View 1 2 3 4 5 1 chunk +1 line, -3 lines 0 comments Download
M sdk/lib/core/iterable.dart View 1 2 3 4 5 1 chunk +13 lines, -0 lines 0 comments Download
M sdk/lib/core/string.dart View 1 2 3 4 5 6 7 2 chunks +197 lines, -2 lines 0 comments Download
A tests/corelib/string_runes_test.dart View 1 2 3 4 5 6 7 1 chunk +78 lines, -0 lines 1 comment Download

Messages

Total messages: 12 (0 generated)
Lasse Reichstein Nielsen
What do you think?
7 years, 10 months ago (2013-01-30 12:12:34 UTC) #1
floitsch
Adding Erik. Like it, but we need to expose the rawIndex (and possibly the string ...
7 years, 10 months ago (2013-01-30 13:12:13 UTC) #2
erikcorry
Needs a test (I don't think it works, seems to use the first surrogate as ...
7 years, 10 months ago (2013-01-30 13:26:55 UTC) #3
Lasse Reichstein Nielsen
https://codereview.chromium.org/12094056/diff/1/sdk/lib/core/string.dart File sdk/lib/core/string.dart (right): https://codereview.chromium.org/12094056/diff/1/sdk/lib/core/string.dart#newcode237 sdk/lib/core/string.dart:237: bool moveNext() { ACK. I was using _readCharForward in ...
7 years, 10 months ago (2013-01-30 14:03:37 UTC) #4
Lasse Reichstein Nielsen
PTAL, ready to commit.
7 years, 10 months ago (2013-02-12 14:05:45 UTC) #5
floitsch
LGTM. https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart File sdk/lib/core/string.dart (right): https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart#newcode309 sdk/lib/core/string.dart:309: int get first { You think it's worth ...
7 years, 10 months ago (2013-02-12 14:23:10 UTC) #6
Lasse Reichstein Nielsen
https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart File sdk/lib/core/string.dart (right): https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart#newcode309 sdk/lib/core/string.dart:309: int get first { Probably not. Let's drop it. ...
7 years, 10 months ago (2013-02-12 15:13:23 UTC) #7
Lasse Reichstein Nielsen
https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart File sdk/lib/core/string.dart (right): https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart#newcode400 sdk/lib/core/string.dart:400: * If the current rune is null, this is ...
7 years, 10 months ago (2013-02-12 15:20:23 UTC) #8
erikcorry
https://codereview.chromium.org/12094056/diff/21001/tests/corelib/string_runes_test.dart File tests/corelib/string_runes_test.dart (right): https://codereview.chromium.org/12094056/diff/21001/tests/corelib/string_runes_test.dart#newcode64 tests/corelib/string_runes_test.dart:64: test("\u{ffff}\u{10000}\u{10ffff}", [0xffff, 0x10000, 0x10ffff]); Can we have at least ...
7 years, 10 months ago (2013-02-13 08:58:54 UTC) #9
floitsch
https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart File sdk/lib/core/string.dart (right): https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart#newcode408 sdk/lib/core/string.dart:408: * Setting a negative [rawIndex], or one greater than ...
7 years, 10 months ago (2013-02-13 10:12:19 UTC) #10
Lasse Reichstein Nielsen
https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart File sdk/lib/core/string.dart (right): https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart#newcode425 sdk/lib/core/string.dart:425: * Setting a negative [rawIndex], or one greater than ...
7 years, 10 months ago (2013-02-13 17:20:42 UTC) #11
floitsch
7 years, 10 months ago (2013-02-13 17:34:50 UTC) #12
Message was sent while issue was closed.
https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart
File sdk/lib/core/string.dart (right):

https://codereview.chromium.org/12094056/diff/15001/sdk/lib/core/string.dart#...
sdk/lib/core/string.dart:425: * Setting a negative [rawIndex], or one greater
than [:string.length:],
On 2013/02/13 17:20:42, Lasse Reichstein Nielsen wrote:
> On 2013/02/13 10:12:19, floitsch wrote:
> > On 2013/02/12 15:13:23, Lasse Reichstein Nielsen wrote:
> > > For what?
> > > reset(0) is a reset to the beginning of the string.
> > > reset(string.length) positions you just after the last rune.
> > > It works here, like <deity> intended indices to work!
> > 
> > If I reset to (0) and then moveNext I don't expect to get a code-unit at
> > position 0. I just moved away from it!
> 
> That's not how RuneIterator.reset works. 
> Are you talking about assigning zero to rawIndex?
> 
> There are two ways to set a position:
> - setting rawIndex of the character you want to be current.
> Valid indices are 0 .. length - 1.
> - resetting to a state with no current, but so that the character you want
will
> be current after a moveNext, or the previous one will be after a movePrevious.
> Valid indices are 0 .. length.
> 
> This allows reset to position the iterator AT the end of the list (which can't
> have a current value), but does not allow setting rawIndex there.
> 
> The reset functionality is essential if you need to do something to the
> iterator, and then pass it to another function that expects to start with a
> moveNext (which is likely to be the case). I like to have this functionality
> generalized so that I can reset to any index without a current value - so
reset
> does that for me.
> 
> > 
> > Currently you allow to set length+1 positions. Basically to every code-unit,
> and
> > to the position after the last code-unit. 
> I changed that to only allowing 0..length - 1, i.e., only indices of actual
code
> units.
> 
> > What's missing is the position before
> > the first code-unit, so that a moveNext brings you to the first position.
> 
> There is no "positions before the first". That is not a position. It has no
> rawIndex (now that rawIndex returns null on a newly created iterator).
> 
> Setting the iterator so that moveNext hits the first rune, or movePrevious
hits
> the last rune, means that you can't use setting rawIndex for it, because that
> always points to a rune.
> 
> I guess we can make special cases for that if you think it's worth it.
> 
> > And yes: I know you see it differently, but nobody else does.
> 
> Ok, then. How do you want setting rawIndex to work?
> 
> For 0..length - 1 it currently set the iterator to a state where current is
the
> rune starting at the index.
> 
> What do you want to happen for length?
> 
> What do you want to happen for -1?
> 
> Are there any other cases it should cover?
> 
> Just say so, and the CL will be in the mail :)

Ok for original behavior for reset (including allowing string.length).

Powered by Google App Engine
This is Rietveld 408576698