refactor(StringWrapper): remove useless methods

Closes #5039
This commit is contained in:
Victor Berchet 2015-10-31 13:04:26 -07:00
parent c5693f07dc
commit a0a627f2f9
19 changed files with 33 additions and 110 deletions

View File

@ -9,6 +9,7 @@ module.exports = function (config) {
frameworks: ['jasmine'], frameworks: ['jasmine'],
files: [ files: [
'../../node_modules/es6-shim/es6-shim.js',
'../../node_modules/angular/angular.js', '../../node_modules/angular/angular.js',
'../../node_modules/angular-animate/angular-animate.js', '../../node_modules/angular-animate/angular-animate.js',
'../../node_modules/angular-mocks/angular-mocks.js', '../../node_modules/angular-mocks/angular-mocks.js',

View File

@ -247,18 +247,10 @@ var StringWrapper = {
return s.split(re); return s.split(re);
}, },
substring: function(s, start, end) {
return s.substr(start, end);
},
replaceAll: function(s, from, replace) { replaceAll: function(s, from, replace) {
return s.replace(from, replace); return s.replace(from, replace);
}, },
startsWith: function(s, start) {
return s.substr(0, start.length) === start;
},
replaceAllMapped: function(s, from, cb) { replaceAllMapped: function(s, from, cb) {
return s.replace(from, function(matches) { return s.replace(from, function(matches) {
// Remove offset & string from the result array // Remove offset & string from the result array

View File

@ -1,4 +1,4 @@
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/core/facade/lang'; import {isString, CONST, isBlank} from 'angular2/src/core/facade/lang';
import {Injectable} from 'angular2/src/core/di'; import {Injectable} from 'angular2/src/core/di';
import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection'; import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
import {Pipe} from 'angular2/src/core/metadata'; import {Pipe} from 'angular2/src/core/metadata';
@ -32,6 +32,6 @@ export class LowerCasePipe implements PipeTransform {
if (!isString(value)) { if (!isString(value)) {
throw new InvalidPipeArgumentException(LowerCasePipe, value); throw new InvalidPipeArgumentException(LowerCasePipe, value);
} }
return StringWrapper.toLowerCase(value); return value.toLowerCase();
} }
} }

View File

@ -1,4 +1,4 @@
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/core/facade/lang'; import {isString, CONST, isBlank} from 'angular2/src/core/facade/lang';
import {Pipe} from 'angular2/src/core/metadata'; import {Pipe} from 'angular2/src/core/metadata';
import {Injectable} from 'angular2/src/core/di'; import {Injectable} from 'angular2/src/core/di';
import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection'; import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
@ -31,6 +31,6 @@ export class UpperCasePipe implements PipeTransform {
if (!isString(value)) { if (!isString(value)) {
throw new InvalidPipeArgumentException(UpperCasePipe, value); throw new InvalidPipeArgumentException(UpperCasePipe, value);
} }
return StringWrapper.toUpperCase(value); return value.toUpperCase();
} }
} }

View File

@ -254,8 +254,8 @@ class TemplateParseVisitor implements HtmlAstVisitor {
var templateBindingsSource = null; var templateBindingsSource = null;
if (attr.name == TEMPLATE_ATTR) { if (attr.name == TEMPLATE_ATTR) {
templateBindingsSource = attr.value; templateBindingsSource = attr.value;
} else if (StringWrapper.startsWith(attr.name, TEMPLATE_ATTR_PREFIX)) { } else if (attr.name.startsWith(TEMPLATE_ATTR_PREFIX)) {
var key = StringWrapper.substring(attr.name, TEMPLATE_ATTR_PREFIX.length); // remove the star var key = attr.name.substring(TEMPLATE_ATTR_PREFIX.length); // remove the star
templateBindingsSource = (attr.value.length == 0) ? key : key + ' ' + attr.value; templateBindingsSource = (attr.value.length == 0) ? key : key + ' ' + attr.value;
} }
if (isPresent(templateBindingsSource)) { if (isPresent(templateBindingsSource)) {
@ -333,8 +333,7 @@ class TemplateParseVisitor implements HtmlAstVisitor {
} }
private _normalizeAttributeName(attrName: string): string { private _normalizeAttributeName(attrName: string): string {
return StringWrapper.startsWith(attrName, 'data-') ? StringWrapper.substring(attrName, 5) : return attrName.startsWith('data-') ? attrName.substring(5) : attrName;
attrName;
} }
private _parseVariable(identifier: string, value: string, sourceInfo: any, private _parseVariable(identifier: string, value: string, sourceInfo: any,

View File

@ -1,5 +1,5 @@
import {ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection'; import {ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {isPresent, isFunction, StringWrapper, Type} from 'angular2/src/core/facade/lang'; import {isPresent, isFunction, Type} from 'angular2/src/core/facade/lang';
import {DomAdapter} from './dom_adapter'; import {DomAdapter} from './dom_adapter';
import {XHRImpl} from 'angular2/src/compiler/xhr_impl'; import {XHRImpl} from 'angular2/src/compiler/xhr_impl';
@ -20,7 +20,7 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
var domPrefixes = ['Webkit', 'Moz', 'O', 'ms']; var domPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
for (var i = 0; i < domPrefixes.length; i++) { for (var i = 0; i < domPrefixes.length; i++) {
if (isPresent(this.getStyle(element, domPrefixes[i] + 'AnimationName'))) { if (isPresent(this.getStyle(element, domPrefixes[i] + 'AnimationName'))) {
this._animationPrefix = '-' + StringWrapper.toLowerCase(domPrefixes[i]) + '-'; this._animationPrefix = '-' + domPrefixes[i].toLowerCase() + '-';
break; break;
} }
} }

View File

@ -80,18 +80,6 @@ class StringWrapper {
return s.replaceAll(from, replace); return s.replaceAll(from, replace);
} }
static String toUpperCase(String s) {
return s.toUpperCase();
}
static String toLowerCase(String s) {
return s.toLowerCase();
}
static startsWith(String s, String start) {
return s.startsWith(start);
}
static String slice(String s, [int start = 0, int end]) { static String slice(String s, [int start = 0, int end]) {
start = _startOffset(s, start); start = _startOffset(s, start);
end = _endOffset(s, end); end = _endOffset(s, end);
@ -102,10 +90,6 @@ class StringWrapper {
return s.substring(start, end); return s.substring(start, end);
} }
static String substring(String s, int start, [int end]) {
return s.substring(start, end);
}
static String replaceAllMapped(String s, RegExp from, Function cb) { static String replaceAllMapped(String s, RegExp from, Function cb) {
return s.replaceAllMapped(from, cb); return s.replaceAllMapped(from, cb);
} }

View File

@ -176,16 +176,6 @@ export class StringWrapper {
return s.slice(from, to === null ? undefined : to); return s.slice(from, to === null ? undefined : to);
} }
static toUpperCase(s: string): string { return s.toUpperCase(); }
static toLowerCase(s: string): string { return s.toLowerCase(); }
static startsWith(s: string, start: string): boolean { return s.startsWith(start); }
static substring(s: string, start: number, end: number = null): string {
return s.substring(start, end === null ? undefined : end);
}
static replaceAllMapped(s: string, from: RegExp, cb: Function): string { static replaceAllMapped(s: string, from: RegExp, cb: Function): string {
return s.replace(from, function(...matches) { return s.replace(from, function(...matches) {
// Remove offset & string from the result array // Remove offset & string from the result array

View File

@ -1,4 +1,3 @@
import {StringWrapper} from 'angular2/src/core/facade/lang';
export const EVENT_TARGET_SEPARATOR = ':'; export const EVENT_TARGET_SEPARATOR = ':';
export class EventConfig { export class EventConfig {
@ -9,8 +8,8 @@ export class EventConfig {
var separatorIdx = eventConfig.indexOf(EVENT_TARGET_SEPARATOR); var separatorIdx = eventConfig.indexOf(EVENT_TARGET_SEPARATOR);
if (separatorIdx > -1) { if (separatorIdx > -1) {
// long format: 'fieldName: eventName' // long format: 'fieldName: eventName'
fieldName = StringWrapper.substring(eventConfig, 0, separatorIdx).trim(); fieldName = eventConfig.substring(0, separatorIdx).trim();
eventName = StringWrapper.substring(eventConfig, separatorIdx + 1).trim(); eventName = eventConfig.substring(separatorIdx + 1).trim();
isLongForm = true; isLongForm = true;
} }
return new EventConfig(fieldName, eventName, isLongForm); return new EventConfig(fieldName, eventName, isLongForm);

View File

@ -1,11 +1,4 @@
import { import {CONST, Type, stringify, isPresent, isString} from 'angular2/src/core/facade/lang';
CONST,
Type,
stringify,
isPresent,
StringWrapper,
isString
} from 'angular2/src/core/facade/lang';
import {resolveForwardRef} from 'angular2/src/core/di'; import {resolveForwardRef} from 'angular2/src/core/di';
import {DependencyMetadata} from 'angular2/src/core/di/metadata'; import {DependencyMetadata} from 'angular2/src/core/di/metadata';
@ -192,7 +185,7 @@ export class QueryMetadata extends DependencyMetadata {
* returns a list of variable bindings this is querying for. * returns a list of variable bindings this is querying for.
* Only applicable if this is a variable bindings query. * Only applicable if this is a variable bindings query.
*/ */
get varBindings(): string[] { return StringWrapper.split(this.selector, new RegExp(",")); } get varBindings(): string[] { return this.selector.split(','); }
toString(): string { return `@Query(${stringify(this.selector)})`; } toString(): string { return `@Query(${stringify(this.selector)})`; }
} }

View File

@ -46,8 +46,7 @@ export class JSONPConnection_ extends JSONPConnection {
if (url.indexOf('=JSONP_CALLBACK&') > -1) { if (url.indexOf('=JSONP_CALLBACK&') > -1) {
url = StringWrapper.replace(url, '=JSONP_CALLBACK&', `=${callback}&`); url = StringWrapper.replace(url, '=JSONP_CALLBACK&', `=${callback}&`);
} else if (url.lastIndexOf('=JSONP_CALLBACK') === url.length - '=JSONP_CALLBACK'.length) { } else if (url.lastIndexOf('=JSONP_CALLBACK') === url.length - '=JSONP_CALLBACK'.length) {
url = url = url.substring(0, url.length - '=JSONP_CALLBACK'.length) + `=${callback}`;
StringWrapper.substring(url, 0, url.length - '=JSONP_CALLBACK'.length) + `=${callback}`;
} }
let script = this._script = _dom.build(url); let script = this._script = _dom.build(url);

View File

@ -1,4 +1,4 @@
import {CONST_EXPR, isPresent, isBlank, StringWrapper} from 'angular2/src/core/facade/lang'; import {CONST_EXPR, isPresent, isBlank} from 'angular2/src/core/facade/lang';
import { import {
Map, Map,
MapWrapper, MapWrapper,
@ -9,9 +9,9 @@ import {
function paramParser(rawParams: string = ''): Map<string, string[]> { function paramParser(rawParams: string = ''): Map<string, string[]> {
var map = new Map<string, string[]>(); var map = new Map<string, string[]>();
if (rawParams.length > 0) { if (rawParams.length > 0) {
var params: string[] = StringWrapper.split(rawParams, new RegExp('&')); var params: string[] = rawParams.split('&');
params.forEach((param: string) => { params.forEach((param: string) => {
var split: string[] = StringWrapper.split(param, new RegExp('=')); var split: string[] = param.split('=');
var key = split[0]; var key = split[0];
var val = split[1]; var val = split[1];
var list = isPresent(map.get(key)) ? map.get(key) : []; var list = isPresent(map.get(key)) ? map.get(key) : [];

View File

@ -93,8 +93,8 @@ var wildcardMatcher = /^\*([^\/]+)$/g;
function parsePathString(route: string): {[key: string]: any} { function parsePathString(route: string): {[key: string]: any} {
// normalize route as not starting with a "/". Recognition will // normalize route as not starting with a "/". Recognition will
// also normalize. // also normalize.
if (StringWrapper.startsWith(route, "/")) { if (route.startsWith("/")) {
route = StringWrapper.substring(route, 1); route = route.substring(1);
} }
var segments = splitBySlash(route); var segments = splitBySlash(route);

View File

@ -1,7 +1,6 @@
import { import {
RegExp, RegExp,
RegExpWrapper, RegExpWrapper,
StringWrapper,
isBlank, isBlank,
isPresent, isPresent,
isType, isType,
@ -46,8 +45,7 @@ export class RouteRecognizer {
if (config instanceof AuxRoute) { if (config instanceof AuxRoute) {
handler = new SyncRouteHandler(config.component, config.data); handler = new SyncRouteHandler(config.component, config.data);
let path = let path = config.path.startsWith('/') ? config.path.substring(1) : config.path;
StringWrapper.startsWith(config.path, '/') ? config.path.substring(1) : config.path;
var recognizer = new PathRecognizer(config.path, handler); var recognizer = new PathRecognizer(config.path, handler);
this.auxRoutes.set(path, recognizer); this.auxRoutes.set(path, recognizer);
return recognizer.terminal; return recognizer.terminal;
@ -136,11 +134,11 @@ export class Redirector {
toSegments: string[] = []; toSegments: string[] = [];
constructor(path: string, redirectTo: string) { constructor(path: string, redirectTo: string) {
if (StringWrapper.startsWith(path, '/')) { if (path.startsWith('/')) {
path = path.substring(1); path = path.substring(1);
} }
this.segments = path.split('/'); this.segments = path.split('/');
if (StringWrapper.startsWith(redirectTo, '/')) { if (redirectTo.startsWith('/')) {
redirectTo = redirectTo.substring(1); redirectTo = redirectTo.substring(1);
} }
this.toSegments = redirectTo.split('/'); this.toSegments = redirectTo.split('/');

View File

@ -5,14 +5,7 @@ import {
ObservableWrapper ObservableWrapper
} from 'angular2/src/core/facade/async'; } from 'angular2/src/core/facade/async';
import {Map, StringMapWrapper, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection'; import {Map, StringMapWrapper, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import { import {isBlank, isString, isPresent, Type, isArray} from 'angular2/src/core/facade/lang';
isBlank,
isString,
StringWrapper,
isPresent,
Type,
isArray
} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {RouteRegistry} from './route_registry'; import {RouteRegistry} from './route_registry';
import { import {
@ -537,11 +530,11 @@ class ChildRouter extends Router {
* Given: ['/a/b', {c: 2}] * Given: ['/a/b', {c: 2}]
* Returns: ['', 'a', 'b', {c: 2}] * Returns: ['', 'a', 'b', {c: 2}]
*/ */
var SLASH = new RegExp('/');
function splitAndFlattenLinkParams(linkParams: any[]): any[] { function splitAndFlattenLinkParams(linkParams: any[]): any[] {
return ListWrapper.reduce(linkParams, (accumulation, item) => { return ListWrapper.reduce(linkParams, (accumulation, item) => {
if (isString(item)) { if (isString(item)) {
return accumulation.concat(StringWrapper.split(item, SLASH)); let parts: String[] = item.split('/');
return accumulation.concat(parts);
} }
accumulation.push(item); accumulation.push(item);
return accumulation; return accumulation;

View File

@ -1,11 +1,5 @@
import {StringMapWrapper} from 'angular2/src/core/facade/collection'; import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import { import {isPresent, isBlank, RegExpWrapper, CONST_EXPR} from 'angular2/src/core/facade/lang';
isPresent,
isBlank,
StringWrapper,
RegExpWrapper,
CONST_EXPR
} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
/** /**
@ -79,10 +73,10 @@ function matchUrlSegment(str: string): string {
export class UrlParser { export class UrlParser {
private _remaining: string; private _remaining: string;
peekStartsWith(str: string): boolean { return StringWrapper.startsWith(this._remaining, str); } peekStartsWith(str: string): boolean { return this._remaining.startsWith(str); }
capture(str: string): void { capture(str: string): void {
if (!StringWrapper.startsWith(this._remaining, str)) { if (!this._remaining.startsWith(str)) {
throw new BaseException(`Expected "${str}".`); throw new BaseException(`Expected "${str}".`);
} }
this._remaining = this._remaining.substring(str.length); this._remaining = this._remaining.substring(str.length);

View File

@ -99,7 +99,7 @@ var _singleTagWhitelist = ['br', 'hr', 'input'];
export function stringifyElement(el): string { export function stringifyElement(el): string {
var result = ''; var result = '';
if (DOM.isElementNode(el)) { if (DOM.isElementNode(el)) {
var tagName = StringWrapper.toLowerCase(DOM.tagName(el)); var tagName = DOM.tagName(el).toLowerCase();
// Opening tag // Opening tag
result += `<${tagName}`; result += `<${tagName}`;

View File

@ -42,24 +42,7 @@ export function main() {
}); });
describe('String', () => { describe('String', () => {
var upper, lower, s; var s;
beforeEach(() => {
upper = 'SOMETHING';
lower = 'something';
});
it('should upper case a string', () => {
var str = StringWrapper.toUpperCase(lower);
expect(str).toEqual(upper);
});
it('should lower case a string', () => {
var str = StringWrapper.toLowerCase(upper);
expect(str).toEqual(lower);
});
describe('slice', () => { describe('slice', () => {
beforeEach(() => { s = "abcdefghij"; }); beforeEach(() => { s = "abcdefghij"; });

View File

@ -41,7 +41,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
if (isBlank(v)) { if (isBlank(v)) {
return -1; return -1;
} }
v = StringWrapper.split(v, /\./g)[0]; v = v.split('.')[0];
if (isBlank(v)) { if (isBlank(v)) {
return -1; return -1;
} }
@ -197,9 +197,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
return null; // nothing useful in this event return null; // nothing useful in this event
} }
private _parseCategories(categories: string): string[] { private _parseCategories(categories: string): string[] { return categories.split(','); }
return StringWrapper.split(categories, /,/g);
}
private _isEvent(eventCategories: string[], eventName: string, expectedCategories: string[], private _isEvent(eventCategories: string[], eventName: string, expectedCategories: string[],
expectedName: string = null): boolean { expectedName: string = null): boolean {