32using std::stringstream;
33using std::istringstream;
47 return ((d < 0.0) ? ceil(d - 0.5) : floor(d + 0.5));
56 return static_cast<int>((d < 0.0) ? ceil(d - 0.5) : floor(d + 0.5));
70 istringstream iStr(str);
73 if (!(iStr >> dDummy))
85 size_t const nPos = str.find_first_not_of(
" \t");
87 if (nPos != string::npos)
88 str = str.substr(nPos);
91 if ((str[0] ==
'-') || (str[0] ==
'+'))
95 return (str.find_first_not_of(
"0123456789") == string::npos);
103 ostr.fill(args.chFill);
104 ostr.width(args.nWidth);
112string strDbl(
double const dX,
int const nDigits)
116 ss.precision(nDigits);
124string strDblRight(
double const dX,
int const nDigits,
int const nWidth,
bool const bShowDash)
127 ss << fixed << right;
129 ss.width(nWidth - 1);
142 ss.precision(nDigits);
156 ss << fixed << right;
158 ss.width(nWidth - 1);
169 string const strIn(pchIn);
170 stringstream ss, spaces;
171 int const nPadding = nWidth -
static_cast<int>(strIn.size());
173 for (
int i = 0; i < nPadding / 2; ++i)
176 ss << spaces.str() << strIn << spaces.str();
178 if (nPadding > 0 && nPadding % 2 != 0)
189 stringstream ss, spaces;
190 int const nPadding = nWidth -
static_cast<int>(strIn.size());
192 for (
int i = 0; i < nPadding / 2; ++i)
195 ss << spaces.str() << strIn << spaces.str();
197 if (nPadding > 0 && nPadding % 2 != 0)
206string strRight(
const string& strIn,
int const nWidth)
208 stringstream ss, spaces;
209 int const nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
211 for (
int i = 0; i < nPadding; ++i)
214 ss << spaces.str() << strIn;
222string strRight(
const char* pchIn,
int const nWidth)
224 string const strIn(pchIn);
225 stringstream ss, spaces;
226 int const nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
228 for (
int i = 0; i < nPadding; ++i)
231 ss << spaces.str() << strIn;
239string strLeft(
const string& strIn,
int const nWidth)
241 stringstream ss, spaces;
242 int const nPadding = nWidth -
static_cast<int>(strIn.size());
244 for (
int i = 0; i < nPadding; ++i)
247 ss << strIn << spaces.str();
254string strLeft(
const char* pchIn,
int const nWidth)
256 string const strIn(pchIn);
257 stringstream ss, spaces;
258 int const nPadding = nWidth -
static_cast<int>(strIn.size());
260 for (
int i = 0; i < nPadding; ++i)
263 ss << strIn << spaces.str();
270string strRightPerCent(
double const d1,
double const d2,
int const nWidth,
int const nDigits,
bool const bShowDash)
273 ss << fixed << right;
279 ss.width(nWidth - 1);
291 double const dResult = 100 * d1 / d2;
293 stringstream ssResult;
294 ssResult << fixed << right;
295 ssResult.precision(nDigits);
296 ssResult <<
"(" << dResult <<
"%)";
298 long int const nResultWidth = ssResult.str().size();
300 for (
int i = 0; i < (nWidth - nResultWidth - 1); i++)
303 ss << ssResult.str();
This file contains global definitions for CoastalME.
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
double dRound(double const d)
Correctly rounds doubles.
bool bIsStringValidInt(string &str)
Checks to see if a string can be read as a valid integer, from https://stackoverflow....
int nRound(double const d)
Version of the above that returns an int.
string strLeft(const string &strIn, int const nWidth)
Left-aligns string within a field of given width, pads with blank spaces to enforce alignment....
string strDblRight(double const dX, int const nDigits, int const nWidth, bool const bShowDash)
Converts double to string with specified number of decimal places, within a field of given width,...
string strRightPerCent(double const d1, double const d2, int const nWidth, int const nDigits, bool const bShowDash)
Calculates a percentage from two numbers then, if the result is non-zero, right-aligns the result as ...
string strDbl(double const dX, int const nDigits)
Converts double to string with specified number of places after the decimal. From https://stackoverfl...
string strCentre(const char *pchIn, int const nWidth)
Centre-aligns char array within a field of given width, pads with blank spaces to enforce alignment....
ostream & operator<<(ostream &ostr, const FillToWidth &args)
Operator that inserts a given fill character, to a given width, into an output stream....
string strRight(const string &strIn, int const nWidth)
Right-aligns string within a field of given width, pads with blank spaces to enforce alignment....
bool bIsStringValidDouble(string &str)
Checks to see if a string can be read as a valid double number. Does not find trailing (i....
string strIntRight(int const nX, int const nWidth)
Converts int to string within a field of given width, pads with blank spaces to enforce alignment....