1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Define TranslatableString::Strip()

This commit is contained in:
Paul Licameli
2019-12-15 11:56:01 -05:00
parent 911e278e60
commit f16709945b
3 changed files with 44 additions and 1 deletions

View File

@@ -312,6 +312,37 @@ bool TranslatableString::IsVerbatim() const
return DoGetContext( mFormatter ) == NullContextName;
}
TranslatableString &TranslatableString::Strip( unsigned codes ) &
{
auto prevFormatter = mFormatter;
mFormatter = [prevFormatter, codes]
( const wxString & str, TranslatableString::Request request ) -> wxString {
switch ( request ) {
case Request::Context:
return TranslatableString::DoGetContext( prevFormatter );
case Request::Format:
case Request::DebugFormat:
default: {
bool debug = request == Request::DebugFormat;
auto result =
TranslatableString::DoSubstitute( prevFormatter, str, debug );
if ( codes & MenuCodes )
result = wxStripMenuCodes( result );
if ( codes & Ellipses ) {
if (result.EndsWith(wxT("...")))
result = result.Left( result.length() - 3 );
// Also check for the single-character Unicode ellipsis
else if (result.EndsWith(wxT("\u2026")))
result = result.Left( result.length() - 1 );
}
return result;
}
}
};
return *this;
}
wxString TranslatableString::DoGetContext( const Formatter &formatter )
{
return formatter ? formatter( {}, Request::Context ) : wxString{};