Reformat libmaxsi format.cpp.
This commit is contained in:
parent
63b1c50cd2
commit
6f08593801
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
||||||
|
|
||||||
This file is part of LibMaxsi.
|
This file is part of LibMaxsi.
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||||
more details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
@ -20,18 +20,16 @@
|
||||||
format.cpp
|
format.cpp
|
||||||
Provides printf formatting functions that uses callbacks.
|
Provides printf formatting functions that uses callbacks.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace Maxsi
|
namespace String {
|
||||||
|
|
||||||
|
static int ConvertInt32(int32_t num, char* dest)
|
||||||
{
|
{
|
||||||
namespace String
|
|
||||||
{
|
|
||||||
int ConvertInt32(int32_t num, char* dest)
|
|
||||||
{
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int32_t copy = num;
|
int32_t copy = num;
|
||||||
|
|
||||||
|
@ -60,10 +58,10 @@ namespace Maxsi
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvertInt64(int64_t num, char* dest)
|
static int ConvertInt64(int64_t num, char* dest)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int64_t copy = num;
|
int64_t copy = num;
|
||||||
|
|
||||||
|
@ -92,10 +90,10 @@ namespace Maxsi
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvertUInt32(uint32_t num, char* dest)
|
static int ConvertUInt32(uint32_t num, char* dest)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
uint32_t copy = num;
|
uint32_t copy = num;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
@ -107,10 +105,10 @@ namespace Maxsi
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvertUInt64(uint64_t num, char* dest)
|
static int ConvertUInt64(uint64_t num, char* dest)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
uint64_t copy = num;
|
uint64_t copy = num;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
@ -122,10 +120,10 @@ namespace Maxsi
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvertUInt32Hex(uint32_t num, char* dest)
|
static int ConvertUInt32Hex(uint32_t num, char* dest)
|
||||||
{
|
{
|
||||||
char chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
char chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
'A', 'B', 'C', 'D', 'E', 'F' };
|
'A', 'B', 'C', 'D', 'E', 'F' };
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -139,10 +137,10 @@ namespace Maxsi
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConvertUInt64Hex(uint64_t num, char* dest)
|
static int ConvertUInt64Hex(uint64_t num, char* dest)
|
||||||
{
|
{
|
||||||
char chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
char chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
'A', 'B', 'C', 'D', 'E', 'F' };
|
'A', 'B', 'C', 'D', 'E', 'F' };
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -156,23 +154,22 @@ namespace Maxsi
|
||||||
}
|
}
|
||||||
|
|
||||||
return result + 1;
|
return result + 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
namespace Format
|
} // namespace String
|
||||||
{
|
|
||||||
#define READY_SIZE 128
|
|
||||||
|
|
||||||
#define READY_FLUSH() \
|
#define READY_SIZE 128
|
||||||
|
|
||||||
|
#define READY_FLUSH() \
|
||||||
ready[readylen] = '\0'; \
|
ready[readylen] = '\0'; \
|
||||||
if ( 0 < readylen && callback && callback(user, ready, readylen) != readylen ) { return SIZE_MAX; } \
|
if ( 0 < readylen && callback && callback(user, ready, readylen) != readylen ) { return SIZE_MAX; } \
|
||||||
written += readylen; readylen = 0;
|
written += readylen; readylen = 0;
|
||||||
|
|
||||||
extern "C" size_t vprintf_callback(size_t (*callback)(void*, const char*, size_t),
|
extern "C" size_t vprintf_callback(size_t (*callback)(void*, const char*, size_t),
|
||||||
void* user,
|
void* user,
|
||||||
const char* restrict format,
|
const char* restrict format,
|
||||||
va_list parameters)
|
va_list parameters)
|
||||||
{
|
{
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
size_t readylen = 0;
|
size_t readylen = 0;
|
||||||
char ready[READY_SIZE + 1];
|
char ready[READY_SIZE + 1];
|
||||||
|
@ -327,6 +324,4 @@ namespace Maxsi
|
||||||
READY_FLUSH();
|
READY_FLUSH();
|
||||||
|
|
||||||
return written;
|
return written;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue