MCPcopy Create free account
hub / github.com/anjo76/angelscript / formatInt

Function formatInt

sdk/add_on/scriptstdstring/scriptstdstring.cpp:518–558  ·  view source on GitHub ↗

AngelScript signature: string formatInt(int64 val, const string &in options, uint width)

Source from the content-addressed store, hash-verified

516// AngelScript signature:
517// string formatInt(int64 val, const string &in options, uint width)
518static string formatInt(asINT64 value, const string &options, asUINT width)
519{
520 bool leftJustify = options.find("l") != string::npos;
521 bool padWithZero = options.find("0") != string::npos;
522 bool alwaysSign = options.find("+") != string::npos;
523 bool spaceOnSign = options.find(" ") != string::npos;
524 bool hexSmall = options.find("h") != string::npos;
525 bool hexLarge = options.find("H") != string::npos;
526
527 string fmt = "%";
528 if( leftJustify ) fmt += "-";
529 if( alwaysSign ) fmt += "+";
530 if( spaceOnSign ) fmt += " ";
531 if( padWithZero ) fmt += "0";
532
533#ifdef _WIN32
534 fmt += "*I64";
535#else
536#ifdef _LP64
537 fmt += "*l";
538#else
539 fmt += "*ll";
540#endif
541#endif
542
543 if( hexSmall ) fmt += "x";
544 else if( hexLarge ) fmt += "X";
545 else fmt += "d";
546
547 string buf;
548 buf.resize(width+30);
549#if _MSC_VER >= 1400 && !defined(__S3E__)
550 // MSVC 8.0 / 2005 or newer
551 sprintf_s(&buf[0], buf.size(), fmt.c_str(), width, value);
552#else
553 snprintf(&buf[0], buf.size(), fmt.c_str(), width, value);
554#endif
555 buf.resize(strlen(&buf[0]));
556
557 return buf;
558}
559
560// AngelScript signature:
561// string formatUInt(uint64 val, const string &in options, uint width)

Callers 1

formatInt_GenericFunction · 0.85

Calls 2

findMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected