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

Function formatUInt

sdk/add_on/scriptstdstring/scriptstdstring.cpp:562–602  ·  view source on GitHub ↗

AngelScript signature: string formatUInt(uint64 val, const string &in options, uint width)

Source from the content-addressed store, hash-verified

560// AngelScript signature:
561// string formatUInt(uint64 val, const string &in options, uint width)
562static string formatUInt(asQWORD value, const string &options, asUINT width)
563{
564 bool leftJustify = options.find("l") != string::npos;
565 bool padWithZero = options.find("0") != string::npos;
566 bool alwaysSign = options.find("+") != string::npos;
567 bool spaceOnSign = options.find(" ") != string::npos;
568 bool hexSmall = options.find("h") != string::npos;
569 bool hexLarge = options.find("H") != string::npos;
570
571 string fmt = "%";
572 if( leftJustify ) fmt += "-";
573 if( alwaysSign ) fmt += "+";
574 if( spaceOnSign ) fmt += " ";
575 if( padWithZero ) fmt += "0";
576
577#ifdef _WIN32
578 fmt += "*I64";
579#else
580#ifdef _LP64
581 fmt += "*l";
582#else
583 fmt += "*ll";
584#endif
585#endif
586
587 if( hexSmall ) fmt += "x";
588 else if( hexLarge ) fmt += "X";
589 else fmt += "u";
590
591 string buf;
592 buf.resize(width+30);
593#if _MSC_VER >= 1400 && !defined(__S3E__)
594 // MSVC 8.0 / 2005 or newer
595 sprintf_s(&buf[0], buf.size(), fmt.c_str(), width, value);
596#else
597 snprintf(&buf[0], buf.size(), fmt.c_str(), width, value);
598#endif
599 buf.resize(strlen(&buf[0]));
600
601 return buf;
602}
603
604// AngelScript signature:
605// string formatFloat(double val, const string &in options, uint width, uint precision)

Callers 1

formatUInt_GenericFunction · 0.85

Calls 2

findMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected