Created
November 15, 2011 15:04
-
-
Save seaneagan/1367275 to your computer and use it in GitHub Desktop.
Dart Collection changes implications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Strings are ReadableLists of chars */ | |
interface String extends ReadableList<char>, Pattern { | |
String(Iterable<int> other); | |
// Accessors | |
String toLowerCase ( ); | |
String toUpperCase ( ); | |
String trim ( ); | |
String getRange (Range range ); // replaces subString | |
String replaceFirst (Pattern pattern, String with); | |
String replaceAll (Pattern pattern, String with); | |
bool endsWith (Pattern pattern ); // generalize from Strings to Patterns | |
bool startsWith (Pattern pattern ); // generalize from Strings to Patterns | |
ReadableList<String> split (Pattern pattern ); | |
} | |
/** | |
* chars are ints which represent unicode characters | |
* could add other metadata, similar to java.lang.Character | |
*/ | |
interface char extends int { | |
const char(int other); | |
// returns String with this sole char | |
toString(); | |
} | |
interface Pattern { | |
// replaces/generalizes Regexp.hasMatch, String.contains | |
bool hasMatch (String str ); | |
// replaces/generalizes String.indexOf | |
Match firstMatch (String str, [int start]); | |
// replaces/generalizes String.lastIndexOf | |
Match lastMatch (String str, [int start]); | |
Collection<Match> allMatches (String str ); | |
} | |
/** Regexps are Patterns with advanced matching rules */ | |
interface RegExp extends Pattern { | |
RegExp(String pattern, [bool multiLine, bool ignoreCase]); | |
String pattern; | |
bool ignoreCase; | |
bool multiLine; | |
ReadableList<RegExp> get groups(); // Regexps for each group in this RegExp | |
RegExpMatch firstMatch (String string, [int start]); | |
RegExpMatch lastMatch (String string, [int start]); | |
ReadableList<RegExpMatch> allMatches (String string ); | |
} | |
/** | |
* Matches are Ranges in which a String matches a Pattern | |
* Inherited ReadableList.{first,last} replace Match.{start(),end()} | |
*/ | |
interface Match extends Range { | |
Pattern pattern; | |
String string; // lengthen "str" to "string" for clarity | |
// replaces RegExp.stringMatch | |
toString(); // => string.getRange(this) | |
} | |
/** RegExpMatches are Matches specialized for RegExps */ | |
interface RegExpMatch extends Match { | |
/** | |
* groups[i] -> | |
* string: this.toString(), | |
* pattern: this.pattern.groups[i], | |
* range: offset from groups[i].string not this.string | |
*/ | |
ReadableList<Match> get groups(); | |
// remove groupCount(), just use `groups.size` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment