Skip to content

Commit

Permalink
[FEATURE] implement title() expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Aug 3, 2012
1 parent dc8ac45 commit de5f95b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions resources/function_help/title-de_DE
@@ -0,0 +1,13 @@
<h3>Funktion title()</h3>
Wandelt alle Worte einer Zeichenkette in Kleinbuchstaben mit großem Anfangsbuchstaben um.

<p><h4>Syntax</h4>
title(<i>zeichenkette</i>)</p>

<p><h4>Argumente</h4>
<!-- List args for functions here-->
<i> zeichenkette</i> &rarr; ist eine Zeichenkette. Die Zeichenkette, deren Worte in Kleinbuchstaben mit großem Anfangsbuchstaben umgewandelt werden.</p>

<p><h4>Beispiel</h4>
<!-- Show example of function.-->
title('hello WOrld') &rarr; 'Hello World'</p>
14 changes: 14 additions & 0 deletions resources/function_help/title_en_US
@@ -0,0 +1,14 @@
<h3>title() function</h3>
Converts all words of a string to title case (all words lower case with leading
capital letter).

<p><h4>Syntax</h4>
title(<i>string</i>)</p>

<p><h4>Arguments</h4>
<!-- List args for functions here-->
<i> string</i> &rarr; is string. The string to convert to title case.</p>

<p><h4>Example</h4>
<!-- Show example of function.-->
upper('hello WOrld') &rarr; 'Hello World'</p>
12 changes: 12 additions & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -450,6 +450,17 @@ static QVariant fcnUpper( const QVariantList& values, QgsFeature* , QgsExpressio
QString str = getStringValue( values.at( 0 ), parent );
return QVariant( str.toUpper() );
}
static QVariant fcnTitle( const QVariantList& values, QgsFeature* , QgsExpression* parent )
{
QString str = getStringValue( values.at( 0 ), parent );
QStringList elems = str.split( " " );
for ( int i = 0; i < elems.size(); i++ )
{
if ( elems[i].size() > 1 )
elems[i] = elems[i].left( 1 ).toUpper() + elems[i].mid( 1 ).toLower();
}
return QVariant( elems.join( " " ) );
}
static QVariant fcnLength( const QVariantList& values, QgsFeature* , QgsExpression* parent )
{
QString str = getStringValue( values.at( 0 ), parent );
Expand Down Expand Up @@ -800,6 +811,7 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
// string manipulation
<< FunctionDef( "lower", 1, fcnLower, QObject::tr( "String" ) )
<< FunctionDef( "upper", 1, fcnUpper, QObject::tr( "String" ) )
<< FunctionDef( "title", 1, fcnTitle, QObject::tr( "String" ) )
<< FunctionDef( "length", 1, fcnLength, QObject::tr( "String" ) )
<< FunctionDef( "replace", 3, fcnReplace, QObject::tr( "String" ) )
<< FunctionDef( "regexp_replace", 3, fcnRegexpReplace, QObject::tr( "String" ) )
Expand Down

0 comments on commit de5f95b

Please sign in to comment.