Menu

#11 Revised calcLength() function

open
nobody
None
5
2006-02-16
2006-02-16
Anonymous
No

I found it necessary to change the 3 ord value
comparisions in the if conditional in the calcLength()
function from:

1024 to 2048
32768 to 65536
2097152 to 1114112

So the new revised calcLength() function is as follows:

// --- Revised function [begin] -----------------------

private function calcLength(struct:String)
{
var c;
var result=0;
var l = struct.length;
for (var i=0; i < l; i++)
{
c = ord(struct.charAt(i));
if(c<128) {
result += 1;
} else if (c<2048) {
result += 2;
} else if (c<65536) {
result += 3;
} else if (c<1114112) {
result += 4;
}
}
return result;
}

// --- Revised function [end] -------------------------

Discussion


Log in to post a comment.