Add Google cpplint & lint one class

This commit is contained in:
John Maguire 2013-07-19 15:37:56 +02:00
parent 7238916359
commit f166954495
4 changed files with 4084 additions and 40 deletions

4
debian/copyright vendored
View File

@ -61,6 +61,10 @@ Files: 3rdparty/gmock/*
Copyright: 2008, Google Inc.
License: BSD-Google
Files: dist/cpplint.py
Copyright: 2009, Google Inc.
License: BSD-Google
Files: 3rdparty/gmock/scripts/generator/*
Copyright: 2007, Neal Norwitz
2007, Google Inc.

4024
dist/cpplint.py vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -15,13 +15,14 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "organiseformat.h"
#include "core/timeconstants.h"
#include "core/organiseformat.h"
#include <QApplication>
#include <QPalette>
#include <QUrl>
#include "core/timeconstants.h"
const char* OrganiseFormat::kTagPattern = "\\%([a-zA-Z]*)";
const char* OrganiseFormat::kBlockPattern = "\\{([^{}]+)\\}";
const QStringList OrganiseFormat::kKnownTags = QStringList()
@ -32,22 +33,28 @@ const QStringList OrganiseFormat::kKnownTags = QStringList()
// From http://en.wikipedia.org/wiki/8.3_filename#Directory_table
const char* OrganiseFormat::kInvalidFatCharacters = "\"*/\\:<>?|";
const int OrganiseFormat::kInvalidFatCharactersCount = strlen(OrganiseFormat::kInvalidFatCharacters);
const int OrganiseFormat::kInvalidFatCharactersCount =
strlen(OrganiseFormat::kInvalidFatCharacters);
const QRgb OrganiseFormat::SyntaxHighlighter::kValidTagColorLight = qRgb(64, 64, 255);
const QRgb OrganiseFormat::SyntaxHighlighter::kInvalidTagColorLight = qRgb(255, 64, 64);
const QRgb OrganiseFormat::SyntaxHighlighter::kBlockColorLight = qRgb(230, 230, 230);
const QRgb OrganiseFormat::SyntaxHighlighter::kValidTagColorLight =
qRgb(64, 64, 255);
const QRgb OrganiseFormat::SyntaxHighlighter::kInvalidTagColorLight =
qRgb(255, 64, 64);
const QRgb OrganiseFormat::SyntaxHighlighter::kBlockColorLight =
qRgb(230, 230, 230);
const QRgb OrganiseFormat::SyntaxHighlighter::kValidTagColorDark = qRgb(128, 128, 255);
const QRgb OrganiseFormat::SyntaxHighlighter::kInvalidTagColorDark = qRgb(255, 128, 128);
const QRgb OrganiseFormat::SyntaxHighlighter::kBlockColorDark = qRgb(64, 64, 64);
const QRgb OrganiseFormat::SyntaxHighlighter::kValidTagColorDark =
qRgb(128, 128, 255);
const QRgb OrganiseFormat::SyntaxHighlighter::kInvalidTagColorDark =
qRgb(255, 128, 128);
const QRgb OrganiseFormat::SyntaxHighlighter::kBlockColorDark =
qRgb(64, 64, 64);
OrganiseFormat::OrganiseFormat(const QString &format)
: format_(format),
replace_non_ascii_(false),
replace_spaces_(false),
replace_the_(false)
{
replace_the_(false) {
}
void OrganiseFormat::set_format(const QString &v) {
@ -71,11 +78,11 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
if (replace_non_ascii_) {
QString stripped;
for (int i=0 ; i<filename.length() ; ++i) {
for (int i = 0 ; i < filename.length(); ++i) {
const QCharRef c = filename[i];
if (c < 128)
if (c < 128) {
stripped.append(c);
else {
} else {
const QString decomposition = c.decomposition();
if (!decomposition.isEmpty() && decomposition[0] < 128)
stripped.append(decomposition[0]);
@ -140,18 +147,21 @@ QString OrganiseFormat::TagValue(const QString &tag, const Song &song) const {
else if (tag == "track") value = QString::number(song.track());
else if (tag == "disc") value = QString::number(song.disc());
else if (tag == "bpm") value = QString::number(song.bpm());
else if (tag == "length") value = QString::number(song.length_nanosec() / kNsecPerSec);
else if (tag == "length") value =
QString::number(song.length_nanosec() / kNsecPerSec);
else if (tag == "bitrate") value = QString::number(song.bitrate());
else if (tag == "samplerate") value = QString::number(song.samplerate());
else if (tag == "extension") value = song.url().toLocalFile().section('.', -1, -1);
else if (tag == "extension") value =
song.url().toLocalFile().section('.', -1, -1);
else if (tag == "artistinitial") {
value = song.effective_albumartist().trimmed();
if (replace_the_ && !value.isEmpty())
value.replace(QRegExp("^the\\s+", Qt::CaseInsensitive), "");
if (!value.isEmpty()) value = value[0].toUpper();
}
else if (tag == "albumartist") {
value = song.is_compilation() ? "Various Artists" : song.effective_albumartist();
} else if (tag == "albumartist") {
value = song.is_compilation()
? "Various Artists"
: song.effective_albumartist();
}
if (replace_the_ && (tag == "artist" || tag == "albumartist"))
@ -165,7 +175,7 @@ QString OrganiseFormat::TagValue(const QString &tag, const Song &song) const {
value.prepend('0');
// Replace characters that really shouldn't be in paths
for (int i=0 ; i<kInvalidFatCharactersCount ; ++i) {
for (int i = 0 ; i < kInvalidFatCharactersCount; ++i) {
value.replace(kInvalidFatCharacters[i], '_');
}
@ -176,16 +186,17 @@ QString OrganiseFormat::TagValue(const QString &tag, const Song &song) const {
OrganiseFormat::Validator::Validator(QObject *parent)
: QValidator(parent) {}
QValidator::State OrganiseFormat::Validator::validate(QString& input, int&) const {
QValidator::State OrganiseFormat::Validator::validate(
QString& input, int&) const {
QRegExp tag_regexp(kTagPattern);
// Make sure all the blocks match up
int block_level = 0;
for (int i=0 ; i<input.length() ; ++i) {
for (int i = 0 ; i < input.length(); ++i) {
if (input[i] == '{')
block_level ++;
block_level++;
else if (input[i] == '}')
block_level --;
block_level--;
if (block_level < 0 || block_level > 1)
return QValidator::Invalid;
@ -217,10 +228,12 @@ OrganiseFormat::SyntaxHighlighter::SyntaxHighlighter(QTextDocument* parent)
: QSyntaxHighlighter(parent) {}
void OrganiseFormat::SyntaxHighlighter::highlightBlock(const QString& text) {
const bool light = QApplication::palette().color(QPalette::Base).value() > 128;
const bool light =
QApplication::palette().color(QPalette::Base).value() > 128;
const QRgb block_color = light ? kBlockColorLight : kBlockColorDark;
const QRgb valid_tag_color = light ? kValidTagColorLight : kValidTagColorDark;
const QRgb invalid_tag_color = light ? kInvalidTagColorLight : kInvalidTagColorDark;
const QRgb invalid_tag_color =
light ? kInvalidTagColorLight : kInvalidTagColorDark;
QRegExp tag_regexp(kTagPattern);
QRegExp block_regexp(kBlockPattern);
@ -243,8 +256,10 @@ void OrganiseFormat::SyntaxHighlighter::highlightBlock(const QString& text) {
pos = 0;
while ((pos = tag_regexp.indexIn(text, pos)) != -1) {
QTextCharFormat f = format(pos);
f.setForeground(QColor(OrganiseFormat::kKnownTags.contains(tag_regexp.cap(1))
? valid_tag_color : invalid_tag_color));
f.setForeground(
QColor(OrganiseFormat::kKnownTags.contains(tag_regexp.cap(1))
? valid_tag_color
: invalid_tag_color));
setFormat(pos, tag_regexp.matchedLength(), f);
pos += tag_regexp.matchedLength();

View File

@ -15,8 +15,8 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ORGANISEFORMAT_H
#define ORGANISEFORMAT_H
#ifndef SRC_CORE_ORGANISEFORMAT_H_
#define SRC_CORE_ORGANISEFORMAT_H_
#include <QSyntaxHighlighter>
#include <QValidator>
@ -24,7 +24,7 @@
#include "core/song.h"
class OrganiseFormat {
public:
public:
OrganiseFormat(const QString& format = QString());
static const char* kTagPattern;
@ -48,13 +48,13 @@ public:
class Validator : public QValidator {
public:
Validator(QObject* parent = 0);
public:
explicit Validator(QObject* parent = 0);
QValidator::State validate(QString& format, int& pos) const;
};
class SyntaxHighlighter : public QSyntaxHighlighter {
public:
public:
static const QRgb kValidTagColorLight;
static const QRgb kInvalidTagColorLight;
static const QRgb kBlockColorLight;
@ -62,14 +62,15 @@ public:
static const QRgb kInvalidTagColorDark;
static const QRgb kBlockColorDark;
SyntaxHighlighter(QObject* parent = 0);
SyntaxHighlighter(QTextEdit* parent);
SyntaxHighlighter(QTextDocument* parent);
explicit SyntaxHighlighter(QObject* parent = 0);
explicit SyntaxHighlighter(QTextEdit* parent);
explicit SyntaxHighlighter(QTextDocument* parent);
void highlightBlock(const QString& format);
};
private:
QString ParseBlock(QString block, const Song& song, bool* any_empty = NULL) const;
private:
QString ParseBlock(
QString block, const Song& song, bool* any_empty = NULL) const;
QString TagValue(const QString& tag, const Song& song) const;
QString format_;
@ -78,4 +79,4 @@ private:
bool replace_the_;
};
#endif // ORGANISEFORMAT_H
#endif // SRC_CORE_ORGANISEFORMAT_H_