S
Sridhar Anupindi
Hi,
I am using the following algorithm to decode the string into ASCII
set of characters.. The function returns me the decoded string but the
problem is that my string contains both normal characters and also the
BASE64 Character set ( like this
"<searchKeyword>çãñ</searchKeyword>").
Since I am passing the entire string to this function and I want this
function to handle only the BASE64 Characters and ignore the rest of
the characters. Any help is greatly appreciated.
string decode(const string& data)
{
string::size_type i;
char c;
char c1;
string::size_type len = data.length();
string ret;
ret.reserve(len);
for (i = 0; i < len; ++i)
{
c = (char) DecodeTable[(unsigned char)data];
++i;
c1 = (char) DecodeTable[(unsigned char)data];
c = (c << 2) | ((c1 >> 4) & 0x3);
ret.append(1, c);
if (++i < len)
{
c = data;
if (fillchar == c)
break;
c = (char) DecodeTable[(unsigned char)data];
c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
ret.append(1, c1);
}
if (++i < len)
{
c1 = data;
if (fillchar == c1)
break;
c1 = (char) DecodeTable[(unsigned char)data];
c = ((c << 6) & 0xc0) | c1;
ret.append(1, c);
}
}
return(ret);
}
Thanks
Sridhar Anupindi
I am using the following algorithm to decode the string into ASCII
set of characters.. The function returns me the decoded string but the
problem is that my string contains both normal characters and also the
BASE64 Character set ( like this
"<searchKeyword>çãñ</searchKeyword>").
Since I am passing the entire string to this function and I want this
function to handle only the BASE64 Characters and ignore the rest of
the characters. Any help is greatly appreciated.
string decode(const string& data)
{
string::size_type i;
char c;
char c1;
string::size_type len = data.length();
string ret;
ret.reserve(len);
for (i = 0; i < len; ++i)
{
c = (char) DecodeTable[(unsigned char)data];
++i;
c1 = (char) DecodeTable[(unsigned char)data];
c = (c << 2) | ((c1 >> 4) & 0x3);
ret.append(1, c);
if (++i < len)
{
c = data;
if (fillchar == c)
break;
c = (char) DecodeTable[(unsigned char)data];
c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
ret.append(1, c1);
}
if (++i < len)
{
c1 = data;
if (fillchar == c1)
break;
c1 = (char) DecodeTable[(unsigned char)data];
c = ((c << 6) & 0xc0) | c1;
ret.append(1, c);
}
}
return(ret);
}
Thanks
Sridhar Anupindi