/** All characters above 127 (7F hex) or below 33 (21 hex) are escaped. This includes the space character, which is escaped as %20. Also, the plus sign (+) needs to be interpreted as a space character. */ void CFormString::urlEncode( bool encodeSpaces ) { int i; CFormString temp; char c; for( i = 0; i < this->length(); ++i ) { c = this->at( i ).toLatin1(); // convert the QChar to a char (which is an int) if( c >= 0x00 && c <= 0x1F ) { temp.append( hexFromInt( c ) ); } else if ( c == 0x20 && encodeSpaces ) { // space temp.append( hexFromInt( c ) ); } else if ( c >= 0x21 && c <= 0x29 ) { // !"#$%&'() temp.append( hexFromInt( c ) ); } // * is OK else if ( c == 0x2B || c == 0x2C ) { //+, temp.append( hexFromInt( c ) ); } // -. are OK else if ( c == 0x2F ) { // / temp.append( hexFromInt( c ) ); } // 0123456789 are OK else if ( c >=0x3A && c <=0x40 ) { // :;<=>?@ temp.append( hexFromInt( c ) ); } // ABCDEFGHIJKLMNOPQRSTUVWXYZ are OK else if ( c >= 0x5B && c <=0x5E ) { // [\]^ temp.append( hexFromInt( c ) ); } // _ is OK else if ( c == 0x60 ) { // ` temp.append( hexFromInt( c ) ); } // abcdefghijklmnopqrstuvwxyz are OK else if ( c >= 0x7B ) { temp.append( hexFromInt( c ) ); } else { // This is a safe, unencoded, OK character temp.append( c ); } } if( encodeSpaces ) { temp.swapChar( ' ', '+' ); } isEncoded_p = true; *this = temp; }
QString hexColor(const QColor& color) { QString result = QLatin1String(""); result += hexFromInt(color.red() / 16); result += hexFromInt(color.red() % 16); result += hexFromInt(color.green() / 16); result += hexFromInt(color.green() % 16); result += hexFromInt(color.blue() / 16); result += hexFromInt(color.blue() % 16); return result; }