mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 21:10:19 +00:00
fix a bug of string interop
This commit is contained in:
parent
890d5a8662
commit
7993eb9000
@ -398,7 +398,11 @@ PyObject* VM::format(Str spec, PyObject* obj){
|
|||||||
int width, precision;
|
int width, precision;
|
||||||
try{
|
try{
|
||||||
if(dot >= 0){
|
if(dot >= 0){
|
||||||
width = Number::stoi(spec.substr(0, dot).str());
|
if(dot == 0){
|
||||||
|
width = -1;
|
||||||
|
}else{
|
||||||
|
width = Number::stoi(spec.substr(0, dot).str());
|
||||||
|
}
|
||||||
precision = Number::stoi(spec.substr(dot+1).str());
|
precision = Number::stoi(spec.substr(dot+1).str());
|
||||||
}else{
|
}else{
|
||||||
width = Number::stoi(spec.str());
|
width = Number::stoi(spec.str());
|
||||||
@ -424,7 +428,7 @@ PyObject* VM::format(Str spec, PyObject* obj){
|
|||||||
}else{
|
}else{
|
||||||
ret = CAST(Str&, py_str(obj));
|
ret = CAST(Str&, py_str(obj));
|
||||||
}
|
}
|
||||||
if(width > ret.length()){
|
if(width != -1 && width > ret.length()){
|
||||||
int pad = width - ret.length();
|
int pad = width - ret.length();
|
||||||
std::string padding(pad, pad_c);
|
std::string padding(pad, pad_c);
|
||||||
if(align == '>') ret = padding.c_str() + ret;
|
if(align == '>') ret = padding.c_str() + ret;
|
||||||
|
|||||||
@ -42,6 +42,8 @@ assert f'{a:010}' == '0000000010'
|
|||||||
assert f'{a:010d}' == '0000000010'
|
assert f'{a:010d}' == '0000000010'
|
||||||
assert f'{a:010f}' == '010.000000'
|
assert f'{a:010f}' == '010.000000'
|
||||||
assert f'{a:010.2f}' == '0000010.00'
|
assert f'{a:010.2f}' == '0000010.00'
|
||||||
|
assert f'{a:.2f}' == '10.00'
|
||||||
|
assert f'{a:.5f}' == '10.00000'
|
||||||
|
|
||||||
b = '123'
|
b = '123'
|
||||||
assert f'{b:10}' == '123 '
|
assert f'{b:10}' == '123 '
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user