AngelScript signature: string formatFloat(double val, const string &in options, uint width, uint precision)
| 531 | // AngelScript signature: |
| 532 | // string formatFloat(double val, const string &in options, uint width, uint precision) |
| 533 | static string formatFloat(double value, const string &options, asUINT width, asUINT precision) |
| 534 | { |
| 535 | bool leftJustify = options.find("l") != string::npos; |
| 536 | bool padWithZero = options.find("0") != string::npos; |
| 537 | bool alwaysSign = options.find("+") != string::npos; |
| 538 | bool spaceOnSign = options.find(" ") != string::npos; |
| 539 | bool expSmall = options.find("e") != string::npos; |
| 540 | bool expLarge = options.find("E") != string::npos; |
| 541 | |
| 542 | string fmt = "%"; |
| 543 | if( leftJustify ) fmt += "-"; |
| 544 | if( alwaysSign ) fmt += "+"; |
| 545 | if( spaceOnSign ) fmt += " "; |
| 546 | if( padWithZero ) fmt += "0"; |
| 547 | |
| 548 | fmt += "*.*"; |
| 549 | |
| 550 | if( expSmall ) fmt += "e"; |
| 551 | else if( expLarge ) fmt += "E"; |
| 552 | else fmt += "f"; |
| 553 | |
| 554 | string buf; |
| 555 | buf.resize(width+precision+50); |
| 556 | #if _MSC_VER >= 1400 && !defined(__S3E__) |
| 557 | // MSVC 8.0 / 2005 or newer |
| 558 | sprintf_s(&buf[0], buf.size(), fmt.c_str(), width, precision, value); |
| 559 | #else |
| 560 | sprintf(&buf[0], fmt.c_str(), width, precision, value); |
| 561 | #endif |
| 562 | buf.resize(strlen(&buf[0])); |
| 563 | |
| 564 | return buf; |
| 565 | } |
| 566 | |
| 567 | // AngelScript signature: |
| 568 | // int64 parseInt(const string &in val, uint base = 10, uint &out byteCount = 0) |
no test coverage detected