google / quiver-dart

A set of utility libraries for Dart
https://pub.dev/packages/quiver
Apache License 2.0
1.02k stars 133 forks source link

Add: Index-based string manipulation functions and C#-esque interpolation option. #171

Open ghost opened 10 years ago

ghost commented 10 years ago

Hoping someone will merge this some day, been sitting in limbo :(

String.capitalize() to capitalize each first a-zA-Z letter of each word in a string.

Index-based insertion, replacement, and removal.

Similar implementation of C# String.Format(..) (only supporting the index-based interpolation by way of "{index}" and arbitrary length parameters. Can be used by way of .formatString(original, arg0, arg1, arg2, ..., argAdInfinitum) (uses noSuchMethod) or by passing a List with the 0th element containing the original string (both methods use the same actual function, the one with the variable-length argument list is a hack with noSuchMehod at the helm, which takes the arguments and extracts them into a List for use with formatStringList). Will accept any object, as it uses toString() to grab the value to be interpolated. This allows for doing simple interpolation with string variables instead of literals. Allowing for centralized management of "template" string constants or less formal localization. (Dart's current localization scheme is very verbose.)

ghost commented 10 years ago

To continue on this after some comments on the PR, here's some of the functionality I'd like to work toward. http://msdn.microsoft.com/en-us/library/26etazsy(v=vs.110).aspx Take what makes sense to have as an alternative and include it, and/or work with the existing functionality and leverage it to this end.

I feel that this form of interpolation is quite handy to have as a terse alternative to some of the others I've seen (mustache templates, Dart's built in localization, and Dart's own built-in interpolation with the handicap that it requires a literal in the spot where the string is interpolated, leading to having strings spread out all among the code).

As for the most efficient way to go about implementing the actual parsing of these strings, we can discuss that here. I'm sure those with greater knowledge of the finer details of performance concerns can help in this matter.