More consistent types in ConversionUtils.

This commit is contained in:
lganzzzo 2020-01-25 03:21:03 +07:00
parent 77f27c30db
commit ae003a0d9e
2 changed files with 27 additions and 27 deletions

View File

@ -75,26 +75,26 @@ namespace oatpp { namespace utils { namespace conversion {
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
return result;
}
v_int32 int32ToCharSequence(v_int32 value, p_char8 data, v_int32 n) {
v_buff_size int32ToCharSequence(v_int32 value, p_char8 data, v_buff_size n) {
return snprintf((char*)data, n, "%ld", (long) value);
}
v_int32 uint32ToCharSequence(v_uint32 value, p_char8 data, v_int32 n) {
v_buff_size uint32ToCharSequence(v_uint32 value, p_char8 data, v_buff_size n) {
return snprintf((char*)data, n, "%lu", (unsigned long) value);
}
v_int32 int64ToCharSequence(v_int64 value, p_char8 data, v_int32 n) {
return snprintf((char*)data, n, "%lld", value);
v_buff_size int64ToCharSequence(v_int64 value, p_char8 data, v_buff_size n) {
return snprintf((char*)data, n, "%lld", (long long int) value);
}
v_int32 uint64ToCharSequence(v_uint64 value, p_char8 data, v_int32 n) {
return snprintf((char*)data, n, "%llu", value);
v_buff_size uint64ToCharSequence(v_uint64 value, p_char8 data, v_buff_size n) {
return snprintf((char*)data, n, "%llu", (long long unsigned int) value);
}
oatpp::String int32ToStr(v_int32 value){
v_char8 buff [16]; // Max 10 digits with 1 sign. 16 is plenty enough.
v_int32 size = int32ToCharSequence(value, &buff[0], 16);
auto size = int32ToCharSequence(value, &buff[0], 16);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}
@ -103,7 +103,7 @@ namespace oatpp { namespace utils { namespace conversion {
oatpp::String uint32ToStr(v_uint32 value){
v_char8 buff [16]; // Max 10 digits. 16 is plenty enough.
v_int32 size = uint32ToCharSequence(value, &buff[0], 16);
auto size = uint32ToCharSequence(value, &buff[0], 16);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}
@ -112,7 +112,7 @@ namespace oatpp { namespace utils { namespace conversion {
oatpp::String int64ToStr(v_int64 value){
v_char8 buff [32]; // Max 20 digits unsigned, 19 digits +1 sign signed.
v_int32 size = int64ToCharSequence(value, &buff[0], 32);
auto size = int64ToCharSequence(value, &buff[0], 32);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}
@ -121,7 +121,7 @@ namespace oatpp { namespace utils { namespace conversion {
oatpp::String uint64ToStr(v_uint64 value){
v_char8 buff [32]; // Max 20 digits.
v_int32 size = uint64ToCharSequence(value, &buff[0], 32);
auto size = uint64ToCharSequence(value, &buff[0], 32);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}
@ -130,7 +130,7 @@ namespace oatpp { namespace utils { namespace conversion {
std::string int32ToStdStr(v_int32 value){
v_char8 buff [16];
v_int32 size = int32ToCharSequence(value, &buff[0], 16);
auto size = int32ToCharSequence(value, &buff[0], 16);
if(size > 0){
return std::string((const char*)buff, size);
}
@ -139,7 +139,7 @@ namespace oatpp { namespace utils { namespace conversion {
std::string uint32ToStdStr(v_uint32 value){
v_char8 buff [16];
v_int32 size = uint32ToCharSequence(value, &buff[0], 16);
auto size = uint32ToCharSequence(value, &buff[0], 16);
if(size > 0){
return std::string((const char*)buff, size);
}
@ -157,7 +157,7 @@ namespace oatpp { namespace utils { namespace conversion {
std::string uint64ToStdStr(v_uint64 value){
v_char8 buff [32];
v_int32 size = uint64ToCharSequence(value, &buff[0], 32);
auto size = uint64ToCharSequence(value, &buff[0], 32);
if(size > 0){
return std::string((const char*)buff, size);
}
@ -187,8 +187,8 @@ namespace oatpp { namespace utils { namespace conversion {
success = (((v_buff_size)end - (v_buff_size)str->getData()) == str->getSize());
return result;
}
v_int32 float32ToCharSequence(v_float32 value, p_char8 data, v_int32 n) {
v_buff_size float32ToCharSequence(v_float32 value, p_char8 data, v_buff_size n) {
return snprintf((char*)data, n, "%f", value);
}
@ -198,7 +198,7 @@ namespace oatpp { namespace utils { namespace conversion {
oatpp::String float32ToStr(v_float32 value){
v_char8 buff [100];
v_int32 size = float32ToCharSequence(value, &buff[0], 100);
auto size = float32ToCharSequence(value, &buff[0], 100);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}
@ -207,7 +207,7 @@ namespace oatpp { namespace utils { namespace conversion {
oatpp::String float64ToStr(v_float64 value){
v_char8 buff [100];
v_int32 size = float64ToCharSequence(value, &buff[0], 100);
auto size = float64ToCharSequence(value, &buff[0], 100);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}

View File

@ -103,7 +103,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @param n - buffer size.
* @return - length of the resultant string.
*/
v_int32 int32ToCharSequence(v_int32 value, p_char8 data, v_int32 n);
v_buff_size int32ToCharSequence(v_int32 value, p_char8 data, v_buff_size n);
/**
* Convert 32-bit unsigned integer to it's string representation.
@ -112,7 +112,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @param n - buffer size.
* @return - length of the resultant string.
*/
v_int32 uint32ToCharSequence(v_uint32 value, p_char8 data, v_int32 n);
v_buff_size uint32ToCharSequence(v_uint32 value, p_char8 data, v_buff_size n);
/**
* Convert 64-bit integer to it's string representation.
@ -121,7 +121,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @param n - buffer size.
* @return - length of the resultant string.
*/
v_int32 int64ToCharSequence(v_int64 value, p_char8 data, v_int32 n);
v_buff_size int64ToCharSequence(v_int64 value, p_char8 data, v_buff_size n);
/**
* Convert 64-bit unsigned integer to it's string representation.
@ -130,7 +130,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @param n - buffer size.
* @return - length of the resultant string.
*/
v_int32 uint64ToCharSequence(v_uint64 value, p_char8 data, v_int32 n);
v_buff_size uint64ToCharSequence(v_uint64 value, p_char8 data, v_buff_size n);
/**
* Convert 32-bit integer to it's string representation.
@ -198,7 +198,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @return - length of the resultant string.
*/
template<typename T>
v_int32 primitiveToCharSequence(T value, p_char8 data, v_int32 n, const char *pattern) {
v_buff_size primitiveToCharSequence(T value, p_char8 data, v_buff_size n, const char *pattern) {
return snprintf((char*)data, n, pattern, value);
}
@ -212,7 +212,7 @@ namespace oatpp { namespace utils { namespace conversion {
template<typename T>
oatpp::String primitiveToStr(T value, const char* pattern){
v_char8 buff [100];
v_int32 size = primitiveToCharSequence(value, &buff[0], 100, pattern);
auto size = primitiveToCharSequence(value, &buff[0], 100, pattern);
if(size > 0){
return oatpp::String((const char*)&buff[0], size, true);
}
@ -256,7 +256,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @param n - buffer size.
* @return - length of the resultant string.
*/
v_int32 float32ToCharSequence(v_float32 value, p_char8 data, v_int32 n);
v_buff_size float32ToCharSequence(v_float32 value, p_char8 data, v_buff_size n);
/**
* Convert 64-bit float to it's string representation.
@ -265,7 +265,7 @@ namespace oatpp { namespace utils { namespace conversion {
* @param n - buffer size.
* @return - length of the resultant string.
*/
v_int32 float64ToCharSequence(v_float64 value, p_char8 data, v_int32 n);
v_buff_size float64ToCharSequence(v_float64 value, p_char8 data, v_buff_size n);
/**
* Convert 32-bit float to it's string representation.