Changes

Jump to: navigation, search

User:Dhhodgin

879 bytes added, 23:20, 5 February 2010
Code Blocks
== Code Blocks ==
Here is a list of code blocks I have written for the processing.js project<br />
=== trim() ===
Trim leading and trailing whitespace from strings as well as tab characters, newlines, and nbsp characters<br/>
Commit [http://github.com/dhodgin/processing-js/commit/e7f258eec8f566a0da39c23f964280637e8e2a4b trim() commit]<br />
Test available [http://matrix.senecac.on.ca/~dhhodgin/dps911/examples/seneca/trim/trimtest.htm here]<br />
p.trim = function( str ) {
var newstr;
if (typeof str === "object") {
// if str is an array recursivly loop through each element
// and drill down into multiple arrays trimming whitespace
newstr = new Array(0);
for (var i = 0; i < str.length; i++) {
newstr[i] = p.trim(str[i]);
}
} else {
// if str is not an array then remove all whitespace, tabs, and returns
newstr = str.replace(/^\s*/,'').replace(/\s*$/,'').replace(/\r*$/,'');
}
return newstr;
};
=== decimalToHex() ===
A helper function used with hex to convert a number passed in to hex and add any specified padding
=== hex() ===
hex(x, y) function for processing. x is a byte, char, int, or color. y is the length of the string to return.<br />
commit Commit [http://github.com/dhodgin/processing-js/commit/d51adccc9acfeb4fa286366c98e06a33ad296524 hex() commit]<br />test Test available [http://matrix.senecac.on.ca/~dhhodgin/dps911/hextest.htm here]<br />
<br />
// note: since we cannot keep track of byte, char, and int types by default the returned string is 8 chars long
1
edit

Navigation menu