From 26ee99743c65a5a43b623f052e6fb9cac48499ad Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Wed, 24 Jul 2013 00:42:53 -0400 Subject: [PATCH] Update readme with todo items, rename truncate to safeTruncate, and clean to collapseWhitespace --- README.md | 64 ++++++++++++++++++++++++++++++----- src/Stringy/Stringy.php | 8 ++--- tests/Stringy/StringyTest.php | 16 ++++----- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0ff24d4..e320c94 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A PHP library with a variety of string manipulation functions with multibyte support. Inspired by underscore.string.js. +Note: The methods listed below are subject to change until we reach a 1.0.0 release. + * [Requiring/Loading](#requiringloading) * [Methods](#methods) * [upperCaseFirst](#uppercasefirst) @@ -14,7 +16,7 @@ A PHP library with a variety of string manipulation functions with multibyte sup * [titleize](#titleize) * [humanize](#humanize) * [tidy](#tidy) - * [clean](#clean) + * [collapseWhitespace](#collapsewhitespace) * [standardize](#standardize) * [pad](#pad) * [padLeft](#padleft) @@ -28,7 +30,7 @@ A PHP library with a variety of string manipulation functions with multibyte sup * [contains](#contains) * [surround](#surround) * [insert](#insert) - * [truncate](#truncate) + * [safeTruncate](#safetruncate) * [reverse](#reverse) * [shuffle](#shuffle) * [Tests](#tests) @@ -183,15 +185,15 @@ Replaces smart quotes, ellipsis characters, and dashes from Windows-1252 S::tidy('“I see…”'); // '"I see..."' ``` -##### clean +##### collapseWhitespace -S::clean(string $str) +S::collapseWhitespace(string $str) Trims the string and replaces consecutive whitespace characters with a -single space. +single space. This inclues tabs and newline characters. ```php -S::clean(' Ο συγγραφέας '); // 'Ο συγγραφέας' +S::collapseWhitespace(' Ο συγγραφέας '); // 'Ο συγγραφέας' ``` ##### standardize @@ -340,9 +342,9 @@ Inserts $substring into $str at the $index provided. S::insert('fòô bà', 'ř', 6, 'UTF-8'); // 'fòô bàř' ``` -##### truncate +##### safeTruncate -S::truncate(string $str, int $length, [, string $substring = '' [, string $encoding ]]) +S::safeTruncate(string $str, int $length, [, string $substring = '' [, string $encoding ]]) Truncates the string to a given length, while ensuring that it does not chop words. If $substring is provided, and truncating occurs, the string @@ -350,7 +352,7 @@ is further truncated so that the substring may be appended without exceeding the desired length. ```php -S::truncate('What are your plans today?', 22, '...'); // 'What are your plans...' +S::safeTruncate('What are your plans today?', 22, '...'); // 'What are your plans...' ``` ##### reverse @@ -386,6 +388,50 @@ S::shuffle('fòô bàř', 'UTF-8') // 'àôřb òf' **isMultibyte** +**wordWrap** + +**chars** $callback + +**words** $callback + +**paragraphs** + +**lines** + +**excerpt** ($str, $substring, $radius) + +**truncate** + +**pluralize** ($count, $singular, $plural = null) + +**at** $position + +**first** + +**last** + +**from** + +**to** + +**toBoolean** + +**ensureLeft** + +**ensureRight** + +**isAlpha** + +**isAlphaNumeric** + +**isUpper** + +**isLower** + +**isBlank** + +**length** + ## Tests [![Build Status](https://travis-ci.org/danielstjules/Stringy.png)](https://travis-ci.org/danielstjules/Stringy) diff --git a/src/Stringy/Stringy.php b/src/Stringy/Stringy.php index aee6d1d..65d8a8a 100644 --- a/src/Stringy/Stringy.php +++ b/src/Stringy/Stringy.php @@ -217,12 +217,12 @@ class Stringy /** * Trims the string and replaces consecutive whitespace characters with a - * single space. + * single space. This inclues tabs and newline characters. * * @param string $str The string to cleanup whitespace * @return string The trimmed string with condensed whitespace */ - public static function clean($str) + public static function collapseWhitespace($str) { return preg_replace('/\s+/u', ' ', trim($str)); } @@ -482,7 +482,7 @@ class Stringy public static function slugify($str) { $str = preg_replace('/[^a-zA-Z\d -]/u', '', self::standardize($str)); - $str = self::clean($str); + $str = self::collapseWhitespace($str); return str_replace(' ', '-', strtolower($str)); } @@ -551,7 +551,7 @@ class Stringy * @param string $encoding The character encoding * @return string The resulting string after truncating */ - public static function truncate($str, $length, $substring = '', + public static function safeTruncate($str, $length, $substring = '', $encoding = null) { $encoding = $encoding ?: mb_internal_encoding(); diff --git a/tests/Stringy/StringyTest.php b/tests/Stringy/StringyTest.php index d790269..bb4d0be 100644 --- a/tests/Stringy/StringyTest.php +++ b/tests/Stringy/StringyTest.php @@ -263,15 +263,15 @@ class StringyTestCase extends PHPUnit_Framework_TestCase } /** - * @dataProvider stringsForClean + * @dataProvider stringsForCollapseWhitespace */ - public function testClean($expected, $string) + public function testCollapseWhitespace($expected, $string) { - $result = S::clean($string); + $result = S::collapseWhitespace($string); $this->assertEquals($expected, $result); } - public function stringsForClean() + public function stringsForCollapseWhitespace() { $testData = array( array('foo bar', ' foo bar '), @@ -624,16 +624,16 @@ class StringyTestCase extends PHPUnit_Framework_TestCase } /** - * @dataProvider stringsForTruncate + * @dataProvider stringsForSafeTruncate */ - public function testTruncate($expected, $string, $length, $substring = '', + public function testSafeTruncate($expected, $string, $length, $substring = '', $encoding = null) { - $result = S::truncate($string, $length, $substring, $encoding); + $result = S::safeTruncate($string, $length, $substring, $encoding); $this->assertEquals($expected, $result); } - public function stringsForTruncate() + public function stringsForSafeTruncate() { $testData = array( array('Test foo bar', 'Test foo bar', 12),