Code Cleanup

- Migrated format helper functions over from taskd.
- Converted much of the sprintf usage to format calls.
This commit is contained in:
Paul Beckingham 2010-12-27 16:31:11 -05:00
parent 5f007ed1d9
commit a6cf99a83c
12 changed files with 138 additions and 47 deletions

View file

@ -26,6 +26,7 @@
////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <ctype.h>
#include "Nibbler.h"
@ -290,6 +291,33 @@ bool Nibbler::getInt (int& result)
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool Nibbler::getHex (int& result)
{
std::string::size_type i = mCursor;
if (i < mLength)
{
if (mInput[i] == '-')
++i;
else if (mInput[i] == '+')
++i;
}
// TODO Potential for use of find_first_not_of
while (i < mLength && isxdigit (mInput[i]))
++i;
if (i > mCursor)
{
result = strtoimax (mInput.substr (mCursor, i - mCursor).c_str (), NULL, 16);
mCursor = i;
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool Nibbler::getUnsignedInt (int& result)
{