[Javascript] Q on parsing

Walter Torres walter at braverock.com
Tue Jul 23 20:18:30 CDT 2002


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




More information about the Javascript mailing list