Skip to content

Commit e0277cd

Browse files
committed
Reader for string unicode symbol values
There's a reader for symbol values that are stored as unicode codepoints, but some types, particularly monsters, use a string to store their symbol value. Add a reader that supports this, by converting the codepoint from the codepoint reader to a string.
1 parent 91c3336 commit e0277cd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/generic_factory.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ bool unicode_codepoint_from_symbol_reader( const JsonObject &jo,
7878
return true;
7979
}
8080

81+
bool unicode_symbol_reader( const JsonObject &jo, const std::string_view member_name,
82+
std::string &member, bool was_loaded )
83+
{
84+
uint32_t codepoint;
85+
bool read = unicode_codepoint_from_symbol_reader( jo, member_name, codepoint, was_loaded );
86+
if( read ) {
87+
member = utf32_to_utf8( codepoint );
88+
return true;
89+
}
90+
return false;
91+
}
92+
8193
float read_proportional_entry( const JsonObject &jo, std::string_view key )
8294
{
8395
if( jo.has_float( key ) ) {

src/generic_factory.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,12 @@ bool one_char_symbol_reader( const JsonObject &jo, std::string_view member_name,
960960
bool unicode_codepoint_from_symbol_reader(
961961
const JsonObject &jo, std::string_view member_name, uint32_t &member, bool );
962962

963+
/**
964+
* unicode_codepoint_from_symbol_reader, but with a string instead of a codepoint
965+
*/
966+
bool unicode_symbol_reader( const JsonObject &jo, std::string_view member_name, std::string &member,
967+
bool was_loaded );
968+
963969
//Reads a standard single-float "proportional" entry
964970
float read_proportional_entry( const JsonObject &jo, std::string_view key );
965971

0 commit comments

Comments
 (0)