forked from processing-js/processing-js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
processing-js#19, rewrote trim(), added tests in examples/seneca/trim
- Loading branch information
Daniel Hodgin
committed
Feb 6, 2010
1 parent
051a398
commit e7f258e
Showing
4 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Trim example | ||
size(500,220, P3D); | ||
background(20); | ||
stroke(128, 128, 128); | ||
fill(64); | ||
rect(1, 1, width-3, height-3); | ||
|
||
String s1 = "normal string"; | ||
String s2 = " extra leading spaces"; | ||
String s3 = "extra trailing spaces "; | ||
String s4 = " both leading and trailing "; | ||
String[] a = { " inconsistent ", " spacing", "ok", " tab at the end "}; | ||
String[] a2 = trim(a); | ||
|
||
PFont font; | ||
font = loadFont("Arial"); | ||
textFont(font, 14); | ||
fill(32, 255, 0); | ||
text("Strings", 5, 20); | ||
text("String Arrays", 5, 120); | ||
fill(255, 255, 255); | ||
text("s1: |" + s1 + "|", 15, 40); | ||
text("after: |" + trim(s1) + "|", 240, 40); | ||
text("s2: |" + s2 + "|", 15, 60); | ||
text("after: |" + trim(s2) + "|", 240, 60); | ||
text("s3: |" + s3 + "|", 15, 80); | ||
text("after: |" + trim(s3) + "|", 240, 80); | ||
text("s4: |" + s4 + "|", 15, 100); | ||
text("after: |" + trim(s4) + "|", 240, 100); | ||
for(int i=0; i<a2.length; i++){ | ||
text("a[" + i + "]: |" + a[i] + "|", 15, 140+(i*20)); | ||
text("after: |" + a2[i] + "|", 240, 140+(i*20)); | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head runat="server"> | ||
<title>Processing.js test of trim()</title> | ||
<script type="text/javascript" src="../../../processing.js"></script> | ||
<script type="text/javascript" src="../../../scripts/shCore.js"></script> | ||
<script type="text/javascript" src="../../../scripts/shBrushProcessing.js"></script> | ||
<link type="text/css" rel="stylesheet" href="../../../styles/shCore.css" /> | ||
<link type="text/css" rel="stylesheet" href="../../../styles/shThemeDefault.css" /> | ||
<script type="text/javascript"> | ||
SyntaxHighlighter.config.clipboardSwf = '../../../scripts/clipboard.swf'; | ||
SyntaxHighlighter.all(); | ||
</script> | ||
|
||
<style type="text/css"> | ||
html, body | ||
{ | ||
background: #EEE; | ||
font-family: Arial; | ||
font-size: 13px; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
h1 | ||
{ | ||
background: #385C85; | ||
color: #FFF; | ||
padding: 10px; | ||
padding-left: 20px; | ||
margin-top: 0px; | ||
margin-bottom: 0px; | ||
} | ||
h1 a | ||
{ | ||
color: #FFF; | ||
} | ||
h2 | ||
{ | ||
padding-left: 20px; | ||
} | ||
p | ||
{ | ||
padding-left: 20px; | ||
line-height: 1.3em; | ||
} | ||
p a | ||
{ | ||
color: #385C85; | ||
} | ||
canvas | ||
{ | ||
margin: 10px 0; | ||
} | ||
pre | ||
{ | ||
margin-left: 20px; | ||
margin-right: 20px; | ||
padding: 5px; | ||
background: #FFF; | ||
border-top: 1px solid #333; | ||
border-bottom: 1px solid #333; | ||
} | ||
div.ref-col | ||
{ | ||
float: left; | ||
width: 32%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1> | ||
<!-- name of your function and test description --> | ||
trim() test</h1> | ||
<h2> | ||
This is a test of trim(string)</h2> | ||
<p> | ||
trim() removes whitespace characters from the beginning and end of a String. In addition to standard whitespace characters such as space, carriage return, and tab, this function also removes the Unicode "nbsp" character.</p> | ||
<!-- include your processing file below --> | ||
<canvas datasrc="trim.pjs" width="200" height="200" style="margin-left: 10px;"></canvas> | ||
<img src="trim.png" alt=""/> | ||
<br /> | ||
<b>Test written by <a href="http://dhodgin.wordpress.com/">Daniel Hodgin</a></b><br /> | ||
<h1> | ||
Source Code:</h1> | ||
<pre class="brush: processing;"> | ||
// Trim example | ||
size(500,220, P3D); | ||
background(20); | ||
stroke(128, 128, 128); | ||
fill(64); | ||
rect(1, 1, width-3, height-3); | ||
|
||
String s1 = "normal string"; | ||
String s2 = " extra leading spaces"; | ||
String s3 = "extra trailing spaces "; | ||
String s4 = " both leading and trailing "; | ||
String[] a = { " inconsistent ", " spacing", "ok" }; | ||
String[] a2 = trim(a); | ||
|
||
PFont font; | ||
font = loadFont("Arial"); | ||
textFont(font, 14); | ||
fill(32, 255, 0); | ||
text("Strings", 5, 20); | ||
text("String Arrays", 5, 120); | ||
fill(255, 255, 255); | ||
text("s1: " + s1, 15, 40); | ||
text("after: " + trim(s1), 240, 40); | ||
text("s2: " + s2, 15, 60); | ||
text("after: " + trim(s2), 240, 60); | ||
text("s3: " + s3, 15, 80); | ||
text("after: " + trim(s3), 240, 80); | ||
text("s4: " + s4, 15, 100); | ||
text("after: " + trim(s4), 240, 100); | ||
for(int i=0; i<a2.length; i++){ | ||
text("a[" + i + "]: " + a[i], 15, 140+(i*20)); | ||
text("after: " + a2[i], 240, 140+(i*20)); | ||
} | ||
</pre> | ||
<br /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters