[Javascript] Q on parsing

TomMallard mallard at serv.net
Tue Jul 23 22:34:33 CDT 2002


...

	var nextChar = '';
      curChar = strFormat.charAt(i);
	if (i < intFormatLen){
      	nextChar = strFormat.charAt(i+1);
	}else{
		nextChar = '';
	}
     	while (( strFormat.charAt(i) == curChar ) && ( i < intFormatLen ) && )
		if (curChar == '\'' && nextChar == '\''){
			i = i+2;	//increment the counter past the 2 single quotes
			token += '\'';	//add the quote to the output
		}else{
         		token += strFormat.charAt(i);
		}
		i++;
	}
...


tom mallard
seattle

-----Original Message-----
From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
Behalf Of Walter Torres
Sent: Tuesday, July 23, 2002 6:18 PM
To: Walter Torres
Cc: javascript at yahoogroups.com; javascript at LaTech.edu
Subject: [Javascript] Q on parsing


I am 99% complete on a date format parser.

(will post when this question is answerd!)

The last item is how to parse out a substring bracketed by single quotes.

i.e.:

I have this var...

    var format = "EEEE, MMMM dd, yyyy ''G'' 'at' hh:mm:ss a z" ;

I can walk down this string and pull out "tokens" (same character of 1 or
more in length: ex: EEEE, hh, z )

I do it like this...

   while ( i < intFormatLen )
   {
      var token = "";

      curChar = strFormat.charAt(i);

      while (( strFormat.charAt(i) == curChar ) && ( i < intFormatLen ))
         token += strFormat.charAt(i++);

      result += formatOptions ( token );
   }


Now, a double single quote (2 in a row) needs to be grapped and passed on
as a single token. but not 3 in a row, the third should be part of the
next token. It needs to grab 2 adjacent at a time.

If it finds one single quote, it needs to grab all characters until it
sees and other single quote. Yes, it needs to be able to handle an
embedded pair of single quotes.

So, if I have this...

     EEEE 'is walter''s birthday'

This should give me 3 tokens
  1) EEEE
  2) a SPACE
  3) is walter's birthday

I can grab all but #3! :(

I have been banging my head for 3 days on this one, I just can't see it.

Help?

Walter

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list