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'],
files: [
'../../node_modules/es6-shim/es6-shim.js',
'../../node_modules/angular/angular.js',
'../../node_modules/angular-animate/angular-animate.js',
'../../node_modules/angular-mocks/angular-mocks.js',

View File

@ -247,18 +247,10 @@ var StringWrapper = {
return s.split(re);
},
substring: function(s, start, end) {
return s.substr(start, end);
},
replaceAll: function(s, from, replace) {
return s.replace(from, replace);
},
startsWith: function(s, start) {
return s.substr(0, start.length) === start;
},
replaceAllMapped: function(s, from, cb) {
return s.replace(from, function(matches) {
// 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 {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
import {Pipe} from 'angular2/src/core/metadata';
@ -32,6 +32,6 @@ export class LowerCasePipe implements PipeTransform {
if (!isString(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 {Injectable} from 'angular2/src/core/di';
import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
@ -31,6 +31,6 @@ export class UpperCasePipe implements PipeTransform {
if (!isString(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;
if (attr.name == TEMPLATE_ATTR) {
templateBindingsSource = attr.value;
} else if (StringWrapper.startsWith(attr.name, TEMPLATE_ATTR_PREFIX)) {
var key = StringWrapper.substring(attr.name, TEMPLATE_ATTR_PREFIX.length); // remove the star
} else if (attr.name.startsWith(TEMPLATE_ATTR_PREFIX)) {
var key = attr.name.substring(TEMPLATE_ATTR_PREFIX.length); // remove the star
templateBindingsSource = (attr.value.length == 0) ? key : key + ' ' + attr.value;
}
if (isPresent(templateBindingsSource)) {
@ -333,8 +333,7 @@ class TemplateParseVisitor implements HtmlAstVisitor {
}
private _normalizeAttributeName(attrName: string): string {
return StringWrapper.startsWith(attrName, 'data-') ? StringWrapper.substring(attrName, 5) :
attrName;
return attrName.startsWith('data-') ? attrName.substring(5) : attrName;
}
private _parseVariable(identifier: string, value: string, sourceInfo: any,

View File

@ -1,5 +1,5 @@
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 {XHRImpl} from 'angular2/src/compiler/xhr_impl';
@ -20,7 +20,7 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
var domPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
for (var i = 0; i < domPrefixes.length; i++) {
if (isPresent(this.getStyle(element, domPrefixes[i] + 'AnimationName'))) {
this._animationPrefix = '-' + StringWrapper.toLowerCase(domPrefixes[i]) + '-';
this._animationPrefix = '-' + domPrefixes[i].toLowerCase() + '-';
break;
}
}

View File

@ -80,18 +80,6 @@ class StringWrapper {
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]) {
start = _startOffset(s, start);
end = _endOffset(s, end);
@ -102,10 +90,6 @@ class StringWrapper {
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) {
return s.replaceAllMapped(from, cb);
}

View File

@ -176,16 +176,6 @@ export class StringWrapper {
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 {
return s.replace(from, function(...matches) {
// 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 class EventConfig {
@ -9,8 +8,8 @@ export class EventConfig {
var separatorIdx = eventConfig.indexOf(EVENT_TARGET_SEPARATOR);
if (separatorIdx > -1) {
// long format: 'fieldName: eventName'
fieldName = StringWrapper.substring(eventConfig, 0, separatorIdx).trim();
eventName = StringWrapper.substring(eventConfig, separatorIdx + 1).trim();
fieldName = eventConfig.substring(0, separatorIdx).trim();
eventName = eventConfig.substring(separatorIdx + 1).trim();
isLongForm = true;
}
return new EventConfig(fieldName, eventName, isLongForm);

View File

@ -1,11 +1,4 @@
import {
CONST,
Type,
stringify,
isPresent,
StringWrapper,
isString
} from 'angular2/src/core/facade/lang';
import {CONST, Type, stringify, isPresent, isString} from 'angular2/src/core/facade/lang';
import {resolveForwardRef} from 'angular2/src/core/di';
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.
* 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)})`; }
}

View File

@ -46,8 +46,7 @@ export class JSONPConnection_ extends JSONPConnection {
if (url.indexOf('=JSONP_CALLBACK&') > -1) {
url = StringWrapper.replace(url, '=JSONP_CALLBACK&', `=${callback}&`);
} else if (url.lastIndexOf('=JSONP_CALLBACK') === url.length - '=JSONP_CALLBACK'.length) {
url =
StringWrapper.substring(url, 0, url.length - '=JSONP_CALLBACK'.length) + `=${callback}`;
url = url.substring(0, url.length - '=JSONP_CALLBACK'.length) + `=${callback}`;
}
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 {
Map,
MapWrapper,
@ -9,9 +9,9 @@ import {
function paramParser(rawParams: string = ''): Map<string, string[]> {
var map = new Map<string, string[]>();
if (rawParams.length > 0) {
var params: string[] = StringWrapper.split(rawParams, new RegExp('&'));
var params: string[] = rawParams.split('&');
params.forEach((param: string) => {
var split: string[] = StringWrapper.split(param, new RegExp('='));
var split: string[] = param.split('=');
var key = split[0];
var val = split[1];
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} {
// normalize route as not starting with a "/". Recognition will
// also normalize.
if (StringWrapper.startsWith(route, "/")) {
route = StringWrapper.substring(route, 1);
if (route.startsWith("/")) {
route = route.substring(1);
}
var segments = splitBySlash(route);

View File

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

View File

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

View File

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

View File

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

View File

@ -42,24 +42,7 @@ export function main() {
});
describe('String', () => {
var upper, lower, 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);
});
var s;
describe('slice', () => {
beforeEach(() => { s = "abcdefghij"; });

View File

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