Skip to content

Commit de5f95b

Browse files
committed
[FEATURE] implement title() expression
1 parent dc8ac45 commit de5f95b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

resources/function_help/title-de_DE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h3>Funktion title()</h3>
2+
Wandelt alle Worte einer Zeichenkette in Kleinbuchstaben mit großem Anfangsbuchstaben um.
3+
4+
<p><h4>Syntax</h4>
5+
title(<i>zeichenkette</i>)</p>
6+
7+
<p><h4>Argumente</h4>
8+
<!-- List args for functions here-->
9+
<i> zeichenkette</i> &rarr; ist eine Zeichenkette. Die Zeichenkette, deren Worte in Kleinbuchstaben mit großem Anfangsbuchstaben umgewandelt werden.</p>
10+
11+
<p><h4>Beispiel</h4>
12+
<!-- Show example of function.-->
13+
title('hello WOrld') &rarr; 'Hello World'</p>

resources/function_help/title_en_US

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h3>title() function</h3>
2+
Converts all words of a string to title case (all words lower case with leading
3+
capital letter).
4+
5+
<p><h4>Syntax</h4>
6+
title(<i>string</i>)</p>
7+
8+
<p><h4>Arguments</h4>
9+
<!-- List args for functions here-->
10+
<i> string</i> &rarr; is string. The string to convert to title case.</p>
11+
12+
<p><h4>Example</h4>
13+
<!-- Show example of function.-->
14+
upper('hello WOrld') &rarr; 'Hello World'</p>

src/core/qgsexpression.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,17 @@ static QVariant fcnUpper( const QVariantList& values, QgsFeature* , QgsExpressio
450450
QString str = getStringValue( values.at( 0 ), parent );
451451
return QVariant( str.toUpper() );
452452
}
453+
static QVariant fcnTitle( const QVariantList& values, QgsFeature* , QgsExpression* parent )
454+
{
455+
QString str = getStringValue( values.at( 0 ), parent );
456+
QStringList elems = str.split( " " );
457+
for ( int i = 0; i < elems.size(); i++ )
458+
{
459+
if ( elems[i].size() > 1 )
460+
elems[i] = elems[i].left( 1 ).toUpper() + elems[i].mid( 1 ).toLower();
461+
}
462+
return QVariant( elems.join( " " ) );
463+
}
453464
static QVariant fcnLength( const QVariantList& values, QgsFeature* , QgsExpression* parent )
454465
{
455466
QString str = getStringValue( values.at( 0 ), parent );
@@ -800,6 +811,7 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
800811
// string manipulation
801812
<< FunctionDef( "lower", 1, fcnLower, QObject::tr( "String" ) )
802813
<< FunctionDef( "upper", 1, fcnUpper, QObject::tr( "String" ) )
814+
<< FunctionDef( "title", 1, fcnTitle, QObject::tr( "String" ) )
803815
<< FunctionDef( "length", 1, fcnLength, QObject::tr( "String" ) )
804816
<< FunctionDef( "replace", 3, fcnReplace, QObject::tr( "String" ) )
805817
<< FunctionDef( "regexp_replace", 3, fcnRegexpReplace, QObject::tr( "String" ) )

0 commit comments

Comments
 (0)