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

Side by Side Diff: sdk/lib/core/string.dart

Issue 172153002: Add String.repeat, String.padLeft, String.padRight. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * A sequence of characters. 8 * A sequence of characters.
9 * 9 *
10 * A string can be either single or multiline. Single line strings are 10 * A string can be either single or multiline. Single line strings are
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 * 2029 ; White_Space # Zp PARAGRAPH SEPARATOR 319 * 2029 ; White_Space # Zp PARAGRAPH SEPARATOR
320 * 202F ; White_Space # Zs NARROW NO-BREAK SPACE 320 * 202F ; White_Space # Zs NARROW NO-BREAK SPACE
321 * 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE 321 * 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
322 * 3000 ; White_Space # Zs IDEOGRAPHIC SPACE 322 * 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
323 * 323 *
324 * FEFF ; BOM ZERO WIDTH NO_BREAK SPACE 324 * FEFF ; BOM ZERO WIDTH NO_BREAK SPACE
325 */ 325 */
326 String trim(); 326 String trim();
327 327
328 /** 328 /**
329 * Creates a new string that repeats this string a number of times.
330 *
331 * If [separator] is provided, it is insert between the copies
floitsch 2014/02/19 10:20:36 it is inserted
Lasse Reichstein Nielsen 2014/02/19 11:43:16 Done.
332 * of this string.
333 *
334 * The [times] number must be non-negative.
335 */
336 String repeat(int times, [String separator = ""]);
floitsch 2014/02/19 10:20:36 Do we really need this one? The only good use-cas
Lasse Reichstein Nielsen 2014/02/19 11:43:16 If we have padLeft, you can do str.repeat(n) by do
337
338 /**
339 * Pads this string on the left if it is shorther than [newSize].
340 *
341 * For each position the length of this string is shorter than [newSize],
342 * a copy of [padding] is added on the left.
343 * If the length of this string is already greater than [newSize],
344 * this string is returned unmodified.
345 *
346 * If [padding] has length greater than 1,
347 * the resulting string's length will be greater than [newSize].
348 * This can be used for cases where the logical length of a string
349 * is not its length in code points.
350 * Example:
351 *
352 * "foo".padLeft(10, " "); // String representing single space.
353 * "foo".padLeft(10, "\u{100002}"); // Surrogate pair character.
354 *
355 * If [size] is provided, it is used as instead of `this.length`
356 * as the size of this string.
357 * If the string contains, for example, surrogate pairs,
358 * and it is intended to be treated as charaters, not code points,
359 * [size] can be used to provide the logical length.
360 * Example:
361 *
362 * "D&D".padLeft(10, " ", size: 3);
363 *
364 * The [size] number must be non-negative.
365 * If [newSize] is negative, no padding will happen.
366 */
367 String padLeft(int newSize, String padding, { int size });
floitsch 2014/02/19 10:20:36 I'm not convinced that dealing with surrogate pair
Søren Gjesse 2014/02/19 10:44:10 I find the option of padding with size larger than
Lasse Reichstein Nielsen 2014/02/19 11:43:16 This is not (just) dealing with surrogate pairs. I
368
369 /**
370 * Pads this string on the right if it is shorther than [newSize].
371 *
372 * For each position the length of this string is shorter than [newSize],
373 * a copy of [padding] is added on the right.
374 * If the length of this string is already greater than [newSize],
375 * this string is returned unmodified.
376 *
377 * If [padding] has length greater than 1,
378 * the resulting string's length will be greater than [newSize].
379 * This can be used for cases where the logical length of a string
380 * is not its length in code points.
381 * Example:
382 *
383 * "foo".padRight(10, " "); // String representing single space.
384 * "foo".padRight(10, "\u{100002}"); // Surrogate pair character.
385 *
386 * If [size] is provided, it is used as instead of `this.length`
387 * as the size of this string.
388 * If the string contains, for example, surrogate pairs,
389 * and it is intended to be treated as charaters, not code points,
390 * [size] can be used to provide the logical length.
391 * Example:
392 *
393 * "D&D".padLeft(10, " ", size: 3);
394 *
395 * The [size] number must be non-negative.
396 * If [newSize] is negative, no padding will happen.
397 */
398 String padRight(int newSize, String padding, {int size});
399
400 /**
329 * Returns true if this string contains a match of [other]: 401 * Returns true if this string contains a match of [other]:
330 * 402 *
331 * var string = 'Dart strings'; 403 * var string = 'Dart strings';
332 * string.contains('D'); // true 404 * string.contains('D'); // true
333 * string.contains(new RegExp(r'[A-Z]')); // true 405 * string.contains(new RegExp(r'[A-Z]')); // true
334 * 406 *
335 * If [startIndex] is provided, this method matches only at or after that 407 * If [startIndex] is provided, this method matches only at or after that
336 * index: 408 * index:
337 * 409 *
338 * string.contains('X', 1); // false 410 * string.contains('X', 1); // false
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 _position = position - 1; 742 _position = position - 1;
671 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit); 743 _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit);
672 return true; 744 return true;
673 } 745 }
674 } 746 }
675 _position = position; 747 _position = position;
676 _currentCodePoint = codeUnit; 748 _currentCodePoint = codeUnit;
677 return true; 749 return true;
678 } 750 }
679 } 751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698