Commit 8a1b4f5f authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplatform: less auto-casting from/to ascii & from bytearray

Reviewed By: kfunk

Subscribers: kfunk, kdevelop-devel

Differential Revision: https://phabricator.kde.org/D8512
parent 4460a8b3
......@@ -40,7 +40,7 @@ static const char* const BREAKPOINT_KINDS[Breakpoint::LastBreakpointKind] = {
static Breakpoint::BreakpointKind stringToKind(const QString& kindString)
{
for (int i = 0; i < Breakpoint::LastBreakpointKind; ++i) {
if (BREAKPOINT_KINDS[i] == kindString) {
if (kindString == QLatin1String(BREAKPOINT_KINDS[i])) {
return (Breakpoint::BreakpointKind)i;
}
}
......@@ -100,7 +100,7 @@ bool Breakpoint::setData(int index, const QVariant& value)
{
QString s = value.toString();
if (index == LocationColumn) {
QRegExp rx("^(.+):([0-9]+)$");
QRegExp rx(QStringLiteral("^(.+):([0-9]+)$"));
int idx = rx.indexIn(s);
if (m_kind == CodeBreakpoint && idx != -1) {
m_url = QUrl::fromLocalFile(rx.cap(1));
......@@ -171,7 +171,7 @@ QVariant Breakpoint::data(int column, int role) const
if (column == TypeColumn && role == Qt::DisplayRole)
{
return BREAKPOINT_KINDS[m_kind];
return QLatin1String(BREAKPOINT_KINDS[m_kind]);
}
if (column == ConditionColumn && (role == Qt::DisplayRole || role == Qt::EditRole)) {
......@@ -187,7 +187,7 @@ QVariant Breakpoint::data(int column, int role) const
} else {
ret = m_url.toDisplayString(QUrl::PreferLocalFile | QUrl::StripTrailingSlash);
}
ret += ':' + QString::number(m_line+1);
ret += QLatin1Char(':') + QString::number(m_line+1);
} else {
ret = m_expression;
}
......
......@@ -213,7 +213,7 @@ BreakpointModel::headerData(int section, Qt::Orientation orientation,
}
if (role == Qt::DisplayRole) {
if (section == 0 || section == 1) return "";
if (section == 0 || section == 1) return QString();
if (section == 2) return i18n("Type");
if (section == 3) return i18n("Location");
if (section == 4) return i18n("Condition");
......
......@@ -205,7 +205,7 @@ QVariant FrameStackModel::data(const QModelIndex& index, int role) const
QString ret = ICore::self()->projectController()
->prettyFileName(frame.file, IProjectController::FormatPlain);
if (frame.line != -1) {
ret += ':' + QString::number(frame.line + 1);
ret += QLatin1Char(':') + QString::number(frame.line + 1);
}
return ret;
} else if (role == Qt::DecorationRole) {
......
......@@ -188,9 +188,9 @@ public:
: TreeItem(model, parent)
{
QVector<QVariant> data;
data.push_back("...");
data.push_back(QVariant(QStringLiteral("...")));
for (int i = 1; i < model->columnCount(QModelIndex()); ++i)
data.push_back("");
data.push_back(QString());
setData(data);
}
......
......@@ -154,7 +154,7 @@ public:
{
QString ext;
if( extension.isEmpty() ) {
ext = qobject_interface_iid<Extension*>();
ext = QString::fromUtf8(qobject_interface_iid<Extension*>());
} else {
ext = extension;
}
......
......@@ -103,7 +103,7 @@ void SourceFormatterStyle::setMimeTypes(const SourceFormatterStyle::MimeList& ty
void SourceFormatterStyle::setMimeTypes(const QStringList& types)
{
foreach ( auto& t, types ) {
auto items = t.split('|');
auto items = t.split(QLatin1Char('|'));
if ( items.size() != 2 ) {
continue;
}
......@@ -167,10 +167,7 @@ QString ISourceFormatter::optionMapToString(const QMap<QString, QVariant> &map)
QString options;
QMap<QString, QVariant>::const_iterator it = map.constBegin();
for (; it != map.constEnd(); ++it) {
options += it.key();
options += '=';
options += it.value().toString();
options += ',';
options += it.key() + QLatin1Char('=') + it.value().toString() + QLatin1Char(',');
}
return options;
}
......@@ -178,10 +175,10 @@ QString ISourceFormatter::optionMapToString(const QMap<QString, QVariant> &map)
QMap<QString, QVariant> ISourceFormatter::stringToOptionMap(const QString &options)
{
QMap<QString, QVariant> map;
QStringList pairs = options.split(',', QString::SkipEmptyParts);
QStringList pairs = options.split(QLatin1Char(','), QString::SkipEmptyParts);
QStringList::const_iterator it;
for (it = pairs.constBegin(); it != pairs.constEnd(); ++it) {
QStringList bits = (*it).split('=');
const QStringList bits = (*it).split(QLatin1Char('='));
map[bits[0]] = bits[1];
}
return map;
......@@ -191,7 +188,7 @@ QString ISourceFormatter::missingExecutableMessage(const QString &name)
{
return i18n("The executable %1 cannot be found. Please make sure"
" it is installed and can be executed. <br />"
"The plugin will not work until you fix this problem.", "<b>" + name + "</b>");
"The plugin will not work until you fix this problem.", QLatin1String("<b>") + name + QLatin1String("</b>"));
}
}
......
......@@ -139,7 +139,7 @@ void RenameAssistant::textChanged(KTextEditor::Document* doc, const KTextEditor:
return;
//If the inserted text isn't valid for a variable name, consider the editing ended
QRegExp validDeclName("^[0-9a-zA-Z_]*$");
QRegExp validDeclName(QStringLiteral("^[0-9a-zA-Z_]*$"));
if (removedText.isEmpty() && !validDeclName.exactMatch(doc->text(invocationRange))) {
d->reset();
return;
......
......@@ -163,8 +163,8 @@ void DocumentChangeTracker::updateChangedRange(int delay)
static Cursor cursorAdd(Cursor c, const QString& text)
{
c.setLine(c.line() + text.count('\n'));
c.setColumn(c.column() + (text.length() - qMin(0, text.lastIndexOf('\n'))));
c.setLine(c.line() + text.count(QLatin1Char('\n')));
c.setColumn(c.column() + (text.length() - qMin(0, text.lastIndexOf(QLatin1Char('\n')))));
return c;
}
......
......@@ -132,7 +132,7 @@ QVariant ClassModel::data(const QModelIndex& index, int role) const
QVariant ClassModel::headerData(int, Qt::Orientation, int role) const
{
if ( role == Qt::DisplayRole )
return "Class";
return QStringLiteral("Class");
return QVariant();
}
......
......@@ -299,9 +299,9 @@ FunctionNode::FunctionNode(Declaration* a_decl, NodesModelInterface* a_model)
ClassFunctionDeclaration* classmember = dynamic_cast<ClassFunctionDeclaration*>(a_decl);
if ( classmember ) {
if ( classmember->isConstructor() || classmember->isDestructor() )
m_sortableString = '0' + m_displayName;
m_sortableString = QLatin1Char('0') + m_displayName;
else
m_sortableString = '1' + m_displayName;
m_sortableString = QLatin1Char('1') + m_displayName;
}
else {
m_sortableString = m_displayName;
......
......@@ -29,7 +29,7 @@ typedef PushValue<int> IntPusher;
///Extracts the last line from the given string
QString CodeCompletionContext::extractLastLine(const QString& str) {
int prevLineEnd = str.lastIndexOf('\n');
int prevLineEnd = str.lastIndexOf(QLatin1Char('\n'));
if(prevLineEnd != -1)
return str.mid(prevLineEnd+1);
else
......
......@@ -51,26 +51,26 @@ void insertFunctionParenText(KTextEditor::View* view, const KTextEditor::Cursor&
//Need to have a paren behind
QString suffix = view->document()->text( KTextEditor::Range( pos, pos + KTextEditor::Cursor(1, 0) ) );
if( suffix.trimmed().startsWith('(') ) {
if (suffix.trimmed().startsWith(QLatin1Char('('))) {
//Move the cursor behind the opening paren
if( view )
view->setCursorPosition( pos + KTextEditor::Cursor( 0, suffix.indexOf('(')+1 ) );
view->setCursorPosition(pos + KTextEditor::Cursor(0, suffix.indexOf(QLatin1Char('(')) + 1));
}else{
//We need to insert an opening paren
QString openingParen;
if( spaceBeforeParen )
openingParen = QStringLiteral(" (");
else
openingParen = '(';
openingParen = QLatin1Char('(');
if( spaceBetweenParens && (haveArguments || spaceBetweenEmptyParens) )
openingParen += ' ';
openingParen += QLatin1Char(' ');
QString closingParen;
if( spaceBetweenParens && (haveArguments) ) {
closingParen = QStringLiteral(" )");
} else
closingParen = ')';
closingParen = QLatin1Char(')');
KTextEditor::Cursor jumpPos = pos + KTextEditor::Cursor( 0, openingParen.length() );
......@@ -79,8 +79,8 @@ void insertFunctionParenText(KTextEditor::View* view, const KTextEditor::Cursor&
if (IntegralType::Ptr type = funcType->returnType().cast<IntegralType>()) {
if (type->dataType() == IntegralType::TypeVoid) {
const QChar nextChar = view->document()->characterAt(pos);
if (nextChar != ';' && nextChar != ')' && nextChar != ',') {
closingParen += ';';
if (nextChar != QLatin1Char(';') && nextChar != QLatin1Char(')') && nextChar != QLatin1Char(',')) {
closingParen += QLatin1Char(';');
}
}
}
......
......@@ -111,7 +111,7 @@ void CodeCompletionWorker::computeCompletions(const KDevelop::DUContextPointer&
}
if( position.column() == 0 ) //Seems like when the cursor is a the beginning of a line, kate does not give the \n
text += '\n';
text += QLatin1Char('\n');
if (aborting()) {
failed();
......
......@@ -156,7 +156,7 @@ QVariant NormalDeclarationCompletionItem::data(const QModelIndex& index, int rol
if(!m_declaration->context()->owner()->identifier().isEmpty())
return shortenedTypeString(DeclarationPointer(m_declaration->context()->owner()), desiredTypeLength);
else
return "enum";
return QStringLiteral("enum");
}
}
if (FunctionType::Ptr functionType = m_declaration->type<FunctionType>()) {
......@@ -171,17 +171,17 @@ QVariant NormalDeclarationCompletionItem::data(const QModelIndex& index, int rol
}else if(argumentHintDepth()) {
return QString();//Don't show useless prefixes in the argument-hints
}else if(funDecl && funDecl->isConstructor() )
return "<constructor>";
return QStringLiteral("<constructor>");
else if(funDecl && funDecl->isDestructor() )
return "<destructor>";
return QStringLiteral("<destructor>");
else
return "<incomplete type>";
return QStringLiteral("<incomplete type>");
} else {
return shortenedTypeString(m_declaration, desiredTypeLength);
}
} else {
return "<incomplete type>";
return QStringLiteral("<incomplete type>");
}
} else if (index.column() == CodeCompletionModel::Arguments) {
if (m_declaration->isFunctionDeclaration()) {
......
......@@ -173,7 +173,7 @@ void ApplyChangesWidgetPrivate::createEditPart(const IndexedString & file)
CodeRepresentation::Ptr repr = createCodeRepresentation(file);
if(!repr->fileExists())
{
const QString templateName = QDir::tempPath() + QLatin1Char('/') + url.fileName().split('.').last();
const QString templateName = QDir::tempPath() + QLatin1Char('/') + url.fileName().split(QLatin1Char('.')).last();
QTemporaryFile * temp(new QTemporaryFile(templateName));
temp->open();
temp->write(repr->text().toUtf8());
......
......@@ -101,5 +101,5 @@ QString ArchiveTemplateLocation::templateContents(const QString& name) const
{
const KArchiveFile* file = dynamic_cast<const KArchiveFile*>(m_directory->entry(name));
Q_ASSERT(file);
return file->data();
return QString::fromUtf8(file->data());
}
......@@ -52,7 +52,7 @@ namespace {
QPair<QString, QString> splitFileAtExtension(const QString& fileName)
{
int idx = fileName.indexOf('.');
int idx = fileName.indexOf(QLatin1Char('.'));
if (idx == -1) {
return qMakePair(fileName, QString());
}
......
......@@ -44,7 +44,7 @@ QString CodeRepresentation::rangeText(const KTextEditor::Range& range) const
QString rangedText = line(range.start().line()).mid(range.start().column());
for(int i = range.start().line() + 1; i <= range.end().line(); ++i)
rangedText += '\n' + ((i == range.end().line()) ? line(i).left(range.end().column()) : line(i));
rangedText += QLatin1Char('\n') + ((i == range.end().line()) ? line(i).left(range.end().column()) : line(i));
return rangedText;
}
......@@ -64,8 +64,8 @@ static void grepLine(const QString& identifier, const QString& lineText, int lin
pos += identifier.length();
int end = pos;
if(!surroundedByBoundary || ( (end == lineText.length() || !lineText[end].isLetterOrNumber() || lineText[end] != '_')
&& (start-1 < 0 || !lineText[start-1].isLetterOrNumber() || lineText[start-1] != '_')) )
if (!surroundedByBoundary || ( (end == lineText.length() || !lineText[end].isLetterOrNumber() || lineText[end] != QLatin1Char('_'))
&& (start-1 < 0 || !lineText[start-1].isLetterOrNumber() || lineText[start-1] != QLatin1Char('_'))) )
{
ret << KTextEditor::Range(lineNumber, start, lineNumber, end);
}
......@@ -158,7 +158,7 @@ class FileCodeRepresentation : public CodeRepresentation {
QFile file( localFile );
if ( file.open(QIODevice::ReadOnly) ) {
data = QString::fromLocal8Bit(file.readAll());
lineData = data.split('\n');
lineData = data.split(QLatin1Char('\n'));
}
m_exists = file.exists();
}
......@@ -228,7 +228,7 @@ class ArtificialStringData : public QSharedData {
}
void setData(const QString& data) {
m_data = data;
m_lineData = m_data.split('\n');
m_lineData = m_data.split(QLatin1Char('\n'));
}
QString data() const {
return m_data;
......
......@@ -379,7 +379,7 @@ DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::generateNewText(const
}
//Create the actual new modified file
QStringList textLines = repr->text().split('\n');
QStringList textLines = repr->text().split(QLatin1Char('\n'));
QUrl url = file.toUrl();
......@@ -406,8 +406,8 @@ DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::generateNewText(const
if(formatPolicy == DocumentChangeSet::AutoFormatChangesKeepIndentation) {
// Reproduce the previous indentation
QStringList oldLines = oldNewText.split('\n');
QStringList newLines = change.m_newText.split('\n');
QStringList oldLines = oldNewText.split(QLatin1Char('\n'));
QStringList newLines = change.m_newText.split(QLatin1Char('\n'));
if(oldLines.size() == newLines.size()) {
for(int line = 0; line < newLines.size(); ++line) {
......
......@@ -39,7 +39,7 @@ using namespace KDevelop;
/// @param base String such as 'public QObject' or 'QObject'
InheritanceDescription descriptionFromString(const QString& base)
{
QStringList splitBase = base.split(' ');
QStringList splitBase = base.split(QLatin1Char(' '));
QString identifier = splitBase.takeLast();
QString inheritanceMode = splitBase.join(QStringLiteral(" "));
......@@ -159,8 +159,8 @@ QUrl TemplateClassGenerator::fileUrl(const QString& outputFile) const
void TemplateClassGenerator::setFileUrl(const QString& outputFile, const QUrl& url)
{
d->fileUrls.insert(outputFile, url);
d->renderer.addVariable("output_file_" + outputFile.toLower(), QDir(d->baseUrl.path()).relativeFilePath(url.path()));
d->renderer.addVariable("output_file_" + outputFile.toLower() + "_absolute", url.toLocalFile());
d->renderer.addVariable(QLatin1String("output_file_") + outputFile.toLower(), QDir(d->baseUrl.path()).relativeFilePath(url.path()));
d->renderer.addVariable(QLatin1String("output_file_") + outputFile.toLower() + QLatin1String("_absolute"), url.toLocalFile());
}
KTextEditor::Cursor TemplateClassGenerator::filePosition(const QString& outputFile) const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment