26using std::stringstream;
27using std::istringstream;
41 return ((d < 0.0) ? ceil(d - 0.5) : floor(d + 0.5));
50 return static_cast<int>((d < 0.0) ? ceil(d - 0.5) : floor(d + 0.5));
64 istringstream iStr(str);
67 if (! (iStr >> dDummy))
79 size_t const nPos = str.find_first_not_of(
" \t");
81 if (nPos != string::npos)
82 str = str.substr(nPos);
85 if ((str[0] ==
'-') || (str[0] ==
'+'))
89 return (str.find_first_not_of(
"0123456789") == string::npos);
95ostream&
operator<<(ostream& ostr,
const FillToWidth& args)
97 ostr.fill(args.chFill);
98 ostr.width(args.nWidth);
118string strDblRight(
double const dX,
int const nDigits,
int const nWidth,
bool const bShowDash)
121 ss << fixed << right;
123 ss.width(nWidth - 1);
136 ss.precision(nDigits);
150 ss << fixed << right;
152 ss.width(nWidth - 1);
163 string const strIn(pchIn);
164 stringstream ss, spaces;
165 int const nPadding = nWidth -
static_cast<int>(strIn.size());
167 for (
int i = 0; i < nPadding / 2; ++i)
170 ss << spaces.str() << strIn << spaces.str();
172 if (nPadding > 0 && nPadding % 2 != 0)
183 stringstream ss, spaces;
184 int const nPadding = nWidth -
static_cast<int>(strIn.size());
186 for (
int i = 0; i < nPadding / 2; ++i)
189 ss << spaces.str() << strIn << spaces.str();
191 if (nPadding > 0 && nPadding % 2 != 0)
200string strRight(
const string& strIn,
int const nWidth)
202 stringstream ss, spaces;
203 int const nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
205 for (
int i = 0; i < nPadding; ++i)
208 ss << spaces.str() << strIn;
216string strRight(
const char* pchIn,
int const nWidth)
218 string const strIn(pchIn);
219 stringstream ss, spaces;
220 int const nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
222 for (
int i = 0; i < nPadding; ++i)
225 ss << spaces.str() << strIn;
233string strLeft(
const string& strIn,
int const nWidth)
235 stringstream ss, spaces;
236 int const nPadding = nWidth -
static_cast<int>(strIn.size());
238 for (
int i = 0; i < nPadding; ++i)
241 ss << strIn << spaces.str();
248string strLeft(
const char* pchIn,
int const nWidth)
250 string const strIn(pchIn);
251 stringstream ss, spaces;
252 int const nPadding = nWidth -
static_cast<int>(strIn.size());
254 for (
int i = 0; i < nPadding; ++i)
257 ss << strIn << spaces.str();
264string strRightPerCent(
double const d1,
double const d2,
int const nWidth,
int const nDigits,
bool const bShowDash)
267 ss << fixed << right;
273 ss.width(nWidth - 1);
284 double const dResult = 100 * d1 / d2;
286 stringstream ssResult;
287 ssResult << fixed << right;
288 ssResult.precision(nDigits);
289 ssResult <<
"(" << dResult <<
"%)";
291 long int const nResultWidth = ssResult.str().size();
293 for (
int i = 0; i < (nWidth - nResultWidth - 1); i++)
296 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)
Correctly rounds doubles, 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 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....