[Javascript] Q on parsing
Walter Torres
walter at torres.ws
Wed Jul 24 00:33:55 CDT 2002
Thanks Tom, but...
What this does is...
- look for a pair of single quotes
- if it finds them
- add 2 to the counter
- insert a single quote in the token string
It does not handle...
(NOTE: square brackets are mine, not for output)
['walter''s birthday'] should return [walter's birthday]
Thanks, but the <formatOptions ( token )> function handles a token of a pair
of single quotes.
I just need to find a way (without using RegExp) to pull out ['walter''s
birthday'] from the input format string.
Thanks for the thought.
Walter
PS: My JS died on this line...
while (( strFormat.charAt(i) == curChar ) && ( i < intFormatLen ) && )
Can I ask why the extra '&&' at the end of the line?
> -----Original Message-----
> From: javascript-admin at LaTech.edu
> [mailto:javascript-admin at LaTech.edu]On
> Behalf Of TomMallard
> Sent: Tuesday, July 23, 2002 8:35 PM
> To: javascript at LaTech.edu
> Subject: RE: [Javascript] Q on parsing
>
>
> ...
>
> 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
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list