MORE CONST
This commit is contained in:
parent
86a12f301e
commit
792642dd6f
@ -192,8 +192,8 @@ static usize to_string(usize value, usize base, char* buf, usize max, bool upper
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
int digit = (int)(value % base);
|
const int digit = (int)(value % base);
|
||||||
char c = (char)(digit < 10 ? '0' + digit : ((uppercase ? 'A' : 'a') + (digit - 10)));
|
const char c = (char)(digit < 10 ? '0' + digit : ((uppercase ? 'A' : 'a') + (digit - 10)));
|
||||||
buf[i++] = c;
|
buf[i++] = c;
|
||||||
value /= base;
|
value /= base;
|
||||||
} while (value && i < max);
|
} while (value && i < max);
|
||||||
@ -224,7 +224,7 @@ static Result<void> output_integer(char specifier, conv_state& vstate, format_st
|
|||||||
if (!(vstate.flags & FLAG_LEFT_ALIGN) &&
|
if (!(vstate.flags & FLAG_LEFT_ALIGN) &&
|
||||||
(vstate.flags & FLAG_ZERO_PAD)) // we're padding with zeroes from the beginning
|
(vstate.flags & FLAG_ZERO_PAD)) // we're padding with zeroes from the beginning
|
||||||
{
|
{
|
||||||
bool extra_char =
|
const bool extra_char =
|
||||||
negative || ((vstate.flags & FLAG_SIGN) ||
|
negative || ((vstate.flags & FLAG_SIGN) ||
|
||||||
(vstate.flags & FLAG_BLANK_SIGNED)); // are we adding an extra character after the buffer?
|
(vstate.flags & FLAG_BLANK_SIGNED)); // are we adding an extra character after the buffer?
|
||||||
if (vstate.width && extra_char) vstate.width--;
|
if (vstate.width && extra_char) vstate.width--;
|
||||||
@ -291,7 +291,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned char v = (unsigned char)va_arg(ap, unsigned int);
|
const unsigned char v = (unsigned char)va_arg(ap, unsigned int);
|
||||||
return output_integer(specifier, vstate, state, v, false);
|
return output_integer(specifier, vstate, state, v, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned short v = (unsigned short)va_arg(ap, unsigned int);
|
const unsigned short v = (unsigned short)va_arg(ap, unsigned int);
|
||||||
return output_integer(specifier, vstate, state, v, false);
|
return output_integer(specifier, vstate, state, v, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,7 +327,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned long long v = va_arg(ap, unsigned long long);
|
const unsigned long long v = va_arg(ap, unsigned long long);
|
||||||
return output_integer(specifier, vstate, state, v, false);
|
return output_integer(specifier, vstate, state, v, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,7 +345,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned long v = va_arg(ap, unsigned long);
|
const unsigned long v = va_arg(ap, unsigned long);
|
||||||
return output_integer(specifier, vstate, state, v, false);
|
return output_integer(specifier, vstate, state, v, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ static Result<void> va_output_integer(char specifier, conv_state& vstate, format
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned int v = va_arg(ap, unsigned int);
|
const unsigned int v = va_arg(ap, unsigned int);
|
||||||
return output_integer(specifier, vstate, state, v, false);
|
return output_integer(specifier, vstate, state, v, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,13 +396,13 @@ Result<usize> cstyle_format(const char* format, callback_t callback, void* arg,
|
|||||||
// %[flags][width][.precision][length]conversion
|
// %[flags][width][.precision][length]conversion
|
||||||
|
|
||||||
flags_t flags = parse_flags(&format);
|
flags_t flags = parse_flags(&format);
|
||||||
usize width = parse_width(&format, flags, ap);
|
const usize width = parse_width(&format, flags, ap);
|
||||||
usize precision = parse_precision(&format, flags, ap);
|
usize precision = parse_precision(&format, flags, ap);
|
||||||
parse_length(&format, flags);
|
parse_length(&format, flags);
|
||||||
|
|
||||||
conv_state vstate = {flags, width, precision};
|
conv_state vstate = {flags, width, precision};
|
||||||
|
|
||||||
char specifier = *format;
|
const char specifier = *format;
|
||||||
format++;
|
format++;
|
||||||
|
|
||||||
if (is_integer_format_specifier(specifier))
|
if (is_integer_format_specifier(specifier))
|
||||||
@ -412,7 +412,7 @@ Result<usize> cstyle_format(const char* format, callback_t callback, void* arg,
|
|||||||
}
|
}
|
||||||
else if (specifier == 'p')
|
else if (specifier == 'p')
|
||||||
{
|
{
|
||||||
void* ptr = va_arg(ap, void*);
|
const void* ptr = va_arg(ap, void*);
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
{
|
{
|
||||||
TRY(start_pad(vstate, state, 5));
|
TRY(start_pad(vstate, state, 5));
|
||||||
|
Loading…
Reference in New Issue
Block a user