PDA

View Full Version : escaped string problem



davidovv
31st January 2013, 00:32
I have different types of kiosk printers for different purposes but i want to have a single printer class
the idea is tho store string like this in database
"\x1B\x40\x1B\x21\x28\x1B\x61\x31\nText line with %1 parameters\nand %2 something"
the first few characters initialize printer and set options (for different printers different initialization)

1. I need to load this string from database
2. convert escaped sequences ( "\x1B" becomes single character 27)
3. process parameter text (%1 is replaced with string)
4. write the result to serial port and to get ticket

Is this proper way or someone knows a better solution?
Anway i am stuck at task no. 2, how to process part of string that represents escape sequence
i have no idea how to do this task
I am using qt5 with c++11 config so new features of language are welcome
some google results pointed to toRaw and fromRaw functions but
to be honest i dont know how to present this problem with "multi level escape usage"

ChrisW67
31st January 2013, 02:41
If you need the strings to be user readable then that is as good an encoding as any other, although you may find URL percent encoding easier to work with because Qt provides QByteArray::fromPercentEncoding() and its inverse. If the binary data does not need to be user readable then you can simply store it unencoded in a blob column or, if your database cannot do a blob, then QByteArray::toBase64() may be useful.

davidovv
1st February 2013, 00:05
wanted string to simplify modification, advanced user needs only database connection
so both blob and toBase64() are out
i searched for function that loads string like compiler does but
QByteArray::fromPercentEncoding() is all I need
thanks again