/*
* All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,
* the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:
*
* '\\' represents a single literal '\' in the name
* '\.' represents a single literal '.' in the name
* '\ddd', where ddd is a three-digit decimal value from 000 to 255,
* represents a single literal byte with that value.
* A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
*/
state = startChar;
for (int i=0; i<tmp.count(); i++) {
switch (state) {
case startChar:
if ((ch == '\\')) {
signPos = i;
nrStr.clear();
state = digit1;
}
break;
case digit1:
if ((ch == '\\') || (ch == '.')) {
tmp.remove(i-1, 1);
i--; //String is shortened by one, so rescan the last sign
state = startChar;
}
else if ((ch >= '0') && (ch <= '2')) {
nrStr.append(ch);
state = digit2;
}
break;
case digit2:
if ((ch >= '0') && (ch <= '9')) {
nrStr.append(ch);
state = digit3;
}
break;
case digit3:
if ((ch >= '0') && (ch <= '9')) {
nrStr.append(ch);
int nr = nrStr.toUInt();
tmp.
replace(signPos,
4,
QChar(nr
));
i=i-3; //String is shortened by 3, so rescan the last 3 signs
state = startChar;
}
break;
default:
state = startChar;
break;
}
}
/*
* All strings used in the DNS-SD APIs are UTF-8 strings. Apart from the exceptions noted below,
* the APIs expect the strings to be properly escaped, using the conventional DNS escaping rules:
*
* '\\' represents a single literal '\' in the name
* '\.' represents a single literal '.' in the name
* '\ddd', where ddd is a three-digit decimal value from 000 to 255,
* represents a single literal byte with that value.
* A bare unescaped '.' is a label separator, marking a boundary between domain and subdomain.
*/
state = startChar;
for (int i=0; i<tmp.count(); i++) {
QChar ch = tmp.at(i);
switch (state) {
case startChar:
if ((ch == '\\')) {
signPos = i;
nrStr.clear();
state = digit1;
}
break;
case digit1:
if ((ch == '\\') || (ch == '.')) {
tmp.remove(i-1, 1);
i--; //String is shortened by one, so rescan the last sign
state = startChar;
}
else if ((ch >= '0') && (ch <= '2')) {
nrStr.append(ch);
state = digit2;
}
break;
case digit2:
if ((ch >= '0') && (ch <= '9')) {
nrStr.append(ch);
state = digit3;
}
break;
case digit3:
if ((ch >= '0') && (ch <= '9')) {
nrStr.append(ch);
int nr = nrStr.toUInt();
tmp.replace(signPos, 4, QChar(nr));
i=i-3; //String is shortened by 3, so rescan the last 3 signs
state = startChar;
}
break;
default:
state = startChar;
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks