print ascii code of a character (ktoi)
This commit is contained in:
@@ -9,26 +9,34 @@
|
||||
|
||||
std::string mini_sprintf_format(bool left_align, bool sign, bool space_on_left, bool padding_by_zero, int width, int precision, int length, char specifier, const MlValue &value) {
|
||||
std::string s;
|
||||
std::ostringstream stream_str; // PERF simpler solution..without string stream
|
||||
bool is_positive = false;
|
||||
|
||||
if (specifier == 's') {
|
||||
return value.as_string();
|
||||
}
|
||||
if (specifier == 'c') {
|
||||
std::ostringstream stream_str;
|
||||
stream_str << (char) value.as_int();
|
||||
return stream_str.str();
|
||||
}
|
||||
if (specifier == 'i' || specifier == 'd') {
|
||||
int ival = value.as_int();
|
||||
is_positive = ival >= 0;
|
||||
if (value.is_number()) {
|
||||
int ival = value.as_int();
|
||||
is_positive = ival >= 0;
|
||||
|
||||
s = std::to_string(ival);
|
||||
s = std::to_string(ival);
|
||||
} else if (value.is_string()) { // print ascii code of character
|
||||
if (value.as_string().size() > 0) {
|
||||
stream_str << (int)value.as_string()[0];
|
||||
return stream_str.str();
|
||||
} else {
|
||||
// TODO handle empty string - error?
|
||||
}
|
||||
}
|
||||
} else if (specifier == 'f' || specifier == 'e') {
|
||||
double dval = value.as_float();
|
||||
is_positive = dval >= 0;
|
||||
|
||||
std::ostringstream stream_str;
|
||||
if (specifier == 'f')
|
||||
stream_str << std::fixed;
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user