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

Use std::string instead of std::ostringstream #36300

Merged
merged 3 commits into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
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
109 changes: 54 additions & 55 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <cmath>
#include <iterator>
#include <memory>
Expand Down Expand Up @@ -4086,8 +4085,8 @@ hp_part Character::body_window( const std::string &menu_header,
e.allowed = false;
}

std::stringstream msg;
std::stringstream desc;
std::string msg;
std::string desc;
bool bleeding = has_effect( effect_bleed, e.bp );
bool bitten = has_effect( effect_bite, e.bp );
bool infected = has_effect( effect_infected, e.bp );
Expand All @@ -4106,90 +4105,90 @@ hp_part Character::body_window( const std::string &menu_header,
int new_d_power = static_cast<int>( std::floor( disinfectant_power ) );

const auto &aligned_name = std::string( max_bp_name_len - utf8_width( e.name ), ' ' ) + e.name;
msg << colorize( aligned_name, all_state_col ) << " " << hp_str( current_hp, maximal_hp );
msg += colorize( aligned_name, all_state_col ) + " " + hp_str( current_hp, maximal_hp );

if( limb_is_broken ) {
desc << colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) << "\n";
desc += colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) + "\n";
}

// BLEEDING block
if( bleeding ) {
desc << colorize( string_format( "%s: %s", get_effect( effect_bleed, e.bp ).get_speed_name(),
get_effect( effect_bleed, e.bp ).disp_short_desc() ), c_red ) << "\n";
desc += colorize( string_format( "%s: %s", get_effect( effect_bleed, e.bp ).get_speed_name(),
get_effect( effect_bleed, e.bp ).disp_short_desc() ), c_red ) + "\n";
if( bleed > 0.0f ) {
desc << colorize( string_format( _( "Chance to stop: %d %%" ),
static_cast<int>( bleed * 100 ) ), c_light_green ) << "\n";
desc += colorize( string_format( _( "Chance to stop: %d %%" ),
static_cast<int>( bleed * 100 ) ), c_light_green ) + "\n";
} else {
desc << colorize( _( "This will not stop the bleeding." ),
c_yellow ) << "\n";
desc += colorize( _( "This will not stop the bleeding." ),
c_yellow ) + "\n";
}
}
// BANDAGE block
if( bandaged ) {
desc << string_format( _( "Bandaged [%s]" ), texitify_healing_power( b_power ) ) << "\n";
desc += string_format( _( "Bandaged [%s]" ), texitify_healing_power( b_power ) ) + "\n";
if( new_b_power > b_power ) {
desc << colorize( string_format( _( "Expected quality improvement: %s" ),
texitify_healing_power( new_b_power ) ), c_light_green ) << "\n";
desc += colorize( string_format( _( "Expected quality improvement: %s" ),
texitify_healing_power( new_b_power ) ), c_light_green ) + "\n";
} else if( new_b_power > 0 ) {
desc << colorize( _( "You don't expect any improvement from using this." ), c_yellow ) << "\n";
desc += colorize( _( "You don't expect any improvement from using this." ), c_yellow ) + "\n";
}
} else if( new_b_power > 0 && e.allowed ) {
desc << colorize( string_format( _( "Expected bandage quality: %s" ),
texitify_healing_power( new_b_power ) ), c_light_green ) << "\n";
desc += colorize( string_format( _( "Expected bandage quality: %s" ),
texitify_healing_power( new_b_power ) ), c_light_green ) + "\n";
}
// BITTEN block
if( bitten ) {
desc << colorize( string_format( "%s: ", get_effect( effect_bite,
desc += colorize( string_format( "%s: ", get_effect( effect_bite,
e.bp ).get_speed_name() ), c_red );
desc << colorize( _( "It has a deep bite wound that needs cleaning." ), c_red ) << "\n";
desc += colorize( _( "It has a deep bite wound that needs cleaning." ), c_red ) + "\n";
if( bite > 0 ) {
desc << colorize( string_format( _( "Chance to clean and disinfect: %d %%" ),
static_cast<int>( bite * 100 ) ), c_light_green ) << "\n";
desc += colorize( string_format( _( "Chance to clean and disinfect: %d %%" ),
static_cast<int>( bite * 100 ) ), c_light_green ) + "\n";
} else {
desc << colorize( _( "This will not help in cleaning this wound." ), c_yellow ) << "\n";
desc += colorize( _( "This will not help in cleaning this wound." ), c_yellow ) + "\n";
}
}
// INFECTED block
if( infected ) {
desc << colorize( string_format( "%s: ", get_effect( effect_infected,
desc += colorize( string_format( "%s: ", get_effect( effect_infected,
e.bp ).get_speed_name() ), c_red );
desc << colorize( _( "It has a deep wound that looks infected. Antibiotics might be required." ),
c_red ) << "\n";
desc += colorize( _( "It has a deep wound that looks infected. Antibiotics might be required." ),
c_red ) + "\n";
if( infect > 0 ) {
desc << colorize( string_format( _( "Chance to heal infection: %d %%" ),
static_cast<int>( infect * 100 ) ), c_light_green ) << "\n";
desc += colorize( string_format( _( "Chance to heal infection: %d %%" ),
static_cast<int>( infect * 100 ) ), c_light_green ) + "\n";
} else {
desc << colorize( _( "This will not help in healing infection." ), c_yellow ) << "\n";
desc += colorize( _( "This will not help in healing infection." ), c_yellow ) + "\n";
}
}
// DISINFECTANT (general) block
if( disinfected ) {
desc << string_format( _( "Disinfected [%s]" ),
texitify_healing_power( d_power ) ) << "\n";
desc += string_format( _( "Disinfected [%s]" ),
texitify_healing_power( d_power ) ) + "\n";
if( new_d_power > d_power ) {
desc << colorize( string_format( _( "Expected quality improvement: %s" ),
texitify_healing_power( new_d_power ) ), c_light_green ) << "\n";
desc += colorize( string_format( _( "Expected quality improvement: %s" ),
texitify_healing_power( new_d_power ) ), c_light_green ) + "\n";
} else if( new_d_power > 0 ) {
desc << colorize( _( "You don't expect any improvement from using this." ),
c_yellow ) << "\n";
desc += colorize( _( "You don't expect any improvement from using this." ),
c_yellow ) + "\n";
}
} else if( new_d_power > 0 && e.allowed ) {
desc << colorize( string_format(
desc += colorize( string_format(
_( "Expected disinfection quality: %s" ),
texitify_healing_power( new_d_power ) ), c_light_green ) << "\n";
texitify_healing_power( new_d_power ) ), c_light_green ) + "\n";
}
// END of blocks

if( ( !e.allowed && !limb_is_broken ) || ( show_all && current_hp == maximal_hp &&
!limb_is_broken && !bitten && !infected && !bleeding ) ) {
desc << colorize( _( "Healthy." ), c_green ) << "\n";
desc += colorize( _( "Healthy." ), c_green ) + "\n";
}
if( !e.allowed ) {
desc << colorize( _( "You don't expect any effect from using this." ), c_yellow );
desc += colorize( _( "You don't expect any effect from using this." ), c_yellow );
} else {
is_valid_choice = true;
}
bmenu.addentry_desc( i, e.allowed, MENU_AUTOASSIGN, msg.str(), desc.str() );
bmenu.addentry_desc( i, e.allowed, MENU_AUTOASSIGN, msg, desc );
}

if( !is_valid_choice ) { // no body part can be chosen for this item/effect
Expand Down Expand Up @@ -4797,15 +4796,15 @@ std::vector<body_part> Character::get_all_body_parts( bool only_main ) const

std::string Character::extended_description() const
{
std::ostringstream ss;
std::string ss;
if( is_player() ) {
// <bad>This is me, <player_name>.</bad>
ss << string_format( _( "This is you - %s." ), name );
ss += string_format( _( "This is you - %s." ), name );
} else {
ss << string_format( _( "This is %s." ), name );
ss += string_format( _( "This is %s." ), name );
}

ss << std::endl << "--" << std::endl;
ss += "\n--\n";

const auto &bps = get_all_body_parts( true );
// Find length of bp names, to align
Expand All @@ -4827,29 +4826,29 @@ std::string Character::extended_description() const
nc_color name_color = state_col;
auto hp_bar = get_hp_bar( current_hp, maximal_hp, false );

ss << colorize( left_justify( bp_heading, longest ), name_color );
ss << colorize( hp_bar.first, hp_bar.second );
ss += colorize( left_justify( bp_heading, longest ), name_color );
ss += colorize( hp_bar.first, hp_bar.second );
// Trailing bars. UGLY!
// TODO: Integrate into get_hp_bar somehow
ss << colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white );
ss << std::endl;
ss += colorize( std::string( 5 - utf8_width( hp_bar.first ), '.' ), c_white );
ss += "\n";
}

ss << "--" << std::endl;
ss << _( "Wielding:" ) << " ";
ss += "--\n";
ss += _( "Wielding:" ) + std::string( " " );
if( weapon.is_null() ) {
ss << _( "Nothing" );
ss += _( "Nothing" );
} else {
ss << weapon.tname();
ss += weapon.tname();
}

ss << std::endl;
ss << _( "Wearing:" ) << " ";
ss << enumerate_as_string( worn.begin(), worn.end(), []( const item & it ) {
ss += "\n";
ss += _( "Wearing:" ) + std::string( " " );
ss += enumerate_as_string( worn.begin(), worn.end(), []( const item & it ) {
return it.tname();
} );

return replace_colors( ss.str() );
return replace_colors( ss );
}

social_modifiers Character::get_mutation_social_mods() const
Expand Down
Loading