Skip to content
Permalink
Browse files

use upper camel case for the class name

  • Loading branch information
Gustry authored and nyalldawson committed Feb 2, 2019
1 parent 599b0c8 commit 57695bd036f3858db60cf4e3954ff1b001714627
@@ -175,6 +175,7 @@ Utility functions for working with strings.
AllLowercase,
ForceFirstLetterToCapital,
TitleCase,
UpperCamelCase,
};

static QString capitalize( const QString &string, Capitalization capitalization );
@@ -381,12 +381,12 @@ QStringList QgsProcessingModelAlgorithm::asPythonCode( const QgsProcessing::Pyth
auto safeName = []( const QString & name )->QString
{
QString n = name.toLower().trimmed();
QRegularExpression rx( QStringLiteral( "[^a-z_A-Z0-9]" ) );
QRegularExpression rx( QStringLiteral( "[^\\sa-z_A-Z0-9]" ) );
n.replace( rx, QString() );
return n;
return QgsStringUtils::capitalize( n, QgsStringUtils::UpperCamelCase );
};

const QString algorithmClassName = QgsStringUtils::capitalize( safeName( name() ), QgsStringUtils::ForceFirstLetterToCapital );
const QString algorithmClassName = safeName( name() );
lines << QStringLiteral( "class %1(QgsProcessingAlgorithm):" ).arg( algorithmClassName );
lines << QString();

@@ -96,6 +96,11 @@ QString QgsStringUtils::capitalize( const QString &string, QgsStringUtils::Capit
}
return result;
}

case UpperCamelCase:
QString result = QgsStringUtils::capitalize( string.toLower(), QgsStringUtils::ForceFirstLetterToCapital ).simplified();
result.remove( ' ' );
return result;
}
// no warnings
return string;
@@ -189,6 +189,7 @@ class CORE_EXPORT QgsStringUtils
AllLowercase = QFont::AllLowercase, //!< Convert all characters to lowercase
ForceFirstLetterToCapital = QFont::Capitalize, //!< Convert just the first letter of each word to uppercase, leave the rest untouched
TitleCase = QFont::Capitalize + 1000, //!< Simple title case conversion - does not fully grammatically parse the text and uses simple rules only. Note that this method does not convert any characters to lowercase, it only uppercases required letters. Callers must ensure that input strings are already lowercased.
UpperCamelCase = QFont::Capitalize + 1001, //!< Convert the string to upper camel case. Note that this method does not unaccent characters.
};

/**
@@ -36,6 +36,7 @@ class TestQgsStringUtils : public QObject
void insertLinks();
void titleCase_data();
void titleCase();
void camelCase();
void ampersandEncode_data();
void ampersandEncode();
void wordWrap_data();
@@ -188,6 +189,15 @@ void TestQgsStringUtils::titleCase()
QCOMPARE( QgsStringUtils::capitalize( input, QgsStringUtils::TitleCase ), expected );
}

void TestQgsStringUtils::camelCase()
{
QCOMPARE( QgsStringUtils::capitalize( QString(), QgsStringUtils::UpperCamelCase ), QString() );
QCOMPARE( QgsStringUtils::capitalize( QString( " abc def" ), QgsStringUtils::UpperCamelCase ), QString( "AbcDef" ) );
QCOMPARE( QgsStringUtils::capitalize( QString( "ABC DEF" ), QgsStringUtils::UpperCamelCase ), QString( "AbcDef" ) );
QCOMPARE( QgsStringUtils::capitalize( QString( "àbc def" ), QgsStringUtils::UpperCamelCase ), QString( "ÀbcDef" ) );
QCOMPARE( QgsStringUtils::capitalize( QString( "àbc dÉf" ), QgsStringUtils::UpperCamelCase ), QString( "ÀbcDéf" ) );
}

void TestQgsStringUtils::ampersandEncode_data()
{
QTest::addColumn<QString>( "input" );

0 comments on commit 57695bd

Please sign in to comment.
You can’t perform that action at this time.