support signed
This commit is contained in:
@ -54,7 +54,16 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
|
|||||||
value >>= 8;
|
value >>= 8;
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
byte = (byte & 0x80) ? 0xFF : 0x00; // fill with sign
|
if (format.flags & zero_flag)
|
||||||
|
{
|
||||||
|
// fill with zero
|
||||||
|
byte = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fill with sign
|
||||||
|
byte = (byte & 0x80) ? 0xFF : 0x00;
|
||||||
|
}
|
||||||
while (width--)
|
while (width--)
|
||||||
{
|
{
|
||||||
output.append(byte);
|
output.append(byte);
|
||||||
@ -62,8 +71,17 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
|
|||||||
}
|
}
|
||||||
else // msb first (big endian)
|
else // msb first (big endian)
|
||||||
{
|
{
|
||||||
|
if (format.flags & zero_flag)
|
||||||
|
{
|
||||||
|
// fill with zero
|
||||||
|
byte = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fill with sign
|
||||||
byte = ((value >> (8 * (prec-1))) & 0x80) ? 0xFF : 0x00;
|
byte = ((value >> (8 * (prec-1))) & 0x80) ? 0xFF : 0x00;
|
||||||
while (width > prec) // fill with sign
|
}
|
||||||
|
while (width > prec)
|
||||||
{
|
{
|
||||||
output.append(byte);
|
output.append(byte);
|
||||||
width--;
|
width--;
|
||||||
@ -98,14 +116,32 @@ scanLong(const StreamFormat& format, const char* input, long& value)
|
|||||||
}
|
}
|
||||||
if (width == 0)
|
if (width == 0)
|
||||||
{
|
{
|
||||||
|
if (format.flags & zero_flag)
|
||||||
|
{
|
||||||
|
// fill with zero
|
||||||
|
val |= ((unsigned char) input[length++]) << shift;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fill with sign
|
||||||
val |= ((signed char) input[length++]) << shift;
|
val |= ((signed char) input[length++]) << shift;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
length += width; // ignore upper bytes not fitting in long
|
length += width; // ignore upper bytes not fitting in long
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// big endian (sign extended)*/
|
// big endian */
|
||||||
|
if (format.flags & zero_flag)
|
||||||
|
{
|
||||||
|
// fill with zero
|
||||||
|
val = (unsigned char) input[length++];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fill with sign
|
||||||
val = (signed char) input[length++];
|
val = (signed char) input[length++];
|
||||||
|
}
|
||||||
while (--width)
|
while (--width)
|
||||||
{
|
{
|
||||||
val <<= 8;
|
val <<= 8;
|
||||||
|
Reference in New Issue
Block a user