[FEATURE] implement title() expression

This commit is contained in:
Juergen E. Fischer 2012-08-03 02:07:04 +02:00
parent dc8ac451da
commit de5f95b6f4
3 changed files with 39 additions and 0 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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" ) )