Skip to content

Instantly share code, notes, and snippets.

@jan-matejka
Last active August 29, 2015 14:02
Show Gist options
  • Save jan-matejka/92ab03331c9115c8bd8a to your computer and use it in GitHub Desktop.
Save jan-matejka/92ab03331c9115c8bd8a to your computer and use it in GitHub Desktop.
inline
Text Volume::labelTextFmt( bool doing, bool has_label ) const {
if (doing && !has_label)
return _("Clearing label on %1$s")
if (doing && has_label)
return _("Setting label on %1$s to %2$s")
if (!has_label)
return _("Clear label on %1$s")
return _("Set label on %1$s to %2$s")
}
Text Volume::labelText( bool doing ) const {
return sformat(labelTextFmt(doing, !label.empty()), dev.c_str(), label.c_str());
}
labelText doing = sformat (labelTextFmt doing $ empty label) [dev, label]
where
labelTextFmt True False = _("Clearing label on %1$s")
labelTextFmt True True = _("Setting label on %1$s to %2$s")
labeltextFmt False False = _("Clear label on %1$s")
labelTextFmt False True = _("Set label on %1$s to %2$s")
Text Volume::labelText( bool doing ) const {
Text txt, fmt;
// compiler should be able to optimize this away I *guess*
bool has_label = !label.empty()
if (doing && !has_label)
fmt = _("Clearing label on %1$s")
else if(doing && has_label)
fmt = _("Setting label on %1$s to %2$s")
else if(!doing && !has_label)
fmt = _("Clear label on %1$s")
else
fmt = _("Set label on %1$s to %2$s")
return sformat(fmt, dev.c_str(), label.c_str());
}
@roman-neuhauser
Copy link

funny, a2.cpp ends up having more negation than if it had bool has_no_label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment