all repos — fluxbox @ a6ed9498cc0e31b0134ecd47de7d5383a062e535

custom fork of the fluxbox windowmanager

code cleanup

* moved code from public API to internals
* avoid code duplication ( while(!m_terms.empty()) ...)
* cosmetic '(*it)->' vs 'term.'
Mathias Gumz akira at fluxbox dot org
commit

a6ed9498cc0e31b0134ecd47de7d5383a062e535

parent

882a50fe1d4930b156965c54d9b66ecb27b4c9b2

2 files changed, 57 insertions(+), 55 deletions(-)

jump to
M src/ClientPattern.ccsrc/ClientPattern.cc

@@ -32,6 +32,7 @@

#include "FbTk/StringUtil.hh" #include "FbTk/App.hh" #include "FbTk/stringstream.hh" +#include "FbTk/STLUtil.hh" // use GNU extensions #ifndef _GNU_SOURCE

@@ -120,6 +121,28 @@

} // end of anonymous namespace +/** + * This is the type of the actual pattern we want to match against + * We have a "term" in the whole expression which is the full pattern + * we also need to keep track of the uncompiled regular expression + * for final output + */ +struct ClientPattern::Term { + + Term(const FbTk::FbString& _regstr, WinProperty _prop, bool _negate) : + orig(_regstr), + regexp(_regstr, true), + prop(_prop), + negate(_negate) { + + } + + FbTk::FbString orig; + FbTk::RegExp regexp; + WinProperty prop; + bool negate; +}; + ClientPattern::ClientPattern(): m_matchlimit(0), m_nummatches(0) {}

@@ -202,8 +225,7 @@ err = FbTk::StringUtil::getStringBetween(number,

str+pos, '{', '}'); if (err > 0) { - FbTk_istringstream iss(number.c_str()); - iss >> m_matchlimit; + FbTk::StringUtil::extractNumber(number, m_matchlimit); pos+=err; } // we don't care if there isn't one

@@ -219,21 +241,12 @@ }

} if (had_error) { - // delete all the terms - while (!m_terms.empty()) { - Term * term = m_terms.back(); - delete term; - m_terms.pop_back(); - } + FbTk::STLUtil::destroyAndClear(m_terms); } } ClientPattern::~ClientPattern() { - // delete all the terms - while (!m_terms.empty()) { - delete m_terms.back(); - m_terms.pop_back(); - } + FbTk::STLUtil::destroyAndClear(m_terms); } // return a string representation of this pattern

@@ -268,25 +281,23 @@ // changing to OR would require minor modifications in this function only

Terms::const_iterator it = m_terms.begin(); Terms::const_iterator it_end = m_terms.end(); for (; it != it_end; ++it) { - if ((*it)->orig == "[current]") { + const Term& term = *(*it); + if (term.orig == "[current]") { WinClient *focused = FocusControl::focusedWindow(); - if ((*it)->prop == WORKSPACE) { - if (!(*it)->negate ^ (getProperty((*it)->prop, win) == FbTk::StringUtil::number2String(win.screen().currentWorkspaceID()))) + if (term.prop == WORKSPACE) { + if (!term.negate ^ (getProperty(term.prop, win) == FbTk::StringUtil::number2String(win.screen().currentWorkspaceID()))) return false; - } else if ((*it)->prop == WORKSPACENAME) { + } else if (term.prop == WORKSPACENAME) { const Workspace *w = win.screen().currentWorkspace(); - if (!w || (!(*it)->negate ^ - (getProperty((*it)->prop, win) == w->name()))) + if (!w || (!term.negate ^ (getProperty(term.prop, win) == w->name()))) return false; - } else if (!focused || (!(*it)->negate ^ - (getProperty((*it)->prop, win) == - getProperty((*it)->prop, *focused)))) + } else if (!focused || (!term.negate ^ (getProperty(term.prop, win) == getProperty(term.prop, *focused)))) return false; - } else if ((*it)->prop == HEAD && (*it)->orig == "[mouse]") { - if (!(*it)->negate ^ (getProperty((*it)->prop, win) == FbTk::StringUtil::number2String(win.screen().getCurrHead()))) + } else if (term.prop == HEAD && term.orig == "[mouse]") { + if (!term.negate ^ (getProperty(term.prop, win) == FbTk::StringUtil::number2String(win.screen().getCurrHead()))) return false; - } else if (!(*it)->negate ^ (*it)->regexp.match(getProperty((*it)->prop, win))) + } else if (!term.negate ^ term.regexp.match(getProperty(term.prop, win))) return false; } return true;

@@ -315,19 +326,22 @@

// add an expression to match against // The first argument is a regular expression, the second is the member // function that we wish to match against. -bool ClientPattern::addTerm(const string &str, WinProperty prop, bool negate) { +bool ClientPattern::addTerm(const FbTk::FbString &str, WinProperty prop, bool negate) { - Term *term = new Term(str, true); - term->orig = str; - term->prop = prop; - term->negate = negate; + bool rc = false; + Term* term = new Term(str, prop, negate); - if (term->regexp.error()) { + if (!term) + return rc; + + if (!term->regexp.error()) { + m_terms.push_back(term); + rc = true; + } else { delete term; - return false; } - m_terms.push_back(term); - return true; + + return rc; } FbTk::FbString ClientPattern::getProperty(WinProperty prop, const Focusable &client) {
M src/ClientPattern.hhsrc/ClientPattern.hh

@@ -26,6 +26,7 @@ #define CLIENTPATTERN_HH

#include "FbTk/RegExp.hh" #include "FbTk/NotCopyable.hh" +#include "FbTk/FbString.hh" #include <list>

@@ -48,7 +49,7 @@

~ClientPattern(); /// @return a string representation of this pattern - std::string toString() const; + FbTk::FbString toString() const; enum WinProperty { TITLE = 0, CLASS, NAME, ROLE, TRANSIENT,

@@ -71,7 +72,7 @@ * @param str is a regular expression

* @param prop is the member function that we wish to match against * @return false if the regexp wasn't valid */ - bool addTerm(const std::string &str, WinProperty prop, bool negate = false); + bool addTerm(const FbTk::FbString &str, WinProperty prop, bool negate = false); void addMatch() { ++m_nummatches; } void removeMatch() { --m_nummatches; }

@@ -86,29 +87,16 @@ * the column of the error is stored in m_matchlimit

*/ int error() const { return m_terms.empty() ? 1 : 0; } - static std::string getProperty(WinProperty prop, const Focusable &client); + static FbTk::FbString getProperty(WinProperty prop, const Focusable &client); private: - /** - * This is the type of the actual pattern we want to match against - * We have a "term" in the whole expression which is the full pattern - * we also need to keep track of the uncompiled regular expression - * for final output - */ - struct Term { - Term(const std::string &regstr, bool full_match) :regexp(regstr, full_match){}; - std::string orig; - FbTk::RegExp regexp; - WinProperty prop; - bool negate; - }; - - + struct Term; + friend struct Term; typedef std::list<Term *> Terms; - Terms m_terms; ///< our pattern is made up of a sequence of terms currently we "and" them all - - int m_matchlimit, m_nummatches; + Terms m_terms; ///< our pattern is made up of a sequence of terms, currently we "and" them all + int m_matchlimit; + int m_nummatches; }; #endif // CLIENTPATTERN_HH