[Javascript] Q on parsing
Walter Torres
walter at torres.ws
Wed Jul 24 01:17:09 CDT 2002
Toms last message got me thinking, and this is what I came up with. (see
below)
It works, but it is ugly as sin.
Anyone fell like 'improving' it?
Walter
========================
// Loop through the format string
while ( i < intFormatLen )
{
// clear token
token = "";
// Retrieve individual character
curChar = strFormat.charAt(i);
// Build the format tokens
while (( strFormat.charAt(i) == curChar ) && ( i < intFormatLen ))
{
// Add current character to token string
token += strFormat.charAt(i);
// Increment to retrieve next char
i++;
// See if we have a single qoute with its mate next to it
if ( ( token == "'" ) && ( strFormat.charAt(i) != "'" ) )
{
// clear token
token = "";
// Loop through format string until we see another single quote
while (( strFormat.charAt(i) != "'" ) && ( i < intFormatLen ))
{
// Pull out character
cChr = strFormat.charAt(i);
// Add it to to token string if it is not a single quote
token += ( cChr != "'" ) ? cChr : '';
// Increment to retrieve next char
i++;
}
// Increment to retrieve next char
i++;
}
}
// Look at the individual token, one or more characters in length
// and pull corosponding value from format collection,
// otherwise just pass the token through
result += formatOptions ( token );
}
return result;
Thanks
More information about the Javascript
mailing list