PDA

View Full Version : [Tool/Web/Other] String checker [length, block size, breaks & tabs] - Is your string size correct?


Sinner
13/07/2012, 06:58 PM
This is a small web page I made with HTML & Javascript that can help you with the creation of strings by calculating it's length for you, aswel as the line breaks, tabs and it will tell you what the recommended string block size would be.

Feel free to give feedback!

DEMO: http://project-pawn.com/dump/stringchecker

<!--
String checker page by Sinner
feel free to modify but leave credits intact please
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>String Length Calculator</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
background-color: #F0F0F0;
background-image: -ms-radial-gradient(center, circle farthest-corner, #C0C0C0 0%, #F0F0F0 100%);
background-image: -moz-radial-gradient(center, circle farthest-corner, #C0C0C0 0%, #F0F0F0 100%);
background-image: -o-radial-gradient(center, circle farthest-corner, #C0C0C0 0%, #F0F0F0 100%);
background-image: -webkit-gradient(radial, center center, 0, center center, 510, color-stop(0, #C0C0C0), color-stop(1, #F0F0F0));
background-image: -webkit-radial-gradient(center, circle farthest-corner, #C0C0C0 0%, #F0F0F0 100%);
background-image: radial-gradient(center, circle farthest-corner, #C0C0C0 0%, #F0F0F0 100%);
}
table {
margin-left: auto;
margin-right: auto;
}
#primary {
height: 100%;
width: 50%;
}
#secondary {
width: 100%;
margin-left: auto;
margin-right: auto;
}
td {
vertical-align: middle;
text-align: center;
font-family: arial;
color: #888;
}
#primary td h1 {
font-size: 80px;
}
#primary td textarea {
width: 100%;
height: 200px;
}
#primary td div {
padding: 10px;
}
#primary td code {
float: right;
}
#num, #num2, #num3, #num4 {
color: #000;
font-size: 48px;
}
#num4 {
color: blue;
}
#warning {
color: red;
font-size: 24px;
}
#code {
background-color: #C0C0C0;
border: solid #D0D0D0 2px;
color: #000;
}
</style>
<script type="text/javascript">
function strlen() {
var len = countLength();
var breaks = countCharacter('\n');
var tabs = countCharacter('\t');
document.getElementById('num').innerHTML = len;
document.getElementById('num2').innerHTML = breaks;
document.getElementById('num3').innerHTML = tabs;
document.getElementById('num4').innerHTML = getRecommendedLen(len);
if(getRecommendedLen(len) > 2048) {
document.getElementById('warning').innerHTML = "Warning: huge strings ("+ len +") are always a bad idea!";
} else document.getElementById('warning').innerHTML = "";
if(breaks > 9) {
var height = ((breaks - 10) * 15.5);
document.getElementById('string').style.height = '0px';
document.getElementById('string').style.height = (3 * 15.5) + (breaks * 15.5) + 'px';
} else {
document.getElementById('string').style.height = '200px';
}
}
function countLength() {
return document.getElementById('string').value.length;
}
function countCharacter(character) {
var str = document.getElementById('string').value;
var breaks = 0;
for(var i=0; i<str.length; i++) {
if(str[i] == character) breaks++;
}
return breaks;
}
function getRecommendedLen(len) {
if(len == 0) return 1;
var rec = 1;
while(rec<=len) {
rec *= 2;
}
return rec;
}
</script>
</head>
<body onkeyup="Javascript:strlen();">
<table id="primary">
<tr>
<td>
<h1>STRING CHECKER V1.0</h1>
<table id="secondary">
<tr>
<td>
<div>Length of this string: <br /><p id="num">0</p></div>
</td>
<td>
<div>Recommended block size: <br /><p id="num4">1</p></div>
</td>
<td>
<div>Line breaks in this string: <br /><p id="num2">0</p></div>
</td>
<td>
<div>TABs in this string: <br /><p id="num3">0</p></div>
</td>
</tr>
</table>
<textarea id="string"></textarea>
<div id="code"><sub>&copy 2012 Sinner - feel free to modify/expand this page</sub></div>
<div id="warning"></div>
</td>
</tr>
</table>
</body>
</html>

kirollos
13/07/2012, 07:17 PM
Nice Script :) +rep

Sinner
24/09/2012, 07:01 PM
Link has been updated :).

Hanger
24/09/2012, 07:24 PM
More bigger demo link MORE !

Niko_boy
25/09/2012, 05:33 AM
great work, i am most of time unsure for cell size for string this might help me ;]

Sinner
23/11/2012, 04:29 PM
Link updated (again), it was redirecting to the old location.

Penki4a
24/11/2012, 12:36 PM
awesome tool!

Faisal_khan
08/12/2012, 07:13 AM
Bloddy awsome! +4reps to ya broda.

Gh05t_
08/12/2012, 01:40 PM
You've created a program to do what almost every well-written source editor does?

Sinner
09/12/2012, 12:50 PM
You've created a program to do what almost every well-written source editor does?

You've written a tutorial on loop structures when there are hundreds of more in-dept tutorials like that already on the internet? Ofcourse this already exists, but that doesn't mean I can't post this does it? I'm the first to post an online, javascript-based, tool like this on these forums.

Slice
09/12/2012, 12:54 PM
The block size is always 4 bytes for unpacked strings, no need to pad it. If anything, show the size packed strings will be (i.e. 4 is 4 bytes, 5 is 8 bytes).

TheChimpJr
09/12/2012, 05:31 PM
Great work, thanks for the share buddy!