Skip to content
Permalink
Browse files

[FEATURE] implement title() expression

  • Loading branch information
jef-n committed Aug 3, 2012
1 parent dc8ac45 commit de5f95b6f476cea41e5838327c6afc69a1ed09de
Showing with 39 additions and 0 deletions.
  1. +13 −0 resources/function_help/title-de_DE
  2. +14 −0 resources/function_help/title_en_US
  3. +12 −0 src/core/qgsexpression.cpp
@@ -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>
@@ -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>
@@ -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 );
@@ -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" ) )

0 comments on commit de5f95b

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