Skip to content

Commit 23332cb

Browse files
committed
Adding missing json::value::number overloads.
1 parent e850595 commit 23332cb

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

Release/include/cpprest/json.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ namespace json
242242
/// <returns>A JSON number value</returns>
243243
static _ASYNCRTIMP value __cdecl number(int32_t value);
244244

245+
/// <summary>
246+
/// Creates a number value
247+
/// </summary>
248+
/// <param name="value">The C++ value to create a JSON value from</param>
249+
/// <returns>A JSON number value</returns>
250+
static _ASYNCRTIMP value __cdecl number(uint32_t value);
251+
252+
/// <summary>
253+
/// Creates a number value
254+
/// </summary>
255+
/// <param name="value">The C++ value to create a JSON value from</param>
256+
/// <returns>A JSON number value</returns>
257+
static _ASYNCRTIMP value __cdecl number(int64_t value);
258+
259+
/// <summary>
260+
/// Creates a number value
261+
/// </summary>
262+
/// <param name="value">The C++ value to create a JSON value from</param>
263+
/// <returns>A JSON number value</returns>
264+
static _ASYNCRTIMP value __cdecl number(uint64_t value);
265+
245266
/// <summary>
246267
/// Creates a Boolean value
247268
/// </summary>

Release/src/json/json.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ web::json::value web::json::value::number(int32_t value)
175175
return web::json::value(value);
176176
}
177177

178+
web::json::value web::json::value::number(uint32_t value)
179+
{
180+
return web::json::value(value);
181+
}
182+
183+
web::json::value web::json::value::number(int64_t value)
184+
{
185+
return web::json::value(value);
186+
}
187+
188+
web::json::value web::json::value::number(uint64_t value)
189+
{
190+
return web::json::value(value);
191+
}
192+
178193
web::json::value web::json::value::boolean(bool value)
179194
{
180195
return web::json::value(value);

Release/tests/functional/json/json_numbers_tests.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ void test_int64(int64_t number)
6161
json::value num = json::value::parse(ss);
6262
VERIFY_ARE_EQUAL(number, num.as_number().to_int64());
6363
VERIFY_IS_TRUE(num.is_integer());
64+
num = json::value::number(number);
65+
VERIFY_ARE_EQUAL(number, num.as_number().to_int64());
66+
VERIFY_IS_TRUE(num.is_integer());
6467

65-
// Check that the number is convertable to signed int64
68+
// Check that the number is convertible to signed int64
6669
VERIFY_IS_TRUE(num.as_number().is_int64());
6770

6871
// Check for other integral conversions
@@ -103,8 +106,11 @@ void test_int64(uint64_t number)
103106
json::value num = json::value::parse(ss);
104107
VERIFY_ARE_EQUAL(number, num.as_number().to_uint64());
105108
VERIFY_IS_TRUE(num.is_integer());
109+
num = json::value::number(number);
110+
VERIFY_ARE_EQUAL(number, num.as_number().to_uint64());
111+
VERIFY_IS_TRUE(num.is_integer());
106112

107-
// Check that the number is convertable to unsigned int64
113+
// Check that the number is convertible to unsigned int64
108114
VERIFY_IS_TRUE(num.as_number().is_uint64());
109115

110116
// Check for other integral conversions

0 commit comments

Comments
 (0)