Browse Source

Replaced startsWidth and endsWidth with regexp. See #3003.

Mr.doob 12 years ago
parent
commit
5a0323ac28

+ 1 - 1
examples/js/loaders/MTLLoader.js

@@ -401,7 +401,7 @@ THREE.MTLLoader.MaterialCreator.prototype = {
 
 
 THREE.MTLLoader.loadTexture = function ( url, mapping, onLoad, onError ) {
 THREE.MTLLoader.loadTexture = function ( url, mapping, onLoad, onError ) {
 
 
-	var isCompressed = url.toLowerCase().endsWith( ".dds" );
+	var isCompressed = /\.dds$/i.test( url );
 
 
 	if ( isCompressed ) {
 	if ( isCompressed ) {
 
 

+ 5 - 5
examples/js/loaders/OBJLoader.js

@@ -382,7 +382,7 @@ THREE.OBJLoader.prototype = {
 
 
 				}
 				}
 
 
-			} else if ( line.startsWith( "o " ) ) {
+			} else if ( /^o /.test( line ) ) {
 
 
 				// object
 				// object
 
 
@@ -390,23 +390,23 @@ THREE.OBJLoader.prototype = {
 				object.name = line.substring( 2 ).trim();
 				object.name = line.substring( 2 ).trim();
 				group.add( object );
 				group.add( object );
 
 
-			} else if ( line.startsWith( "g " ) ) {
+			} else if ( /^g /.test( line ) ) {
 
 
 				// group
 				// group
 
 
 				meshN( line.substring( 2 ).trim(), undefined );
 				meshN( line.substring( 2 ).trim(), undefined );
 
 
-			} else if ( line.startsWith( "usemtl " ) ) {
+			} else if ( /^usemtl /.test( line ) ) {
 
 
 				// material
 				// material
 
 
 				meshN( undefined, line.substring( 7 ).trim() );
 				meshN( undefined, line.substring( 7 ).trim() );
 
 
-			} else if ( line.startsWith( "mtllib ") ) {
+			} else if ( /^mtllib /.test( line ) ) {
 
 
 				// mtl file
 				// mtl file
 
 
-			} else if ( line.startsWith( "s ") ) {
+			} else if ( /^s /.test( line ) ) {
 
 
 				// smooth shading
 				// smooth shading
 
 

+ 5 - 5
examples/js/loaders/OBJMTLLoader.js

@@ -518,7 +518,7 @@ THREE.OBJMTLLoader.prototype = {
 
 
 				}
 				}
 
 
-			} else if ( line.startsWith( "o " ) ) {
+			} else if ( /^o /.test( line ) ) {
 
 
 				// object
 				// object
 
 
@@ -526,19 +526,19 @@ THREE.OBJMTLLoader.prototype = {
 				object.name = line.substring( 2 ).trim();
 				object.name = line.substring( 2 ).trim();
 				group.add( object );
 				group.add( object );
 
 
-			} else if ( line.startsWith( "g " ) ) {
+			} else if ( /^g /.test( line ) ) {
 
 
 				// group
 				// group
 
 
 				meshN( line.substring( 2 ).trim(), undefined );
 				meshN( line.substring( 2 ).trim(), undefined );
 
 
-			} else if ( line.startsWith( "usemtl " ) ) {
+			} else if ( /^usemtl /.test( line ) ) {
 
 
 				// material
 				// material
 
 
 				meshN( undefined, line.substring( 7 ).trim() );
 				meshN( undefined, line.substring( 7 ).trim() );
 
 
-			} else if ( line.startsWith( "mtllib ") ) {
+			} else if ( /^mtllib /.test( line ) ) {
 
 
 				// mtl file
 				// mtl file
 
 
@@ -550,7 +550,7 @@ THREE.OBJMTLLoader.prototype = {
 
 
 				}
 				}
 
 
-			} else if ( line.startsWith( "s ") ) {
+			} else if ( /^s /.test( line ) ) {
 
 
 				// Smooth shading
 				// Smooth shading
 
 

+ 0 - 21
src/Three.js

@@ -18,27 +18,6 @@ self.console = self.console || {
 self.Int32Array = self.Int32Array || Array;
 self.Int32Array = self.Int32Array || Array;
 self.Float32Array = self.Float32Array || 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 () {
 String.prototype.trim = String.prototype.trim || function () {
 
 
 	return this.replace( /^\s+|\s+$/g, '' );
 	return this.replace( /^\s+|\s+$/g, '' );

+ 1 - 1
src/loaders/Loader.js

@@ -145,7 +145,7 @@ THREE.Loader.prototype = {
 
 
 		function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
 		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;
 			var fullPath = texturePath + "/" + sourceFile;
 
 
 			if ( isCompressed ) {
 			if ( isCompressed ) {

+ 2 - 2
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 ) {
 			if ( isCompressed ) {
 
 
@@ -917,7 +917,7 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 		} else {
 		} else {
 
 
-			var isCompressed = textureJSON.url.toLowerCase().endsWith( ".dds" );
+			var isCompressed = /\.dds$/i.test( textureJSON.url );
 			var fullUrl = get_url( textureJSON.url, data.urlBaseType );
 			var fullUrl = get_url( textureJSON.url, data.urlBaseType );
 			var textureCallback = generateTextureCallback( 1 );
 			var textureCallback = generateTextureCallback( 1 );