Skip to content

Commit f1cda01

Browse files
committed
added cpp20 mode and fixed a output format bug
1 parent 070926f commit f1cda01

16 files changed

Lines changed: 71 additions & 45 deletions

include/json_to_cpp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace daw::json_to_cpp {
3838
std::vector<std::vector<std::string>> kv_paths;
3939
bool hide_null_only;
4040
bool use_string_view;
41+
bool has_cpp20;
4142

4243
std::ostream &header_file( );
4344
std::ostream &cpp_file( );

include/ti_array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace daw::json_to_cpp::types {
6060
ti_array &operator=( ti_array const &rhs );
6161

6262
std::string name( ) const;
63-
std::string json_name( daw::string_view member_name ) const;
63+
std::string json_name( daw::string_view member_name, bool use_cpp20 ) const;
6464
std::string array_member_info( ) const;
6565
};
6666
} // namespace daw::json_to_cpp::types

include/ti_base.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <variant>
2828

2929
#include <daw/cpp_17.h>
30+
#include <daw/daw_string_view.h>
3031

3132
namespace daw::json_to_cpp::types::impl {
3233
inline constexpr size_t ti_null_pos = 0;
@@ -62,4 +63,11 @@ namespace daw::json_to_cpp::types::impl {
6263
}
6364
return ( std::is_same_v<Args0, Args1> and ... );
6465
}
66+
67+
inline std::string format_member_name( daw::string_view name, bool use_cpp20 ) {
68+
if( use_cpp20 ) {
69+
return "\"" + name + "\"";
70+
}
71+
return name;
72+
}
6573
} // namespace daw::json_to_cpp::types::impl

include/ti_boolean.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ namespace daw::json_to_cpp::types {
4545
return "json_bool<no_name>";
4646
}
4747

48-
inline static std::string
49-
json_name( daw::string_view member_name ) noexcept {
50-
return "json_bool<" + member_name + ">";
48+
inline static std::string json_name( daw::string_view member_name,
49+
bool use_cpp20 ) noexcept {
50+
return "json_bool<" + impl::format_member_name( member_name, use_cpp20 ) +
51+
">";
5152
}
5253
};
5354
} // namespace daw::json_to_cpp::types

include/ti_integral.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <daw/daw_string_view.h>
2929
#include <daw/json/daw_json_value_t.h>
3030

31+
#include "ti_base.h"
32+
3133
namespace daw::json_to_cpp::types {
3234
struct ti_integral {
3335
bool is_optional = false;
@@ -45,8 +47,8 @@ namespace daw::json_to_cpp::types {
4547
return "json_number<no_name, int64_t>";
4648
}
4749

48-
inline static std::string json_name( daw::string_view member_name ) noexcept {
49-
return "json_number<" + member_name + ", int64_t>";
50+
inline static std::string json_name( daw::string_view member_name, bool use_cpp20 ) noexcept {
51+
return "json_number<" + impl::format_member_name( member_name, use_cpp20 ) + ", int64_t>";
5052
}
5153
};
5254
} // namespace daw::json_to_cpp::types

include/ti_kv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ namespace daw::json_to_cpp::types {
6565
std::string name( ) const;
6666
std::string array_member_info( ) const;
6767

68-
std::string json_name( daw::string_view member_name ) const;
68+
std::string json_name( daw::string_view member_name, bool use_cpp20 ) const;
6969
};
7070
} // namespace daw::json_to_cpp::types

include/ti_null.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ namespace daw::json_to_cpp::types {
4747
return "json_custom<no_name>";
4848
}
4949

50-
static inline std::string json_name( daw::string_view member_name ) noexcept {
51-
return "json_custom<" + member_name + ">";
50+
static inline std::string json_name( daw::string_view member_name, bool use_cpp20 ) noexcept {
51+
return "json_custom<" + impl::format_member_name( member_name, use_cpp20 ) + ">";
5252
}
5353
};
5454
} // namespace daw::json_to_cpp::types

include/ti_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace daw::json_to_cpp::types {
6262
ti_object &operator=( ti_object const &rhs );
6363

6464
std::string name( ) const;
65-
std::string json_name( daw::string_view member_name ) const;
65+
std::string json_name( daw::string_view member_name, bool use_cpp20 ) const;
6666
std::string array_member_info( ) const;
6767
};
6868
} // namespace daw::json_to_cpp::types

include/ti_real.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <daw/daw_string_view.h>
2929
#include <daw/json/daw_json_value_t.h>
3030

31+
#include "ti_base.h"
32+
3133
namespace daw::json_to_cpp::types {
3234
struct ti_real {
3335
bool is_optional = false;
@@ -45,8 +47,8 @@ namespace daw::json_to_cpp::types {
4547
return "json_number<no_name>";
4648
}
4749

48-
inline static std::string json_name( daw::string_view member_name ) noexcept {
49-
return "json_number<" + member_name + ">";
50+
inline static std::string json_name( daw::string_view member_name, bool use_cpp20 ) noexcept {
51+
return "json_number<" + impl::format_member_name( member_name, use_cpp20 ) + ">";
5052
}
5153
};
5254
} // namespace daw::json_to_cpp::types

include/ti_string.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <daw/daw_string_view.h>
2929
#include <daw/json/daw_json_value_t.h>
3030

31+
#include "ti_base.h"
32+
3133
namespace daw::json_to_cpp::types {
3234
class ti_string {
3335
bool m_use_string_view;
@@ -54,11 +56,11 @@ namespace daw::json_to_cpp::types {
5456
return "json_string<no_name>";
5557
}
5658

57-
inline std::string json_name( daw::string_view member_name ) const noexcept {
59+
inline std::string json_name( daw::string_view member_name, bool use_cpp20 ) const noexcept {
5860
if( m_use_string_view ) {
59-
return "json_string<" + member_name + ", std::string_view>";
61+
return "json_string<" + impl::format_member_name( member_name, use_cpp20 ) + ", std::string_view>";
6062
}
61-
return "json_string<" + member_name + ">";
63+
return "json_string<" + impl::format_member_name( member_name, use_cpp20 ) + ">";
6264
}
6365
};
6466
} // namespace daw::json_to_cpp::types

0 commit comments

Comments
 (0)