MediaTomb

function: abcbox

for description: see structured_import_script

function abcbox(stringtobox, boxtype, divchar)
{
	// get ascii value of first character 
	var intchar = stringtobox.toUpperCase().charCodeAt(0);
 
	// check for numbers
	if ( (intchar >= 48) && (intchar <= 57) )
	{
		return divchar + '0-9' + divchar;
	}
	// check for other characters
	if ( !((intchar >= 65) && (intchar <= 90)) )
	{
		return divchar + '^\&#\'' + divchar;
	}
	// all other characters are letters
 
	// definition of box types, adjust to your own needs
	// as a start: the number is the same as the number of boxes, evenly spaced ... more or less.
	switch (boxtype)
	{
	case 1:
		var boxwidth = new Array();
		boxwidth[0] = 26;                             // one large box of 26 letters
		break;
	case 2:
		var boxwidth = new Array(13,13);              // two boxes of 13 letters
		break;
	case 3:
		var boxwidth = new Array(8,9,9);              // and so on ...
		break;
	case 4:
		var boxwidth = new Array(7,6,7,6);
		break;
	case 5:
		var boxwidth = new Array(5,5,5,6,5);
		break;
	case 6:
		var boxwidth = new Array(4,5,4,4,5,4);
		break;
	case 7:
		var boxwidth = new Array(4,3,4,4,4,3,4);
		break;
	case 9:
		var boxwidth = new Array(5,5,5,4,1,6);        // When T is a large box...
		break;
	default:
		var boxwidth = new Array(5,5,5,6,5);
		break;
	}
 
	// check for a total of 26 characters for all boxes
	charttl = 0;
	for (cb=0;cb<boxwidth.length;cb++) { charttl = charttl + boxwidth[cb]; }
	if (charttl != 26) {
		print("Error in box-definition, length is " + charttl + ". Check the file common.js" );
		// maybe an exit call here to stop processing the media ??
		end;
	}
 
	// declaration of some variables
	boxnum=0;                         // boxnumber start
	sc=65;                            // first ascii character (corresponds to 'A')
	ec=sc + boxwidth[boxnum] - 1;     // last character of first box
 
	// loop that will define first and last character of the right box
	while (intchar>ec)
	{
		boxnum++;                         // next boxnumber
		sc = ec + 1;                      // next startchar
		ec = sc + boxwidth[boxnum] - 1;   // next endchar
	}
 
	// construction of output string
	output = divchar;
	for (i=sc;i<=ec;i++) {
		output = output + String.fromCharCode(i);
	}
	output = output + divchar;
	return output;
}
 
scripting/abcbox.txt ยท Last modified: 2008/11/02 21:25 by allart