Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fun with single and double quotes within strings
#1
I have come to a bit of an impasse in my efforts to support backdoor queries and strings or more specifically lists of strings. The problem I have run into is how to be able to return a list of strings that may contain single and double quotes within the strings themselves and parse them correctly using the StringTokenizer. In all cases I'm using the ParseCmdLine because that is the only method that comes close to handling it correctly.

One method is to wrap each entry in quotes and separate them by spaces. So lets say we have a list with 2 entries whos raw values are

Quote:Security firm spots Chrome 'SaveAs' flaw
Panasonic 65PY700 65" 1080p Plasma HDTV
Which in a list gives
Quote:"Security firm spots Chrome 'SaveAs' flaw" "Panasonic 65PY700 65" 1080p Plasma HDTV"
and when parsed will give the 5 tokens below because of the single " in the second list member
Quote:Security firm spots Chrome 'SaveAs' flaw
Panasonic 65PY700 65
1080p
Plasma
HDTV"

Using single quotes for the wraps will give you the 3 shown below for similar reasons.
Quote:Security firm spots Chrome 'SaveAs
flaw'
Panasonic 65PY700 65" 1080p Plasma HDTV

For now to get things displaying properly in a web page I am replacing any " with a single-double-single ('"') in the driver and then re-replacing with " after parsing in the cmlbin macro, but this is definitely a hack.I want to keep this as simple as possible without having to resort to replacing characters to make the parse work as desired.

On a related note what are the proposed "static" list browsers going to take as a source. I'm guessing a comma separated quoted list. If so I'm not sure how to make a return value of a stringlist via a backdoor method compatible for both a source for a list browser or for use in something like a cmlbin macro.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#2
There is a dedicated parser for those types of formatted string lists. It's on the tokenizer class:
Code:
ParseQuotedCommaList
(
   [In] String ToParse
   , [Out] VectorOf[String] ToFill
   , [Out] Card4 ErrorIndex
) Returns Boolean;

It correctly handles single quotes inside of the strings. But you will have to do a replace character pass to replace double quotes in the strings with single quotes.

I could allow escaped quotes, \", as another means to deal with it. But, no matter what, if you are getting random text from an external source, any formatted scheme will require that you do some sort of replacement or escapement mechanisms. And there has to be a formatted way of doing it, so that it can be done from actions.
Dean Roddey
Explorans limites defectum
Reply
#3
Ahh...another easter egg. The ParseCmdLine already handles single quotes just fine when wrapping everything in double quotes though. Looking at it a little more I think the best option may be replacing quotes with a token and then replace the tokens at the client. This way it could be handled in actions easily as well.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#4
ParseCmdLine though doesn't handle the comma separator. I could provide you with a method to create such a list by just handing it successive lines, which it would then go through and escape the internal double quotes for you.
Dean Roddey
Explorans limites defectum
Reply
#5
True. How does the ParseQuotedCommaList handle internal commas? And in fact isn't the comma separated list going to be required to support the new "static" list browsers.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#6
It will ignore anything between the quotes, so it doesn't matter what's inside the quotes other than more quotes. And yeh, it would be the form that you'd pass a list of values to the static browsers, so there would probably need to be some commands on the variables target to support building up those types of lists easily.
Dean Roddey
Explorans limites defectum
Reply
#7
On a related note at one time you talked about having the ReplaceToken method of the String class return a value for whether it found a token to replace or not so you could loop through a string replacing all the tokens. I was thinking it was going to be a boolean, but it appears it is returning an undocumented Enumeration of FindRes from the BaseInfo class. It returns Found when it finds one and NoMore if not.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#8
Ooops, I'll get that documented. The values are Found, NotFound, NoMore, so that it can be used in a number of places where that general type of indicator would be needed. There's also a FindTokenList method now, to find a list of all of the tokens that exist in a string, so that you can only try to replace those that exist (if you have a large potential list of things that might need to be replaced.)
Dean Roddey
Explorans limites defectum
Reply
#9
So the meaning of those values should be:

Found - That token was found
NotFound - That token was not found, but other tokens were seen
NoMore - That token was not found and no more tokens were seen (so that you can stop trying to replace anymore.)
Dean Roddey
Explorans limites defectum
Reply
#10
Sounds good. And as long as we are on the subject of strings does the return value for GetConfigStr indicate whether a ConfigStr has been set by SetConfigStr? Also for the ParseQuotedCommaList is the ErrorIndex the byte where an error occured and what will cause this?
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CML Macros - Replacing Quotes gReatAutomation 2 260 02-13-2021, 11:59 AM
Last Post: Dean Roddey
  Single button, Multiple images & commands? M4T VW 6 3,330 10-04-2014, 01:47 PM
Last Post: M4T VW
  USBUIRT double triggers indygreg 4 1,769 08-31-2010, 01:14 PM
Last Post: Dean Roddey
  How to create a double indirection? pjgregory 1 1,275 05-19-2010, 08:52 AM
Last Post: Dean Roddey
  Viewing really long strings in fields beelzerob 3 1,709 02-09-2010, 08:09 PM
Last Post: Dean Roddey
  Double case statement in cml RobWalker 1 1,378 12-28-2009, 08:21 PM
Last Post: Dean Roddey
  Append double quote to string in CML VidaBox LLC 1 1,423 11-03-2009, 03:55 PM
Last Post: Dean Roddey
  Single thermostat template for multiple t-stats with ELK robolo 12 4,140 03-24-2009, 10:05 AM
Last Post: Dean Roddey
  Stock Quotes anogee 7 3,410 01-08-2009, 08:06 PM
Last Post: Sendero
  Question about driver configuraton strings jrlewis 3 1,618 10-06-2008, 09:18 PM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)