Skip to content

Commit

Permalink
redefine typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
Bwar committed Aug 29, 2020
1 parent f11e0ea commit 9312017
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 61 deletions.
55 changes: 7 additions & 48 deletions CJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
******************************************************************************/

#include "CJsonObject.hpp"
#include <sstream>

#ifdef _WIN32
#define snprintf _snprintf_s
Expand Down Expand Up @@ -307,30 +308,9 @@ std::string CJsonObject::operator()(const std::string& strKey) const
}
else if (pJsonStruct->type == cJSON_Int)
{
char szNumber[128] = {0};
if (pJsonStruct->sign == -1)
{
if (pJsonStruct->valueint <= (int64)INT_MAX && (int64)pJsonStruct->valueint >= (int64)INT_MIN)
{
snprintf(szNumber, sizeof(szNumber), "%d", (int32)pJsonStruct->valueint);
}
else
{
snprintf(szNumber, sizeof(szNumber), "%lld", (int64)pJsonStruct->valueint);
}
}
else
{
if ((uint64)pJsonStruct->valueint <= (uint64)UINT_MAX)
{
snprintf(szNumber, sizeof(szNumber), "%u", (uint32)pJsonStruct->valueint);
}
else
{
snprintf(szNumber, sizeof(szNumber), "%llu", pJsonStruct->valueint);
}
}
return(std::string(szNumber));
std::ostringstream ossNumber;
ossNumber << pJsonStruct->valueint;
return(ossNumber.str());
}
else if (pJsonStruct->type == cJSON_Double)
{
Expand Down Expand Up @@ -383,30 +363,9 @@ std::string CJsonObject::operator()(unsigned int uiWhich) const
}
else if (pJsonStruct->type == cJSON_Int)
{
char szNumber[128] = {0};
if (pJsonStruct->sign == -1)
{
if (pJsonStruct->valueint <= (int64)INT_MAX && (int64)pJsonStruct->valueint >= (int64)INT_MIN)
{
snprintf(szNumber, sizeof(szNumber), "%d", (int32)pJsonStruct->valueint);
}
else
{
snprintf(szNumber, sizeof(szNumber), "%lld", (int64)pJsonStruct->valueint);
}
}
else
{
if ((uint64)pJsonStruct->valueint <= (uint64)UINT_MAX)
{
snprintf(szNumber, sizeof(szNumber), "%u", (uint32)pJsonStruct->valueint);
}
else
{
snprintf(szNumber, sizeof(szNumber), "%llu", pJsonStruct->valueint);
}
}
return(std::string(szNumber));
std::ostringstream ossNumber;
ossNumber << pJsonStruct->valueint;
return(ossNumber.str());
}
else if (pJsonStruct->type == cJSON_Double)
{
Expand Down
4 changes: 2 additions & 2 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static char *print_int(cJSON *item)
}
else
{
sprintf(str, "%lld", (int64)item->valueint);
sprintf(str, "%ld", (int64)item->valueint);
}
}
else
Expand All @@ -204,7 +204,7 @@ static char *print_int(cJSON *item)
}
else
{
sprintf(str, "%llu", item->valueint);
sprintf(str, "%lu", item->valueint);
}
}
}
Expand Down
15 changes: 4 additions & 11 deletions cJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@

#include <stdint.h>

typedef int int32;
typedef unsigned int uint32;
#ifndef _WIN32
#if __WORDSIZE == 64
typedef long int64;
typedef unsigned long uint64;
#endif
#else
typedef long long int64;
typedef unsigned long long uint64;
#endif
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;


#ifdef __cplusplus
Expand Down

0 comments on commit 9312017

Please sign in to comment.