Index: trunk/extensions/Arrays/RELEASE-NOTES |
— | — | @@ -7,6 +7,10 @@ |
8 | 8 | version 1.3.2. A new option 'singleempty' can be used to avoid this behavior, ',' can be used to |
9 | 9 | create an array with two empty elements. |
10 | 10 | - Bug fixed where '#arraysearch' would always return '-1' instead of parameter 5 value. |
| 11 | + - '#arraysort' (for 'asce' and 'desc' modes) now respects local sort settings specified via PHPs |
| 12 | + 'setlocale()'. A flag system allows to set 'nolocale' separated by a space behind the sort mode. to |
| 13 | + deactivate this for the sorting. |
| 14 | + - '#arraysort' has a new sort mode 'natural' which will sort numbers within strings more human-like. |
11 | 15 | |
12 | 16 | * December 5, 2011 -- Version 2.0rc2 |
13 | 17 | - Bug introduced in r105069 fixed where '#arrayprint' was broken in compatibility mode in some cases. |
Index: trunk/extensions/Arrays/Arrays.php |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | * |
71 | 71 | * @since 2.0 |
72 | 72 | * |
73 | | - * @var type |
| 73 | + * @var string |
74 | 74 | */ |
75 | 75 | static $mDefaultSep; |
76 | 76 | |
— | — | @@ -130,7 +130,7 @@ |
131 | 131 | * |
132 | 132 | * @since 2.0 |
133 | 133 | * |
134 | | - * @return boolean |
| 134 | + * @return string |
135 | 135 | */ |
136 | 136 | public static function getDir() { |
137 | 137 | static $dir = null; |
— | — | @@ -1091,8 +1091,8 @@ |
1092 | 1092 | * This is save and faster for internal usage, just be sure your array doesn't have un-trimmed |
1093 | 1093 | * values or non-numeric or negative array keys and no gaps between keys. |
1094 | 1094 | * |
1095 | | - * @param type $arrayId |
1096 | | - * @param type $array |
| 1095 | + * @param string $arrayId |
| 1096 | + * @param array $array |
1097 | 1097 | */ |
1098 | 1098 | protected function setArray( $arrayId, $array = array() ) { |
1099 | 1099 | $this->mArrays[ trim( $arrayId ) ] = $array; |
— | — | @@ -1192,24 +1192,52 @@ |
1193 | 1193 | * @since 2.0 |
1194 | 1194 | * |
1195 | 1195 | * @param array $array |
1196 | | - * @param string $sortMode |
| 1196 | + * @param string $sortMode one of the following sort modes: |
| 1197 | + * - random: random array order |
| 1198 | + * - reverse: last entry will be first, first the last. |
| 1199 | + * - asce: sort array in ascending order. |
| 1200 | + * - desc: sort array in descending order. |
| 1201 | + * - natural: sort with a 'natural order' algorithm. See PHPs natsort() function. |
| 1202 | + * |
| 1203 | + * In addition, this function allows to set several flags behind the sort mode. The must be |
| 1204 | + * separated by a space. The following keys are allowed: |
| 1205 | + * - nolocale: will prevent 'asce' and 'desc' mode to considering PHP-defined language rules. |
1197 | 1206 | * |
1198 | 1207 | * @return array |
1199 | 1208 | */ |
1200 | 1209 | public static function arraySort( array $array, $sortMode ) { |
1201 | | - // do the requested sorting of the given array: |
| 1210 | + global $egArraysCompatibilityMode; |
| 1211 | + |
| 1212 | + $flags = preg_split( '/\s+/s', $sortMode ); |
| 1213 | + $sortMode = array_shift( $flags ); // first string is the actual sort mode |
| 1214 | + |
| 1215 | + $localeFlag = SORT_LOCALE_STRING; // sort strings accordingly to what was set via setlocale() |
| 1216 | + if( |
| 1217 | + in_array( 'nolocale', $flags ) |
| 1218 | + || $egArraysCompatibilityMode // COMPATIBILITY-MODE |
| 1219 | + ) { |
| 1220 | + // 'nolocale' will prevent from using this flag! |
| 1221 | + $localeFlag = null; |
| 1222 | + } |
| 1223 | + |
| 1224 | + // do the requested sorting of the given array: |
1202 | 1225 | switch( $sortMode ) { |
1203 | 1226 | case 'asc': |
1204 | 1227 | case 'asce': |
1205 | 1228 | case 'ascending': |
1206 | | - sort( $array ); |
| 1229 | + sort( $array, $localeFlag ); |
1207 | 1230 | break; |
1208 | 1231 | |
1209 | 1232 | case 'desc': |
1210 | 1233 | case 'descending': |
1211 | | - rsort( $array ); |
| 1234 | + rsort( $array, $localeFlag ); |
1212 | 1235 | break; |
1213 | | - |
| 1236 | + |
| 1237 | + case 'nat': |
| 1238 | + case 'natural': |
| 1239 | + natsort( $array ); |
| 1240 | + break; |
| 1241 | + |
1214 | 1242 | case 'rand': |
1215 | 1243 | case 'random': |
1216 | 1244 | shuffle( $array ); |
— | — | @@ -1218,7 +1246,7 @@ |
1219 | 1247 | case 'reverse': |
1220 | 1248 | $array = array_reverse( $array ); |
1221 | 1249 | break; |
1222 | | - } ; |
| 1250 | + }; |
1223 | 1251 | return $array; |
1224 | 1252 | } |
1225 | 1253 | |
Index: trunk/extensions/Arrays/COPYING |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | The MIT License |
3 | 3 | |
4 | | - Copyright (c) 2008 - 2011 |
| 4 | + Copyright (c) 2008 - 2012 |
5 | 5 | |
6 | 6 | |
7 | 7 | Permission is hereby granted, free of charge, to any person |