From fa13bfb4bb9745311f8eec7a3457c3f3ae1c9f8a Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Wed, 10 Jul 2013 02:35:51 -0400 Subject: [PATCH] Start work on library --- LICENSE.txt | 19 ++++++ README.md | 106 ++++++++++++++++++++++++++++++- composer.json | 20 ++++++ phpunit.xml.dist | 11 ++++ src/Stringy/Stringy.php | 111 ++++++++++++++++++++++++++++++++ tests/Stringy/StringyTest.php | 116 ++++++++++++++++++++++++++++++++++ 6 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 LICENSE.txt create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/Stringy/Stringy.php create mode 100644 tests/Stringy/StringyTest.php diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..0b70302 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (C) 2013 Daniel St. Jules + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 51aba91..7183757 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,108 @@ Stringy ======= -A PHP library with a variety of string manipulation methods. +A PHP library with a variety of multibyte string manipulation functions. + +Usage +----- + +```php +use Stringy\Stringy as S; +``` + +**upperCaseFirst** + +S::upperCaseFirst($string [, $encoding]) + +Converts the first character of the supplied string to upper case, with +support for multibyte strings. + +```php +S::upperCaseFirst('σ test', 'UTF-8'); // 'Σ test' +``` + +**lowerCaseFirst** + +S::lowerCaseFirst($string [, $encoding]) + +Converts the first character of the supplied string to lower case, with +support for multibyte strings. + +```php +S::lowerCaseFirst('Σ test', 'UTF-8'); // 'σ test' +``` + +**camelize** + +S::camelize($string [, $encoding]) + +Returns a camelCase version of a supplied string, with multibyte support. +Trims surrounding spaces, capitalizes letters following digits, spaces, +dashes and underscores, and removes spaces, dashes, underscores. + +```php +S::camelize('Camel-Case'); // 'camelCase' +``` + +**upperCamelize** + +S::upperCamelize($string [, $encoding]) + +Returns an UpperCamelCase version of a supplied string, with multibyte +support. Trims surrounding spaces, capitalizes letters following digits, +spaces, dashes and underscores, and removes spaces, dashes, underscores. + +```php +S::upperCamelize('Upper Camel-Case'); // 'UpperCamelCase' +``` + +TODO +---- + +**dasherize** + +**underscored** + +**swapCase** + +**dashes** + +**underscores** + +**title** + +**sentence** + +**center** + +**endsWith** + +**beginsWith** + +**toSpaces** + +**toTabs** + +**slugify** + +**contains** + +**clean** + +**between** + +**insert** + +**nextChar** + +**truncateByChars** + +**truncateByWords** + +**longestCommonPrefix** + +**longestCommonSubstring** + +**isJson** + +**toAnchor** diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..325b3ae --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "danielstjules/Stringy", + "description": "A PHP library with a variety of multibyte string manipulation functions.", + "keywords": ["multibyte", "string", "manipulation", "utf-8", "helpers", "utils"], + "license": "MIT", + "authors": [ + { + "name": "Daniel St. Jules", + "email": "danielst.jules@gmail.com", + "homepage": "http://www.danielstjules.com" + } + ], + "minimum-stability": "stable", + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-0": { "Stringy": "src/" } + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..72c9345 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,11 @@ + + + + + + tests/Stringy + + + diff --git a/src/Stringy/Stringy.php b/src/Stringy/Stringy.php new file mode 100644 index 0000000..0636495 --- /dev/null +++ b/src/Stringy/Stringy.php @@ -0,0 +1,111 @@ + diff --git a/tests/Stringy/StringyTest.php b/tests/Stringy/StringyTest.php new file mode 100644 index 0000000..d4f9cae --- /dev/null +++ b/tests/Stringy/StringyTest.php @@ -0,0 +1,116 @@ +assertEquals($expected, $result); + } + + public function stringsForUpperCaseFirst() { + $testData = array( + array('Test', 'Test'), + array('test', 'Test'), + array('σ test', 'Σ test', 'UTF-8') + ); + + return $testData; + } + + /** + * @dataProvider stringsForLowerCaseFirst + */ + public function testLowerCaseFirst($string, $expected, $encoding = null) { + $result = S::lowerCaseFirst($string, $encoding); + $this->assertEquals($expected, $result); + } + + public function stringsForLowerCaseFirst() { + $testData = array( + array('Test', 'test'), + array('test', 'test'), + array('Σ test', 'σ test', 'UTF-8') + ); + + return $testData; + } + + /** + * @dataProvider stringsForCamelize + */ + public function testCamelize($string, $expected, $encoding = null) { + $result = S::camelize($string, $encoding); + $this->assertEquals($expected, $result); + } + + public function stringsForCamelize() { + $testData = array( + array('CamelCase', 'camelCase'), + array('Camel-Case', 'camelCase'), + array('camel case', 'camelCase'), + array('camel -case', 'camelCase'), + array('camel - case', 'camelCase'), + array('camel_case', 'camelCase'), + array('camel c test', 'camelCTest'), + array('string_with1number', 'stringWith1Number'), + array('string-with-2-2 numbers', 'stringWith22Numbers'), + array('camel σase', 'camelΣase', 'UTF-8'), + array('Σamel case', 'σamelCase', 'UTF-8'), + array('σamel Case', 'σamelCase', 'UTF-8') + ); + + return $testData; + } + + /** + * @dataProvider stringsForUpperCamelize + */ + public function testUpperCamelize($string, $expected, $encoding = null) { + $result = S::upperCamelize($string, $encoding); + $this->assertEquals($expected, $result); + } + + public function stringsForUpperCamelize() { + $testData = array( + array('camelCase', 'CamelCase'), + array('Camel-Case', 'CamelCase'), + array('camel case', 'CamelCase'), + array('camel -case', 'CamelCase'), + array('camel - case', 'CamelCase'), + array('camel_case', 'CamelCase'), + array('camel c test', 'CamelCTest'), + array('string_with1number', 'StringWith1Number'), + array('string-with-2-2 numbers', 'StringWith22Numbers'), + array('camel σase', 'CamelΣase', 'UTF-8'), + array('σamel case', 'ΣamelCase', 'UTF-8'), + array('Σamel Case', 'ΣamelCase', 'UTF-8') + ); + + return $testData; + } + +} + +?>