Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve item volume loading #69238

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
return true;
}

bool assign( const JsonObject &jo, const std::string &name, units::volume &val, bool strict,

Check failure on line 33 in src/assign.cpp

View workflow job for this annotation

GitHub Actions / build (src)

Parameter 'name' of 'assign' can be std::string_view. [cata-use-string_view,-warnings-as-errors]
const units::volume lo, const units::volume hi )
{
const auto parse = [&name]( const JsonObject & obj, units::volume & out ) {
Expand All @@ -40,21 +40,7 @@
}

if( obj.has_string( name ) ) {
units::volume::value_type tmp;
std::string suffix;
std::istringstream str( obj.get_string( name ) );
str.imbue( std::locale::classic() );
str >> tmp >> suffix;
if( str.peek() != std::istringstream::traits_type::eof() ) {
obj.throw_error_at( name, "syntax error when specifying volume" );
}
if( suffix == "ml" ) {
out = units::from_milliliter( tmp );
} else if( suffix == "L" ) {
out = units::from_milliliter( tmp * 1000 );
} else {
obj.throw_error_at( name, "unrecognized volumetric unit" );
}
out = read_from_json_string<units::volume>( obj.get_member( name ), units::volume_units );
return true;
}

Expand Down
Loading