Index: trunk/phase3/languages/Language.php |
— | — | @@ -1271,13 +1271,21 @@ |
1272 | 1272 | return $s; |
1273 | 1273 | } |
1274 | 1274 | |
1275 | | - # Crop a string from the beginning or end to a certain number of bytes. |
1276 | | - # (Bytes are used because our storage has limited byte lengths for some |
1277 | | - # columns in the database.) Multibyte charsets will need to make sure that |
1278 | | - # only whole characters are included! |
1279 | | - # |
1280 | | - # $length does not include the optional ellipsis. |
1281 | | - # If $length is negative, snip from the beginning |
| 1275 | + /** |
| 1276 | + * Truncate a string to a specified length in bytes, appending an optional |
| 1277 | + * string (e.g. for ellipses) |
| 1278 | + * |
| 1279 | + * The database offers limited byte lengths for some columns in the database; |
| 1280 | + * multi-byte character sets mean we need to ensure that only whole characters |
| 1281 | + * are included, otherwise broken characters can be passed to the user |
| 1282 | + * |
| 1283 | + * If $length is negative, the string will be truncated from the beginning |
| 1284 | + * |
| 1285 | + * @param string $string String to truncate |
| 1286 | + * @param int $length Maximum length (excluding ellipses) |
| 1287 | + * @param string $ellipses String to append to the truncated text |
| 1288 | + * @return string |
| 1289 | + */ |
1282 | 1290 | function truncate( $string, $length, $ellipsis = "" ) { |
1283 | 1291 | if( $length == 0 ) { |
1284 | 1292 | return $ellipsis; |