/*!  Adds checksum to GDB Tx buffer
  */
void GdbInOut::putGdbChecksum(void) {
   int checksum = gdbTxChecksum & 0xFF;
   putGdbChar('#');
   putGdbChar(hexChar(checksum >> 4));
   putGdbChar(hexChar(checksum % 16));
   putGdbChar('\0');
}
/*!  Add bytes to GDB Tx buffer as Hex character pairs
 *
 *   @param buff  Buffer to add
 *   @param size  Size of buffer
 */
void GdbInOut::putGdbHex(const unsigned char *buffer, unsigned size) {
  unsigned index;
  for (index=0; index<size; index++) {
     putGdbChar(hexChar(buffer[index]>>4));
     putGdbChar(hexChar(buffer[index]));
  }
}
 /*!  Add a string to GDB Tx buffer as a series of hex digit pairs
  *
  *   @param s    - '\0' terminated string to add
  *   @param size - maximum size to send (-1 ignored)
  */
void GdbInOut::putGdbHexString(const char *s, int size) {
   while ((*s != '\0') && (size != 0)) {
      putGdbChar(hexChar((*s)>>4));
      putGdbChar(hexChar(*s++));
      if (size > 0)
         size--;
   }
}
HBufC8* CVBookmarkConverter::DecodeQuotedPrintableLC( const TDesC8& aEncodedData )
    {
    TInt encodedLength = aEncodedData.Length();
    
    HBufC8* decodeBuffer = HBufC8::NewLC( encodedLength );
    TPtr8 ptrDecodeBuffer = decodeBuffer->Des();
    
    TInt i(0);
    while ( i < encodedLength )
        {
        TChar nextChar = aEncodedData[i++];
        
        if ( nextChar == '=' )
            {
            if ( i + 2 > encodedLength )
                {
                ptrDecodeBuffer.Append( '=' );
                if ( i + 1 == encodedLength )
                    {
                    ptrDecodeBuffer.Append( aEncodedData[i++] );
                    }     
                }
            else
                {
                TPtrC8 data = aEncodedData.Mid( i, 2 );
                i += 2;    
                
                if ( data.Compare(KVBMKLinefeed) == 0 )
                    {
                    // Do nothing
                    // '=' at the end of line is soft line break, not to be decoded
                    }
                else
                    {
                    TLex8 hexChar( data );
                    TUint8 value( 0 );
                    
                    if ( hexChar.Val( value, EHex ) == KErrNone )
                        {
                        ptrDecodeBuffer.Append( TChar( value ) );
                        }
                    else
                        {
                        // Decoding failed, put the data at itself
                        ptrDecodeBuffer.Append( '=' );
                        ptrDecodeBuffer.Append( data );
                        }    
                    }
                }
            }
        else
            {
            ptrDecodeBuffer.Append( nextChar );
            }    
        }
        
    return decodeBuffer;    
    }
예제 #5
0
 String QueryParseError::addEscapes(const String& str)
 {
     StringStream buffer;
     for (String::const_iterator ch = str.begin(); ch != str.end(); ++ch)
     {
         switch (*ch)
         {
             case L'\0':
                 continue;
             case L'\b':
                 buffer << L"\\b";
                 continue;
             case L'\t':
                 buffer << L"\\t";
                 continue;
             case L'\n':
                 buffer << L"\\n";
                 continue;
             case L'\f':
                 buffer << L"\\f";
                 continue;
             case L'\r':
                 buffer << L"\\r";
                 continue;
             case L'\"':
                 buffer << L"\\\"";
                 continue;
             case L'\'':
                 buffer << L"\\\'";
                 continue;
             case L'\\':
                 buffer << L"\\\\";
                 continue;
             default:
                 if (*ch < 0x20 || *ch > 0x7e)
                 {
                     String hexChar(L"0000" + StringUtils::toString(*ch, 16));
                     buffer << L"\\u" + hexChar.substr(hexChar.length() - 4);
                 }
                 else
                     buffer << *ch;
                 continue;
         }
     }
     return buffer.str();
 }
예제 #6
0
void WifiCreds::writeHex(byte val, char *str, int pos1, int pos2) {
  byte left = val / 16;
  byte right = val - (left * 16);
  str[pos1] = hexChar(left);
  str[pos2] = hexChar(right);
}
예제 #7
0
void CJsonFormatter::printValue(const std::string & value)
{
    buf << '\"';

    const char * str = value.c_str();
    for (;;) {

        if (!str || *str == '\0') break;

        else if (*str == '\"' || *str == '\\' || *str == '/') {
            buf << '\\' << *str;
            ++str;
            continue;
        }

        else if (*str >= ' ' && *str <= 127) {
            buf << *str;
            ++str;
            continue;
        }

        else if (*str == '\b') {
            buf << "\\b";
            ++str;
            continue;
        }

        else if (*str == '\t') {
            buf << "\\t";
            ++str;
            continue;
        }

        else if (*str == '\n') {
            buf << "\\n";
            ++str;
            continue;
        }

        else if (*str == '\f') {
            buf << "\\f";
            ++str;
            continue;
        }

        else if (*str == '\r') {
            buf << "\\r";
            ++str;
            continue;
        }



        uint64_t code = 0;
        int max_lex = strlen(str);
        int len = 0;

        if (false) ; /* For symmetry */

        else if ((*str & 0x60) == 0x40) {
            code = *str & 0x1F;
            len = 2;
        }

        else if ((*str & 0x70) == 0x60) {
            code = *str & 0x0F;
            len = 3;
        }

        else if ((*str & 0x78) == 0x70) {
            code = *str & 0x07;
            len = 4;
        }

        else if ((*str & 0x7C) == 0x78) {
            code = *str & 0x03;
            len = 5;
        }

        else if ((*str & 0x7E) == 0x7C) {
            code = *str & 0x01;
            len = 6;
        }

        len = len > max_lex ? max_lex : len;

        if (len == 0) {
            buf << "?";
            ++str;
            continue;
        }

        for (int i=1; i<len; ++i) {

            if (str[i] >= 0 || (str[i] & 0x40) != 0) {
                buf << "?";
                continue;
            }

            code <<= 6;
            code |= str[i] & 0x3F;
        }

        if (code <= 0xFFFF) {

            hexChar(code);
        }
        else {

            uint64_t ex_code = code - 0x10000;
            uint64_t lo = ex_code & 0x3FF;
            uint64_t hi = ex_code >> 10;
            if (hi <= 0x3FF) {
                hexChar(hi + 0xD800);
                hexChar(lo + 0xDC00);
            } else {
                buf << '?';
            }
        }

        str += len;
    }

    buf << '\"';
}