Menu

#1 Support for alphanumeric address information

open
nobody
None
5
2011-01-17
2011-01-17
No

I have added the following code to support alpha addresses an Address::from_stream:

void from_stream(std::istream& st)
{
std::basic_ostringstream<CharT, Traits> dst;
unsigned char len = 0;
unsigned char toa = 0;

unsigned int n = 0;
unsigned char cx = 0;

for (unsigned char i = 0; i < len + 1; ++i)
{
unsigned char x = (unsigned char)st.get();
if (!st) {
st.setstate( std::ios::failbit );
return;
}

if (0 == i)
len = x / 2 + x % 2 + 1;
else if (1 == i)
{
toa = x;
if (0x91 == toa && 1 < len)
dst << dst.widen('+');
}
else
{
// WMM - if the address type (toa) is 0xd0, then the
// address is alphanumeric; 7-bit alphabet
if (0xD0 == toa)
{
//--userDataOctetLenght;

unsigned char ch = x;
ch <<= n + 1;
ch >>= 1;
ch |= cx;
dst << dst.widen(ch);

++n;
cx = x >> (8 - n);

if (n == 7)
{
dst << dst.widen(cx);
n = 0;
cx = 0;
}
}
else
{
unsigned int hi = x >> 4;
unsigned int low = x & 0x0F;

if ( (low > 9) || (hi > 9 && i < len-1) )
{
st.setstate( std::ios::failbit );
return;
}

dst << low;
if (hi < 10)
dst << hi;
}
}
}

addressType_ = toa;
address_ = dst.str();
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.