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

Side by Side Diff: runtime/lib/string.dart

Issue 8333001: Implement case mapping using the Unicode default case mapping algorithm. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Renamed result string variables. Created 9 years, 2 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
« no previous file with comments | « runtime/lib/string.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * [StringBase] contains common methods used by concrete String implementations, 6 * [StringBase] contains common methods used by concrete String implementations,
7 * e.g., OneByteString. 7 * e.g., OneByteString.
8 */ 8 */
9 class StringBase { 9 class StringBase {
10 10
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 327
328 Array<int> charCodes() { 328 Array<int> charCodes() {
329 int len = this.length; 329 int len = this.length;
330 final result = new Array<int>(len); 330 final result = new Array<int>(len);
331 for (int i = 0; i < len; i++) { 331 for (int i = 0; i < len; i++) {
332 result[i] = this.charCodeAt(i); 332 result[i] = this.charCodeAt(i);
333 } 333 }
334 return result; 334 return result;
335 } 335 }
336 336
337 String toLowerCase() { 337 String toUpperCase() native "String_toUpperCase";
338 final int aCode = "A".charCodeAt(0);
339 final int zCode = "Z".charCodeAt(0);
340 final int delta = aCode - "a".charCodeAt(0);
341 return _convert(this, aCode, zCode, delta);
342 }
343 338
344 String toUpperCase() { 339 String toLowerCase() native "String_toLowerCase";
345 final int aCode = "a".charCodeAt(0);
346 final int zCode = "z".charCodeAt(0);
347 final int delta = aCode - "A".charCodeAt(0);
348 return _convert(this, aCode, zCode, delta);
349 }
350
351 static String _convert(String str, int startCode, int endCode, int delta) {
352 final int len = str.length;
353 int i = 0;
354 // Check if we can just return the string.
355 for (; i < len; i++) {
356 int code = str.charCodeAt(i);
357 if ((startCode <= code) && (code <= endCode)) break;
358 }
359 if (i == len) return str;
360
361 Array<int> charCodes = new Array<int>(len);
362 for (i = 0; i < len; i++) {
363 int code = str.charCodeAt(i);
364 if ((startCode <= code) && (code <= endCode)) {
365 code = code - delta;
366 }
367 charCodes[i] = code;
368 }
369 return StringBase.createFromCharCodes(charCodes);
370 }
371
372
373 340
374 // Implementations of Strings methods follow below. 341 // Implementations of Strings methods follow below.
375 static String join(Array<String> strings, String separator) { 342 static String join(Array<String> strings, String separator) {
376 final int length = strings.length; 343 final int length = strings.length;
377 if (length === 0) { 344 if (length === 0) {
378 return ""; 345 return "";
379 } 346 }
380 347
381 Array strings_array = strings; 348 Array strings_array = strings;
382 if (separator.length != 0) { 349 if (separator.length != 0) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 for (int g in groups) { 435 for (int g in groups) {
469 result.add(group(g)); 436 result.add(group(g));
470 } 437 }
471 return result; 438 return result;
472 } 439 }
473 440
474 final int _start; 441 final int _start;
475 final String str; 442 final String str;
476 final String pattern; 443 final String pattern;
477 } 444 }
OLDNEW
« no previous file with comments | « runtime/lib/string.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698