|
#pragma once
/// \file tstoi.hpp
/// tomato::tstoi works around CRT.
namespace tomato {
/// \cond OUTPUT_DETAIL
namespace detail {
inline bool is_space(TCHAR c)
{
return c == _T(' ');
}
inline bool is_digit(TCHAR c)
{
return c >= _T('0') && c <= _T('9');
}
inline bool is_sign(TCHAR c)
{
return c == _T('-') || c == _T('+');
}
inline bool is_minus(TCHAR c)
{
return c == _T('-');
}
inline int to_digit(TCHAR c)
{
ATLASSERT(is_digit(c));
return c - _T('0');
}
} // namespace detail
/// \endcond
inline int tstoi(LPCTSTR psz)
{
// See: crt/_tstol
while (detail::is_space(*psz))
++psz;
TCHAR c = *psz++;
bool neg = false;
if (detail::is_sign(c))
{
if (detail::is_minus(c))
neg = true;
c = *psz++;
}
int total = 0;
while (detail::is_digit(c))
{
total = 10 * total + detail::to_digit(c);
c = *psz++;
}
if (neg)
return -total;
else
return total;
}
} // namespace tomato
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here