From 5a0323ac288dd30f2bc17109bbb3ef32e8a76cf1 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Fri, 8 Feb 2013 18:47:18 +0100 Subject: [PATCH] Replaced startsWidth and endsWidth with regexp. See #3003. --- examples/js/loaders/MTLLoader.js | 2 +- examples/js/loaders/OBJLoader.js | 10 +++++----- examples/js/loaders/OBJMTLLoader.js | 10 +++++----- src/Three.js | 21 --------------------- src/loaders/Loader.js | 2 +- src/loaders/SceneLoader.js | 4 ++-- 6 files changed, 14 insertions(+), 35 deletions(-) diff --git a/examples/js/loaders/MTLLoader.js b/examples/js/loaders/MTLLoader.js index 97d7f13907..53027a48df 100644 --- a/examples/js/loaders/MTLLoader.js +++ b/examples/js/loaders/MTLLoader.js @@ -401,7 +401,7 @@ THREE.MTLLoader.MaterialCreator.prototype = { THREE.MTLLoader.loadTexture = function ( url, mapping, onLoad, onError ) { - var isCompressed = url.toLowerCase().endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( url ); if ( isCompressed ) { diff --git a/examples/js/loaders/OBJLoader.js b/examples/js/loaders/OBJLoader.js index 536a1e5b25..a28f6ec51e 100644 --- a/examples/js/loaders/OBJLoader.js +++ b/examples/js/loaders/OBJLoader.js @@ -382,7 +382,7 @@ THREE.OBJLoader.prototype = { } - } else if ( line.startsWith( "o " ) ) { + } else if ( /^o /.test( line ) ) { // object @@ -390,23 +390,23 @@ THREE.OBJLoader.prototype = { object.name = line.substring( 2 ).trim(); group.add( object ); - } else if ( line.startsWith( "g " ) ) { + } else if ( /^g /.test( line ) ) { // group meshN( line.substring( 2 ).trim(), undefined ); - } else if ( line.startsWith( "usemtl " ) ) { + } else if ( /^usemtl /.test( line ) ) { // material meshN( undefined, line.substring( 7 ).trim() ); - } else if ( line.startsWith( "mtllib ") ) { + } else if ( /^mtllib /.test( line ) ) { // mtl file - } else if ( line.startsWith( "s ") ) { + } else if ( /^s /.test( line ) ) { // smooth shading diff --git a/examples/js/loaders/OBJMTLLoader.js b/examples/js/loaders/OBJMTLLoader.js index 1d6bffdb10..f30864dd30 100644 --- a/examples/js/loaders/OBJMTLLoader.js +++ b/examples/js/loaders/OBJMTLLoader.js @@ -518,7 +518,7 @@ THREE.OBJMTLLoader.prototype = { } - } else if ( line.startsWith( "o " ) ) { + } else if ( /^o /.test( line ) ) { // object @@ -526,19 +526,19 @@ THREE.OBJMTLLoader.prototype = { object.name = line.substring( 2 ).trim(); group.add( object ); - } else if ( line.startsWith( "g " ) ) { + } else if ( /^g /.test( line ) ) { // group meshN( line.substring( 2 ).trim(), undefined ); - } else if ( line.startsWith( "usemtl " ) ) { + } else if ( /^usemtl /.test( line ) ) { // material meshN( undefined, line.substring( 7 ).trim() ); - } else if ( line.startsWith( "mtllib ") ) { + } else if ( /^mtllib /.test( line ) ) { // mtl file @@ -550,7 +550,7 @@ THREE.OBJMTLLoader.prototype = { } - } else if ( line.startsWith( "s ") ) { + } else if ( /^s /.test( line ) ) { // Smooth shading diff --git a/src/Three.js b/src/Three.js index cf7a515e8f..6714339fdd 100644 --- a/src/Three.js +++ b/src/Three.js @@ -18,27 +18,6 @@ self.console = self.console || { self.Int32Array = self.Int32Array || Array; self.Float32Array = self.Float32Array || Array; -// Shims for "startsWith", "endsWith", and "trim" for browsers where this is not yet implemented -// not sure we should have this, or at least not have it here - -// http://stackoverflow.com/questions/646628/javascript-startswith -// http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript -// http://wiki.ecmascript.org/doku.php?id=harmony%3astring_extras - -String.prototype.startsWith = String.prototype.startsWith || function ( str ) { - - return this.slice( 0, str.length ) === str; - -}; - -String.prototype.endsWith = String.prototype.endsWith || function ( str ) { - - var t = String( str ); - var index = this.lastIndexOf( t ); - return ( -1 < index && index ) === (this.length - t.length); - -}; - String.prototype.trim = String.prototype.trim || function () { return this.replace( /^\s+|\s+$/g, '' ); diff --git a/src/loaders/Loader.js b/src/loaders/Loader.js index 5e7334127c..dd22b0715a 100644 --- a/src/loaders/Loader.js +++ b/src/loaders/Loader.js @@ -145,7 +145,7 @@ THREE.Loader.prototype = { function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) { - var isCompressed = sourceFile.toLowerCase().endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( sourceFile ); var fullPath = texturePath + "/" + sourceFile; if ( isCompressed ) { diff --git a/src/loaders/SceneLoader.js b/src/loaders/SceneLoader.js index a6243f800f..3179aee550 100644 --- a/src/loaders/SceneLoader.js +++ b/src/loaders/SceneLoader.js @@ -903,7 +903,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) { } - var isCompressed = url_array[ 0 ].endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( url_array[ 0 ] ); if ( isCompressed ) { @@ -917,7 +917,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) { } else { - var isCompressed = textureJSON.url.toLowerCase().endsWith( ".dds" ); + var isCompressed = /\.dds$/i.test( textureJSON.url ); var fullUrl = get_url( textureJSON.url, data.urlBaseType ); var textureCallback = generateTextureCallback( 1 ); -- GitLab