1 /** 2 * potree.js 3 * http://potree.org 4 * 5 * Copyright 2012, Markus Sch�tz 6 * Licensed under the GPL Version 2 or later. 7 * - http://potree.org/wp/?page_id=7 8 * - http://www.gnu.org/licenses/gpl-3.0.html 9 * 10 */ 11 12 /** 13 * extensions for strings 14 * 15 * @author Markus Sch�tz 16 */ 17 18 String.prototype.repeat = function(count) { 19 var msg = ""; 20 for ( var i = 0; i < count; i++) { 21 msg += this; 22 } 23 24 return msg; 25 }; 26 27 /** 28 * fills the string with character to the left, until it reaches the desired length. <br> 29 * if string.length is already >= length, the unmodified string will be returned. 30 * 31 * @param length 32 * @param character 33 * @returns {String} 34 */ 35 String.prototype.leftPad = function(length, character){ 36 if(character == null){ 37 character = ' '; 38 } 39 40 var padded = ""; 41 var diff = length - this.length; 42 if(diff > 0){ 43 padded = character.repeat(diff) + this; 44 } 45 46 return padded; 47 }; 48 49 /** 50 * fills the string with character to the right, until it reaches the desired length. <br> 51 * if string.length is already >= length, the unmodified string will be returned. 52 * 53 * @param length 54 * @param character 55 * @returns {String} 56 */ 57 String.prototype.rightPad = function(length, character){ 58 if(character == null){ 59 character = ' '; 60 } 61 62 var padded = ""; 63 var diff = length - this.length; 64 if(diff > 0){ 65 padded = this + character.repeat(diff); 66 } 67 68 return padded; 69 }; 70 71 /** 72 * turns a buffer object into a string. 73 * 74 * @param buffer 75 * @returns {String} 76 */ 77 String.fromBuffer = function(buffer){ 78 var string = ""; 79 80 var ibuff = new Uint8Array(buffer); 81 for(var i = 0; i < ibuff.length; i++){ 82 string += String.fromCharCode(ibuff[i]); 83 } 84 85 return string; 86 }; 87 88 Object.defineProperty(String.prototype, 'first', { 89 get: function(){ 90 return "lala"; 91 } 92 });