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

Issue 16957002: Use Pattern.matchAsPrefix to let String.indexOf/lastIndexOf/startsWith accept Pattern. (Closed)

Created:
7 years, 6 months ago by Lasse Reichstein Nielsen
Modified:
7 years, 6 months ago
Reviewers:
floitsch, sra1
CC:
reviews_dartlang.org, regis, ngeoffray
Visibility:
Public.

Description

Use Pattern.matchAsPrefix to let String.indexOf/lastIndexOf/startsWith accept Pattern. Rearranged co19-runtime.status to only have one section for each configuration, and tried to keep them in a logical order. BUG=http://dartbug.com/11129 R=floitsch@google.com Committed: https://code.google.com/p/dart/source/detail?r=23974

Patch Set 1 #

Total comments: 6

Patch Set 2 : Addressed review comments. #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+315 lines, -208 lines) Patch
M runtime/lib/string_patch.dart View 1 2 chunks +41 lines, -25 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/interceptors.dart View 1 chunk +2 lines, -1 line 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/js_string.dart View 2 chunks +45 lines, -24 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart View 2 chunks +32 lines, -9 lines 0 comments Download
M sdk/lib/core/string.dart View 1 chunk +14 lines, -8 lines 2 comments Download
M tests/co19/co19-dart2dart.status View 1 chunk +2 lines, -0 lines 0 comments Download
M tests/co19/co19-dart2js.status View 1 chunk +2 lines, -0 lines 0 comments Download
M tests/co19/co19-runtime.status View 13 chunks +76 lines, -87 lines 0 comments Download
M tests/corelib/string_test.dart View 1 7 chunks +101 lines, -54 lines 0 comments Download

Messages

Total messages: 9 (0 generated)
Lasse Reichstein Nielsen
7 years, 6 months ago (2013-06-13 10:39:20 UTC) #1
floitsch
Not convinced of the co19 status-file change, but LGTM. https://codereview.chromium.org/16957002/diff/1/runtime/lib/string_patch.dart File runtime/lib/string_patch.dart (right): https://codereview.chromium.org/16957002/diff/1/runtime/lib/string_patch.dart#newcode146 runtime/lib/string_patch.dart:146: ...
7 years, 6 months ago (2013-06-13 11:54:58 UTC) #2
floitsch
Also missing: tests.
7 years, 6 months ago (2013-06-13 11:55:22 UTC) #3
Lasse Reichstein Nielsen
https://codereview.chromium.org/16957002/diff/1/runtime/lib/string_patch.dart File runtime/lib/string_patch.dart (right): https://codereview.chromium.org/16957002/diff/1/runtime/lib/string_patch.dart#newcode146 runtime/lib/string_patch.dart:146: // Consider using an efficient string search (e.g. BMH). ...
7 years, 6 months ago (2013-06-13 12:37:49 UTC) #4
Lasse Reichstein Nielsen
Also, tests were already added to corelib/string_test to test RegExp patterns in startsWith, indexOf and ...
7 years, 6 months ago (2013-06-13 12:39:26 UTC) #5
Lasse Reichstein Nielsen
Committed patchset #2 manually as r23974 (presubmit successful).
7 years, 6 months ago (2013-06-13 12:49:54 UTC) #6
sra1
DBC. This CL stops short of fixing https://code.google.com/p/dart/issues/detail?id=158 Is fixing Issue 158 next? https://codereview.chromium.org/16957002/diff/9001/sdk/lib/core/string.dart File ...
7 years, 6 months ago (2013-06-13 17:49:21 UTC) #7
Lasse Reichstein Nielsen
You should be able to handle issue 158 with string.matchAsPrefix itself: string1 occurs in string2 ...
7 years, 6 months ago (2013-06-13 19:43:55 UTC) #8
sra1
7 years, 6 months ago (2013-06-13 20:33:06 UTC) #9
Message was sent while issue was closed.
On 2013/06/13 19:43:55, Lasse Reichstein Nielsen wrote:
> You should be able to handle issue 158 with string.matchAsPrefix itself:
>   string1 occurs in string2 at position p if string1.matchAsPrefix(string2, p)
> returns a match.

I can accomplish the task but it does not feel like a nice API.

s.startsWith('foo', i)
'foo'.matchAsPrefix(s, i) != null   // verbose, sounds like Yoda, wasteful
allocation

I see there are a lot of methods on RegExp that could be on Pattern.
firstMatch and hasMatch suggest renaming matchAsPrefix to (matchAt, hasMatchAt).
But these names on String would probably be confusing  (p.hasMatch(s) ===
s.contains(p))

Perhaps all the matching functions need a preposition to indicate the, e.g 
'foo'.hasMatchIn(s)

That String is both a Pattern and the subject of matching does make choosing
these names difficult.



> 
> https://codereview.chromium.org/16957002/diff/9001/sdk/lib/core/string.dart
> File sdk/lib/core/string.dart (right):
> 
>
https://codereview.chromium.org/16957002/diff/9001/sdk/lib/core/string.dart#n...
> sdk/lib/core/string.dart:126: * Returns -1 if [other] could not be found.
> Ack!

Powered by Google App Engine
This is Rietveld 408576698