Skip to content

Commit 42d7e0b

Browse files
renamed parameter names of array_slice, ran prepare-commit.sh
1 parent 8978469 commit 42d7e0b

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

resources/function_help/json/array_slice

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "array_get",
33
"type": "function",
4-
"description": "Returns a portion of the array. The slice is defined by the startPos and endPos arguments. A slice that ",
4+
"description": "Returns a portion of the array. The slice is defined by the start_pos and end_pos arguments.",
55
"arguments": [{
66
"arg": "array",
77
"description": "an array"
88
},
99
{
10-
"arg": "startPos",
11-
"description": "the index of the start position of the slice (0 based). The startPos index is included in the slice. If you use a negative startPos, the index is counted from the end of the list (-1 based)."
10+
"arg": "start_pos",
11+
"description": "the index of the start position of the slice (0 based). The start_pos index is included in the slice. If you use a negative start_pos, the index is counted from the end of the list (-1 based)."
1212
},
1313
{
14-
"arg": "endPos",
15-
"description": "the index of the start position of the slice (0 based). The endPos index is included in the slice. If you use a negative endPos, the index is counted from the end of the list (-1 based)."
14+
"arg": "end_pos",
15+
"description": "the index of the end position of the slice (0 based). The end_pos index is included in the slice. If you use a negative end_pos, the index is counted from the end of the list (-1 based)."
1616
}
1717
],
1818
"examples": [{

src/core/expression/qgsexpressionfunction.cpp

+17-13
Original file line numberDiff line numberDiff line change
@@ -3605,24 +3605,28 @@ static QVariant fcnArrayCat( const QVariantList &values, const QgsExpressionCont
36053605
static QVariant fcnArraySlice( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
36063606
{
36073607
QVariantList list = QgsExpressionUtils::getListValue( values.at( 0 ), parent );
3608-
qlonglong startPos = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
3609-
const qlonglong endPos = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
3610-
qlonglong sliceLength = 0;
3608+
qlonglong start_pos = QgsExpressionUtils::getIntValue( values.at( 1 ), parent );
3609+
const qlonglong end_pos = QgsExpressionUtils::getIntValue( values.at( 2 ), parent );
3610+
qlonglong slice_length = 0;
36113611
// negative positions means positions taken relative to the end of the array
3612-
if( startPos < 0 ) {
3613-
startPos = list.length() + startPos;
3612+
if ( start_pos < 0 )
3613+
{
3614+
start_pos = list.length() + start_pos;
36143615
}
3615-
if( endPos >= 0 ) {
3616-
sliceLength = endPos - startPos + 1;
3616+
if ( end_pos >= 0 )
3617+
{
3618+
slice_length = end_pos - start_pos + 1;
36173619
}
3618-
else {
3619-
sliceLength = list.length() + endPos - startPos + 1;
3620+
else
3621+
{
3622+
slice_length = list.length() + end_pos - start_pos + 1;
36203623
}
36213624
//avoid negative lengths in QList.mid function
3622-
if (sliceLength < 0) {
3623-
sliceLength = 0;
3625+
if ( slice_length < 0 )
3626+
{
3627+
slice_length = 0;
36243628
}
3625-
list = list.mid(startPos,sliceLength);
3629+
list = list.mid( start_pos, slice_length );
36263630
return list;
36273631
}
36283632

@@ -4287,7 +4291,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
42874291
<< new QgsStaticExpressionFunction( QStringLiteral( "array_remove_at" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "array" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "pos" ) ), fcnArrayRemoveAt, QStringLiteral( "Arrays" ) )
42884292
<< new QgsStaticExpressionFunction( QStringLiteral( "array_remove_all" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "array" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "value" ) ), fcnArrayRemoveAll, QStringLiteral( "Arrays" ) )
42894293
<< new QgsStaticExpressionFunction( QStringLiteral( "array_cat" ), -1, fcnArrayCat, QStringLiteral( "Arrays" ) )
4290-
<< new QgsStaticExpressionFunction( QStringLiteral( "array_slice" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "array" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "startPos" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "endPos" ) ), fcnArraySlice, QStringLiteral( "Arrays" ) )
4294+
<< new QgsStaticExpressionFunction( QStringLiteral( "array_slice" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "array" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "start_pos" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "end_pos" ) ), fcnArraySlice, QStringLiteral( "Arrays" ) )
42914295
<< new QgsStaticExpressionFunction( QStringLiteral( "array_reverse" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "array" ) ), fcnArrayReverse, QStringLiteral( "Arrays" ) )
42924296
<< new QgsStaticExpressionFunction( QStringLiteral( "array_intersect" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "array1" ) ) << QgsExpressionFunction::Parameter( QStringLiteral( "array2" ) ), fcnArrayIntersect, QStringLiteral( "Arrays" ) )
42934297
<< new QgsStaticExpressionFunction( QStringLiteral( "array_distinct" ), 1, fcnArrayDistinct, QStringLiteral( "Arrays" ) )

tests/src/core/testqgsexpression.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ class TestQgsExpression: public QObject
24252425

24262426
QCOMPARE( QgsExpression( "array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),1,2) = array('Valmiera','Chugiak')" ).evaluate( &context ), QVariant( true ) );
24272427
QCOMPARE( QgsExpression( "array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),-2,-1) = array('Chugiak','Brighton')" ).evaluate( &context ), QVariant( true ) );
2428+
QCOMPARE( QgsExpression( "array_slice( array(), 0, 3) = array()" ).evaluate( &context ), QVariant( true ) );
24282429
}
24292430

24302431
void eval_int_array()

0 commit comments

Comments
 (0)