Skip to content

Commit

Permalink
Do not remove angle brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox authored and satheon49 committed Aug 14, 2021
1 parent c7a9ce0 commit 2da59bf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,7 @@ ret_val<bool> Character::can_wear( const item &it, bool with_equip_change ) cons
if( this_restricts_only_one || i.has_flag( flag_id( "ONE_PER_LAYER" ) ) ) {
cata::optional<side> overlaps = it.covers_overlaps( i );
if( overlaps && sidedness_conflicts( *overlaps ) ) {
return ret_val<bool>::make_failure( _( " %1$s conflicts with %2$s!" ), it.tname(), i.tname() );
return ret_val<bool>::make_failure( _( "%1$s conflicts with %2$s!" ), it.tname(), i.tname() );
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class wear_inventory_preset: public armor_inventory_preset
const auto ret = you.can_wear( *loc );

if( !ret.success() ) {
return trim_punctuation_marks( ret.str() );
return trim_trailing_punctuations( ret.str() );
}

return std::string();
Expand Down Expand Up @@ -378,7 +378,7 @@ class take_off_inventory_preset: public armor_inventory_preset
const ret_val<bool> ret = you.can_takeoff( *loc );

if( !ret.success() ) {
return trim_punctuation_marks( ret.str() );
return trim_trailing_punctuations( ret.str() );
}

return std::string();
Expand Down Expand Up @@ -1104,7 +1104,7 @@ class activatable_inventory_preset : public pickup_inventory_preset
if( uses.size() == 1 ) {
const auto ret = uses.begin()->second.can_call( you, it, false, you.pos() );
if( !ret.success() ) {
return trim_punctuation_marks( ret.str() );
return trim_trailing_punctuations( ret.str() );
}
}

Expand Down Expand Up @@ -1512,7 +1512,7 @@ class weapon_inventory_preset: public inventory_selector_preset
const auto ret = you.can_wield( *loc );

if( !ret.success() ) {
return trim_punctuation_marks( ret.str() );
return trim_trailing_punctuations( ret.str() );
}

return std::string();
Expand Down Expand Up @@ -1617,7 +1617,7 @@ class saw_barrel_inventory_preset: public weapon_inventory_preset
const auto ret = actor.can_use_on( you, tool, *loc );

if( !ret.success() ) {
return trim_punctuation_marks( ret.str() );
return trim_trailing_punctuations( ret.str() );
}

return std::string();
Expand Down
16 changes: 13 additions & 3 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,17 +1133,27 @@ std::string trim( const std::string &s, Prep prep )
} ).base() );
}

template<typename Prep>
std::string trim_trailing( const std::string &s, Prep prep )
{
return std::string( s.begin(), std::find_if_not(
s.rbegin(), s.rend(), [&prep]( int c ) {
return prep( c );
} ).base() );
}

std::string trim( const std::string &s )
{
return trim( s, []( int c ) {
return isspace( c );
} );
}

std::string trim_punctuation_marks( const std::string &s )
std::string trim_trailing_punctuations( const std::string &s )
{
return trim( s, []( int c ) {
return ispunct( c );
return trim_trailing( s, []( int c ) {
// '<' and '>' are used for tags and should not be removed
return c == '.' || c == '!';
} );
}

Expand Down
4 changes: 2 additions & 2 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ int special_symbol( int sym );

// Remove spaces from the start and the end of a string.
std::string trim( const std::string &s );
// Removes punctuation marks from the start and the end of a string.
std::string trim_punctuation_marks( const std::string &s );
// Removes trailing periods and exclamation marks.
std::string trim_trailing_punctuations( const std::string &s );
// Converts the string to upper case.
std::string to_upper_case( const std::string &s );

Expand Down

0 comments on commit 2da59bf

Please sign in to comment.