├── .coveralls.yml
├── .gitignore
├── .travis.yml
├── LICENSE.md
├── README.md
├── _config.yml
├── composer.json
├── phpunit.xml
├── src
├── Stringizer.php
└── Transformers
│ ├── Alpha.php
│ ├── AlphaNumeric.php
│ ├── AlphaNumericSpace.php
│ ├── AlphaNumericSpaceDash.php
│ ├── Ascii.php
│ ├── Base64.php
│ ├── Base64Check.php
│ ├── Between.php
│ ├── BooleanConverter.php
│ ├── CamelToSnake.php
│ ├── Camelize.php
│ ├── Chars.php
│ ├── ChopLeft.php
│ ├── ChopRight.php
│ ├── CollapseWhitespace.php
│ ├── Concat.php
│ ├── Contains.php
│ ├── Dasherize.php
│ ├── Date.php
│ ├── Decimal.php
│ ├── Email.php
│ ├── EmptyCheck.php
│ ├── EndsWith.php
│ ├── EnsureLeft.php
│ ├── EnsureRight.php
│ ├── Hash.php
│ ├── HashCode.php
│ ├── HexColor.php
│ ├── HexDecimal.php
│ ├── IndexOf.php
│ ├── Ipv4.php
│ ├── Ipv6.php
│ ├── Isbn.php
│ ├── Join.php
│ ├── Json.php
│ ├── LastIndexOf.php
│ ├── Latitude.php
│ ├── Length.php
│ ├── Longitude.php
│ ├── Lowercase.php
│ ├── LowercaseCheck.php
│ ├── LowercaseFirst.php
│ ├── MultiByte.php
│ ├── Number.php
│ ├── Pad.php
│ ├── Random.php
│ ├── RemoveNonAscii.php
│ ├── RemoveWhitespace.php
│ ├── Repeat.php
│ ├── Replace.php
│ ├── ReplaceAccents.php
│ ├── Reverse.php
│ ├── RgbColor.php
│ ├── Semver.php
│ ├── SentenceCount.php
│ ├── Split.php
│ ├── StartsWith.php
│ ├── StringFindPosition.php
│ ├── StringFirstOccurrence.php
│ ├── StripPunctuation.php
│ ├── StripTags.php
│ ├── SubString.php
│ ├── SubStringCount.php
│ ├── SwapCase.php
│ ├── Transformer.php
│ ├── TransformerCaseInsensitive.php
│ ├── TransformerInterface.php
│ ├── Trim.php
│ ├── TrimLeft.php
│ ├── TrimRight.php
│ ├── Truncate.php
│ ├── TruncateMatch.php
│ ├── Uppercase.php
│ ├── UppercaseCheck.php
│ ├── UppercaseFirst.php
│ ├── UppercaseWords.php
│ ├── Url.php
│ ├── Width.php
│ └── WordCount.php
└── tests
├── AlphaNumericSpaceDashTest.php
├── AlphaNumericSpaceTest.php
├── AlphaNumericTest.php
├── AlphaTest.php
├── AsciiTest.php
├── Base64Test.php
├── BetweenTest.php
├── BlankTest.php
├── CamelToSnakeTest.php
├── CamelizeTest.php
├── CharsTest.php
├── ChartAtTest.php
├── ChopLeftTest.php
├── ChopRightTest.php
├── CollapseWhitespaceTest.php
├── ConcatTest.php
├── ContainsCountTest.php
├── ContainsTest.php
├── DasherizeTest.php
├── DateTest.php
├── DecimalTest.php
├── DeleteTest.php
├── EmailTest.php
├── EmptyTest.php
├── EndsWithTest.php
├── EnsureLeftTest.php
├── EnsureRightTest.php
├── FirstTest.php
├── HasLowercaseTest.php
├── HasUppercaseTest.php
├── HashCodeTest.php
├── HashTest.php
├── HexColorTest.php
├── HexDecimalTest.php
├── IndexOfTest.php
├── Ipv4Test.php
├── Ipv6Test.php
├── IsbnTest.php
├── JoinTest.php
├── JsonTest.php
├── LastIndexOfTest.php
├── LastTest.php
├── LatitudeTest.php
├── LengthTest.php
├── LineCountTest.php
├── LongitudeTest.php
├── LowercaseFirstTest.php
├── LowercaseTest.php
├── MultiByteTest.php
├── NumberTest.php
├── PadTest.php
├── RandomTest.php
├── RemoveNonAsciiTest.php
├── RemoveWhitespaceTest.php
├── RepeatTest.php
├── ReplaceAccentsTest.php
├── ReplaceTest.php
├── ReverseTest.php
├── RgbColorTest.php
├── SemverTest.php
├── SentenceCountTest.php
├── SplitTest.php
├── StartsWithTest.php
├── StringizerTest.php
├── StripPunctuationTest.php
├── StripTagsTest.php
├── SubStringTest.php
├── SwapTest.php
├── ToBooleanTest.php
├── TransformerTest.php
├── TrimLeftTest.php
├── TrimRightTest.php
├── TrimTest.php
├── TruncateMatchTest.php
├── TruncateTest.php
├── UppercaseFirstTest.php
├── UppercaseTest.php
├── UppercaseWordTest.php
├── UrlTest.php
├── WidthTest.php
└── WordCountTest.php
/.coveralls.yml:
--------------------------------------------------------------------------------
1 | coverage_clover: build/logs/clover.xml
2 | json_path: build/logs/coveralls-upload.json
3 | service_name: travis-ci
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.lock
3 | .settings
4 | .project
5 | .buildpath
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.6
5 | - 7.0
6 | - 7.1
7 | - 7.2
8 | - 7.4
9 | # Use the newer stack for HHVM as HHVM does not support Precise
10 | #- php: hhvm
11 | # sudo: required
12 | # dist: trusty
13 | # group: edge
14 |
15 | before_install:
16 | #- composer require phpunit/phpunit:4.8.* satooshi/php-coveralls:dev-master
17 | - composer require phpunit/phpunit:4.8.* php-coveralls/php-coveralls '^2.0'
18 | - composer install --dev
19 |
20 | script:
21 | - mkdir -p build/logs && ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
22 |
23 | after_script:
24 | - php vendor/bin/coveralls -v
25 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Jason Lam
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
2 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jasonlam604/stringizer",
3 | "type": "library",
4 | "description": "Stringizer is a PHP string manipulation library with support for method chaining and multibyte handling",
5 | "keywords": ["laravel","library","toolkit","string","manipulation","chaining","multibyte","php","transformer","stringizer"],
6 | "license": "MIT",
7 | "homepage": "http://jasonlam604.github.io/Stringizer/",
8 | "authors": [
9 | {
10 | "name": "Jason Lam",
11 | "email": "jasonlam604@gmail.com"
12 | }
13 | ],
14 | "require": {
15 | "php": ">=5.6.0",
16 | "cocur/slugify" : "3.2.*"
17 |
18 | },
19 | "require-dev": {
20 | "phpunit/phpunit": "5.3.*"
21 | },
22 | "autoload": {
23 | "psr-4": {
24 | "Stringizer\\": "src"
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
17 |
18 | ./tests/
19 |
20 |
21 |
22 |
23 |
24 | ./src/
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/Stringizer.php:
--------------------------------------------------------------------------------
1 | setString($stringValue);
121 |
122 | if (empty($encoding))
123 | $encoding = \mb_internal_encoding();
124 |
125 | $this->setEncoding($encoding);
126 | }
127 |
128 | public function base64Encode()
129 | {
130 | $this->value = (new Base64($this->value))->execute();
131 | return $this;
132 | }
133 |
134 | public function base64Decode()
135 | {
136 | $this->value = (new Base64($this->value,true))->execute();
137 | return $this;
138 | }
139 |
140 | public function camelize()
141 | {
142 | $this->value = (new Camelize($this->value))->execute();
143 | return $this;
144 | }
145 |
146 | public function camelToSnake()
147 | {
148 | $this->value = (new CamelToSnake($this->value))->execute();
149 | return $this;
150 | }
151 |
152 | public function charAt($index)
153 | {
154 | $this->value = (new SubString($this->value,$index,1))->execute();
155 | return $this;
156 | }
157 |
158 | public function chars()
159 | {
160 | return $this->value = (new Chars($this->value))->execute();
161 | }
162 |
163 | /**
164 | * @deprecated Since 2.8.0 named incorrectly see chopLeft
165 | */
166 | public function chompLeft($prefix)
167 | {
168 | $this->value = (new ChopLeft($this->value,$prefix))->execute();
169 | return $this;
170 | }
171 |
172 | /**
173 | * @deprecated Since 2.8.0 named incorrectly see chopRight
174 | */
175 | public function chompRight($prefix)
176 | {
177 | $this->value = (new ChopRight($this->value,$prefix))->execute();
178 | return $this;
179 | }
180 |
181 | public function chopLeft($prefix)
182 | {
183 | $this->value = (new ChopLeft($this->value,$prefix))->execute();
184 | return $this;
185 | }
186 |
187 | public function chopRight($prefix)
188 | {
189 | $this->value = (new ChopRight($this->value,$prefix))->execute();
190 | return $this;
191 | }
192 |
193 | public function collapseWhitespace()
194 | {
195 | $this->value = (new CollapseWhitespace($this->value))->execute();
196 | return $this;
197 | }
198 |
199 | /**
200 | * Append 2 String values
201 | *
202 | * @param string $value
203 | *
204 | * @param string $preAppend
205 | * flag when true to prepend value
206 | *
207 | * @return \Stringizer\Stringizer
208 | */
209 | public function concat($value, $preAppend = false)
210 | {
211 | $transformer = new Concat($this->value, $value);
212 | $transformer->setPreAppend($preAppend);
213 | $this->value = $transformer->execute();
214 | return $this;
215 | }
216 |
217 | public function between($left,$right)
218 | {
219 | $this->value = (new Between($this->value,$left,$right))->execute();
220 | return $this;
221 | }
222 |
223 | public function contains($needle)
224 | {
225 | return (new Contains($this->value, $needle))->execute();
226 | }
227 |
228 | public function containsIncaseSensitive($needle)
229 | {
230 | return (new Contains($this->value, $needle))->enableCaseInsensitive()->execute();
231 | }
232 |
233 | public function containsCount($needle)
234 | {
235 | return (new SubStringCount($this->value, $needle))->execute();
236 | }
237 |
238 | public function containsCountIncaseSensitive($needle)
239 | {
240 | return (new SubStringCount($this->value, $needle))->enableCaseInsensitive()->execute();
241 | }
242 |
243 | public function dasherize()
244 | {
245 | $this->value = (new Dasherize($this->value))->execute();
246 | return $this;
247 | }
248 |
249 | /**
250 | * Delete runes in str matching the pattern, similiar in Ruby
251 | *
252 | * Simple wrapper to Replace
253 | *
254 | * @param string or array $needles
255 | * @return \Stringizer\Stringizer
256 | */
257 | public function delete($needles)
258 | {
259 | $this->value = (new Replace($this->value, $needles, ""))->execute();
260 | return $this;
261 | }
262 |
263 | public function endsWith($needle)
264 | {
265 | return (new EndsWith($this->value, $needle))->execute();
266 | }
267 |
268 | public function ensureLeft($prefix)
269 | {
270 | $this->value = (new EnsureLeft($this->value, $prefix))->execute();
271 | return $this;
272 | }
273 |
274 | public function ensureRight($suffix)
275 | {
276 | $this->value = (new EnsureRight($this->value, $suffix))->execute();
277 | return $this;
278 | }
279 |
280 | public function first($numberOfCharacters)
281 | {
282 | $this->value = (new SubString($this->value, 0, $numberOfCharacters))->execute();
283 | return $this;
284 | }
285 |
286 | public function hashCode()
287 | {
288 | $this->value = (string) (new HashCode($this->value))->execute();
289 | return $this;
290 | }
291 |
292 | public function hasLowercase()
293 | {
294 | return (new LowercaseCheck($this->value))->execute();
295 | }
296 |
297 | public function hasUppercase()
298 | {
299 | return (new UppercaseCheck($this->value))->execute();
300 | }
301 |
302 | public function indexOf($needle, $offset = 0)
303 | {
304 | return (new IndexOf($this->value, $needle, $offset))->execute();
305 | }
306 |
307 | public function indexOfCaseInsensitive($needle, $offset = 0)
308 | {
309 | return (new IndexOf($this->value, $needle, $offset))->enableCaseInsensitive()->execute();
310 | }
311 |
312 | public function isAlpha()
313 | {
314 | return (new Alpha($this->value))->execute();
315 | }
316 |
317 | public function isAlphaNumeric()
318 | {
319 | return (new AlphaNumeric($this->value))->execute();
320 | }
321 |
322 | public function isAlphaNumericSpace()
323 | {
324 | return (new AlphaNumericSpace($this->value))->execute();
325 | }
326 |
327 | public function isAlphaNumericSpaceDash()
328 | {
329 | return (new AlphaNumericSpaceDash($this->value))->execute();
330 | }
331 |
332 | public function isAscii($isPrintableOnly=false)
333 | {
334 | return (new Ascii($this->value,$isPrintableOnly))->execute();
335 | }
336 |
337 | public function isBase64()
338 | {
339 | return (new Base64Check($this->value))->execute();
340 | }
341 |
342 | /**
343 | * Alias for isEmpty
344 | */
345 | public function isBlank()
346 | {
347 | return (new EmptyCheck($this->value))->execute();
348 | }
349 |
350 | public function isDate()
351 | {
352 | return (new Date($this->value))->execute();
353 | }
354 |
355 | public function isDecimal()
356 | {
357 | return (new Decimal($this->value))->execute();
358 | }
359 |
360 | public function isEmail()
361 | {
362 | return (new Email($this->value))->execute();
363 | }
364 |
365 | public function isEmpty()
366 | {
367 | return (new EmptyCheck($this->value))->execute();
368 | }
369 |
370 | public function isHash($hashAlgorithm)
371 | {
372 | return (new Hash($this->value,$hashAlgorithm))->execute();
373 | }
374 |
375 | public function isHexColor()
376 | {
377 | return (new HexColor($this->value))->execute();
378 | }
379 |
380 | public function isHexDecimal()
381 | {
382 | return (new HexDecimal($this->value))->execute();
383 | }
384 |
385 | public function isIsbn10() {
386 | return (new Isbn($this->value))->execute();
387 | }
388 |
389 | public function isIsbn13() {
390 | $isbn = new Isbn($this->value);
391 | $isbn->checkIsbn13();
392 | return $isbn->execute();
393 | }
394 |
395 | public function isIpv4()
396 | {
397 | return (new Ipv4($this->value))->execute();
398 | }
399 |
400 | public function isIpv6()
401 | {
402 | return (new Ipv6($this->value))->execute();
403 | }
404 |
405 | public function isJson()
406 | {
407 | return (new Json($this->value))->execute();
408 | }
409 |
410 | public function isLatitude()
411 | {
412 | return (new Latitude($this->value))->execute();
413 | }
414 |
415 | public function isLongitude()
416 | {
417 | return (new Longitude($this->value))->execute();
418 | }
419 |
420 | public function isMultiByte()
421 | {
422 | return (new MultiByte($this->value))->execute();
423 | }
424 |
425 | public function isNumber()
426 | {
427 | return (new Number($this->value))->execute();
428 | }
429 |
430 | public function isRgbColor()
431 | {
432 | return (new RgbColor($this->value))->execute();
433 | }
434 |
435 | public function isSemver()
436 | {
437 | return (new Semver($this->value))->execute();
438 | }
439 |
440 | public function isUrl($santize=false)
441 | {
442 | return (new Url($this->value,$santize))->execute();
443 | }
444 |
445 | public function join($values,$separator=",")
446 | {
447 | $this->value = (new Join($values,$separator))->execute();
448 | return $this;
449 | }
450 |
451 | public function last($numberOfCharacters)
452 | {
453 | $this->value = (new SubString($this->value, ($this->length() - $numberOfCharacters)))->execute();
454 | return $this;
455 | }
456 |
457 | public function lastIndexOf($needle, $offset = 0)
458 | {
459 | return (new LastIndexOf($this->value, $needle, $offset))->execute();
460 | }
461 |
462 | public function lastIndexOfCaseInsensitive($needle, $offset = 0)
463 | {
464 | return (new LastIndexOf($this->value, $needle, $offset, true))->enableCaseInsensitive()->execute();
465 | }
466 |
467 | public function lineCount()
468 | {
469 | return (new SubStringCount($this->value,"\n"))->execute();
470 | }
471 |
472 | /**
473 | * Length
474 | *
475 | * @return int length of string
476 | */
477 | public function length()
478 | {
479 | return (new Length($this->value))->execute();
480 | }
481 |
482 | /**
483 | * Convert entire sgring to lowercase
484 | *
485 | * @return \Stringizer\Stringizer
486 | */
487 | public function lowercase()
488 | {
489 | $this->value = (new Lowercase($this->value))->execute();
490 | return $this;
491 | }
492 |
493 | public function lowercaseFirst($ignoreUppercaseFirst = false)
494 | {
495 | if (! $ignoreUppercaseFirst) {
496 | $this->value = (new Uppercase($this->value))->execute();
497 | }
498 | $this->value = (new LowercaseFirst($this->value))->execute();
499 | return $this;
500 | }
501 |
502 | public function padBoth($padValue, $padAmount)
503 | {
504 | $this->value = (new Pad($this->value, $padValue, $padAmount, STR_PAD_BOTH))->execute();
505 | return $this;
506 | }
507 |
508 | public function padLeft($padValue, $padAmount)
509 | {
510 | $this->value = (new Pad($this->value, $padValue, $padAmount, STR_PAD_LEFT))->execute();
511 | return $this;
512 | }
513 |
514 | public function padRight($padValue, $padAmount)
515 | {
516 | $this->value = (new Pad($this->value, $padValue, $padAmount, STR_PAD_RIGHT))->execute();
517 | return $this;
518 | }
519 |
520 | public function randomAlpha($length=10)
521 | {
522 | $this->value = (new Random(Random::$RANDOM_ALPHA,$length))->execute();
523 | return $this;
524 | }
525 |
526 | public function randomNumeric($length=10)
527 | {
528 | $this->value = (new Random(Random::$RANDOM_NUMERIC,$length))->execute();
529 | return $this;
530 | }
531 |
532 | public function randomAlphanumeric($length=10)
533 | {
534 | $this->value = (new Random(Random::$RANDOM_ALPHA_NUMERIC,$length))->execute();
535 | return $this;
536 | }
537 |
538 | public function repeat($repeatNumber)
539 | {
540 | $this->value = (new Repeat($this->value, $repeatNumber))->execute();
541 | return $this;
542 | }
543 |
544 | public function replace($needles, $replacements)
545 | {
546 | $this->value = (new Replace($this->value, $needles, $replacements))->execute();
547 | return $this;
548 | }
549 |
550 | public function replaceIncaseSensitive($needles, $replacements)
551 | {
552 | $this->value = (new Replace($this->value, $needles, $replacements))->enableCaseInsensitive()->execute();
553 | return $this;
554 | }
555 |
556 | public function replaceAccents()
557 | {
558 | $this->value = (new ReplaceAccents($this->value))->execute();
559 | return $this;
560 | }
561 |
562 | public function removeNonAscii()
563 | {
564 | $this->value = (new RemoveNonAscii($this->value))->execute();
565 | return $this;
566 | }
567 |
568 | public function removeWhitespace()
569 | {
570 | $this->value = (new RemoveWhitespace($this->value))->execute();
571 | return $this;
572 | }
573 |
574 | public function reverse()
575 | {
576 | $this->value = (new Reverse($this->value))->execute();
577 | return $this;
578 | }
579 |
580 | public function sentenceCount()
581 | {
582 | return (new SentenceCount($this->value))->execute();
583 | }
584 |
585 | public function startsWith($needle)
586 | {
587 | return (new StartsWith($this->value, $needle))->execute();
588 | }
589 |
590 | public function stripPunctuation()
591 | {
592 | $this->value = (new StripPunctuation($this->value))->execute();
593 | return $this;
594 | }
595 |
596 | public function stripTags($allowableTags = '')
597 | {
598 | $this->value = (new StripTags($this->value, $allowableTags))->execute();
599 | return $this;
600 | }
601 |
602 | public function split($delimiter = ",")
603 | {
604 | return (new Split($this->value, $delimiter))->execute();
605 | }
606 |
607 | public function subString($start, $length = null)
608 | {
609 | $this->value = (new SubString($this->value, $start, $length))->execute();
610 | return $this;
611 | }
612 |
613 | public function swapCase()
614 | {
615 | $this->value = (new SwapCase($this->value))->execute();
616 | return $this;
617 | }
618 |
619 | public function toBoolean()
620 | {
621 | return (new BooleanConverter($this->value))->execute();
622 | }
623 |
624 | public function trim()
625 | {
626 | $this->value = (new Trim($this->value))->execute();
627 | return $this;
628 | }
629 |
630 | public function trimRight()
631 | {
632 | $this->value = (new TrimRight($this->value))->execute();
633 | return $this;
634 | }
635 |
636 | public function trimLeft()
637 | {
638 | $this->value = (new TrimLeft($this->value))->execute();
639 | return $this;
640 | }
641 |
642 | /**
643 | * Truncate remove the number of indicated values at the end of the string
644 | *
645 | * @param int $numberToTruncate
646 | *
647 | * @throws \InvalidArgumentException
648 | *
649 | * @return \Stringizer\Stringizer
650 | */
651 | public function truncate($numberToTruncate)
652 | {
653 | $this->value = (new Truncate($this->value, $numberToTruncate))->execute();
654 | return $this;
655 | }
656 |
657 | public function truncateMatch($stringToMatch, $truncateBefore = false)
658 | {
659 | $result = (new TruncateMatch($this->value, $stringToMatch, ! $truncateBefore))->execute();
660 | if ($result === FALSE) {
661 | return $result;
662 | } else {
663 | $this->value = $result;
664 | return $this;
665 | }
666 | }
667 |
668 | public function truncateMatchCaseInsensitive($stringToMatch, $truncateBefore = false)
669 | {
670 | $result = (new TruncateMatch($this->value, $stringToMatch, ! $truncateBefore))->enableCaseInsensitive()->execute();
671 | if ($result === FALSE) {
672 | return $result;
673 | } else {
674 | $this->value = $result;
675 | return $this;
676 | }
677 | }
678 |
679 | public function uppercase()
680 | {
681 | $this->value = (new Uppercase($this->value))->execute();
682 | return $this;
683 | }
684 |
685 | public function uppercaseWords()
686 | {
687 | $this->value = (new UppercaseWords((new Lowercase($this->value))->execute()))->execute();
688 | return $this;
689 | }
690 |
691 | public function uppercaseFirst($ignoreLowercaseFirst = false)
692 | {
693 | if (! $ignoreLowercaseFirst) {
694 | $this->value = (new Lowercase($this->value))->execute();
695 | }
696 | $this->value = (new UppercaseFirst($this->value))->execute();
697 | return $this;
698 | }
699 |
700 | public function width()
701 | {
702 | return (new Width($this->value))->execute();
703 | }
704 |
705 | public function wordCount()
706 | {
707 | return (new WordCount($this->value))->execute();
708 | }
709 |
710 | public function setEncoding($encoding)
711 | {
712 | if (! isset($encoding))
713 | throw new \Exception("Given encoding value not valid");
714 |
715 | $this->encoding = $encoding;
716 |
717 | mb_internal_encoding($this->encoding);
718 | }
719 |
720 | public function getEncoding()
721 | {
722 | return $this->encoding;
723 | }
724 |
725 | public function getStringOriginal()
726 | {
727 | return $this->valueOriginal;
728 | }
729 |
730 | public function setString($stringValue)
731 | {
732 |
733 | if (!isset($stringValue)) {
734 | throw new \InvalidArgumentException("Given value is null not a string");
735 | } elseif (is_array($stringValue)) {
736 | throw new \InvalidArgumentException("Given value is an array not a string");
737 | } elseif (is_object($stringValue) && ! method_exists($stringValue, "__toString")) {
738 | throw new \InvalidArgumentException("Given object does not have a __toString method");
739 | }
740 |
741 | $this->value = (string) $stringValue;
742 |
743 | $this->valueOriginal = $this->value;
744 | }
745 |
746 | public function getString()
747 | {
748 | return $this->__toString();
749 | }
750 |
751 | public function __toString()
752 | {
753 | return $this->value;
754 | }
755 | }
756 |
--------------------------------------------------------------------------------
/src/Transformers/Alpha.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/AlphaNumeric.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/AlphaNumericSpace.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/AlphaNumericSpaceDash.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Ascii.php:
--------------------------------------------------------------------------------
1 | pattern = '/^[\x20-\x7E]+$/';
22 | } else {
23 | $this->pattern = '/^[\x00-\x7F]+$/';
24 | }
25 | }
26 |
27 | public function execute()
28 | {
29 | // if (preg_match('/^[\x00-\x7F]+$/', $this->getValue())) {
30 | if (preg_match($this->pattern, $this->getValue())) {
31 | return true;
32 | } else {
33 | return false;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Transformers/Base64.php:
--------------------------------------------------------------------------------
1 | decode = $decode;
23 | }
24 |
25 | public function execute()
26 | {
27 | if ($this->decode) {
28 | return base64_decode($this->getValue());
29 | } else {
30 | return base64_encode($this->getValue());
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Transformers/Base64Check.php:
--------------------------------------------------------------------------------
1 | getValue())) {
24 | return true;
25 | } else {
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Transformers/Between.php:
--------------------------------------------------------------------------------
1 | left = $left;
21 | $this->right = $right;
22 | }
23 |
24 | public function execute()
25 | {
26 | $str = $this->getValue();
27 |
28 | if (mb_substr($this->getValue(), 0, mb_strlen($this->left)) == $this->left) {
29 | $str = mb_substr($this->getValue(), mb_strlen($this->left));
30 | }
31 |
32 | if(mb_substr($this->getValue(), mb_strlen($this->getValue()) - mb_strlen($this->right), mb_strlen($this->right)) == $this->right) {
33 | $str = mb_substr($str, 0, mb_strlen($str) - mb_strlen($this->right));
34 | }
35 |
36 | return $str;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Transformers/BooleanConverter.php:
--------------------------------------------------------------------------------
1 | getValue();
22 |
23 | if (is_bool($val) === true) {
24 | // value is a boolean, return the contained boolean valu
25 | return $val;
26 |
27 | } else if (is_string($val)) {
28 |
29 | // value is string return string if it contains 'yes', 'true' or 'on' (case insensitive)
30 | $val = mb_strtolower($val);
31 | if ($val == 'true' || $val == 'yes' || $val == 'on' || $val == '1') {
32 | return true;
33 | } else {
34 | return false;
35 | }
36 |
37 | } else if ($val == 1) {
38 | // only numeric value that will return boolean 'true' is 1
39 | return true;
40 | } else {
41 | // Everything is boolean 'false'
42 | return false;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Transformers/CamelToSnake.php:
--------------------------------------------------------------------------------
1 | getValue()));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Transformers/Camelize.php:
--------------------------------------------------------------------------------
1 | getValue());
24 | $s->replace(array(
25 | "_",
26 | "-"
27 | ), array(
28 | " ",
29 | " "
30 | ))
31 | ->lowercase()
32 | ->uppercaseWords()
33 | ->replace(" ", "")
34 | ->lowercaseFirst(true);
35 | return $s->getString();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Transformers/Chars.php:
--------------------------------------------------------------------------------
1 | getValue(), - 1, PREG_SPLIT_NO_EMPTY);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Transformers/ChopLeft.php:
--------------------------------------------------------------------------------
1 | prefix = $prefix;
20 | }
21 |
22 | public function execute()
23 | {
24 | $str = $this->getValue();
25 |
26 | if (mb_substr($this->getValue(), 0, mb_strlen($this->prefix)) == $this->prefix) {
27 | $str = mb_substr($this->getValue(), mb_strlen($this->prefix));
28 | }
29 |
30 | return $str;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Transformers/ChopRight.php:
--------------------------------------------------------------------------------
1 | suffix = $suffix;
20 | }
21 |
22 | public function execute()
23 | {
24 | $str = $this->getValue();
25 |
26 | if (mb_substr($this->getValue(), mb_strlen($this->getValue()) - mb_strlen($this->suffix), mb_strlen($this->suffix)) == $this->suffix) {
27 | $str = mb_substr($str, 0, mb_strlen($str) - mb_strlen($this->suffix));
28 | }
29 |
30 | return $str;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Transformers/CollapseWhitespace.php:
--------------------------------------------------------------------------------
1 | getValue()));
24 | return $s->trim()->getString();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/Concat.php:
--------------------------------------------------------------------------------
1 | appendValue = $appendValue;
32 | $this->setPreAppend(false);
33 | }
34 |
35 | /**
36 | * Set flag indicator to pre-append value when true
37 | *
38 | * @param boolean $isPreAppend
39 | */
40 | public function setPreAppend($isPreAppend)
41 | {
42 | $this->isPreAppend = $isPreAppend;
43 | }
44 |
45 | /**
46 | * Append or Pre-append $appendValue with $value
47 | */
48 | public function execute()
49 | {
50 | if (! isset($this->appendValue) || empty($this->appendValue)) {
51 | if ($this->isPreAppend)
52 | throw new \InvalidArgumentException("Missing value to preappend with");
53 | else
54 | throw new \InvalidArgumentException("Missing value to concat with");
55 | }
56 |
57 | if ($this->isPreAppend)
58 | return $this->appendValue . $this->getValue();
59 | else
60 | return $this->getValue() . $this->appendValue;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Transformers/Contains.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
22 | }
23 |
24 | public function execute()
25 | {
26 | if ($this->isCaseInsensitive()) {
27 |
28 | if ((new StringFindPosition($this->getValue(), $this->needle))->enableCaseInsensitive()->execute()) {
29 | return true;
30 | } else {
31 | return false;
32 | }
33 | } else {
34 |
35 | if ((new StringFindPosition($this->getValue(), $this->needle))->execute()) {
36 | return true;
37 | } else {
38 | return false;
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Transformers/Dasherize.php:
--------------------------------------------------------------------------------
1 | hello-world-again
8 | *
9 | * Regex Split by Capital letters Solution from here http://stackoverflow.com/questions/8998382/php-explode-at-capital-letters
10 | *
11 | * @link https://github.com/jasonlam604/Stringizer
12 | * @copyright Copyright (c) 2016 Jason Lam
13 | * @license https://github.com/jasonlam604/Stringizer/blob/master/LICENSE.md (MIT License)
14 | */
15 | class Dasherize extends Transformer implements TransformerInterface
16 | {
17 |
18 | public function __construct($value)
19 | {
20 | parent::__construct($value);
21 | }
22 |
23 | public function execute()
24 | {
25 | preg_match_all('((?:^|[A-Z])[^A-Z]*)', $this->getValue(), $matches);
26 |
27 | return mb_strtolower(implode("-", $matches[0]));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Transformers/Date.php:
--------------------------------------------------------------------------------
1 | getValue()) !== FALSE) {
26 | return true;
27 | } else {
28 | return false;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Transformers/Decimal.php:
--------------------------------------------------------------------------------
1 | getValue(), FILTER_VALIDATE_FLOAT) !== false) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Email.php:
--------------------------------------------------------------------------------
1 | getValue(), FILTER_VALIDATE_EMAIL) !== FALSE) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/EmptyCheck.php:
--------------------------------------------------------------------------------
1 | getValue());
24 | $s->removeWhitespace();
25 |
26 | return empty(trim($s->getString()));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Transformers/EndsWith.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
21 | }
22 |
23 | /**
24 | * EndsWith
25 | */
26 | public function execute()
27 | {
28 | return (mb_substr($this->getValue(), - (mb_strlen($this->needle))) === $this->needle);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Transformers/EnsureLeft.php:
--------------------------------------------------------------------------------
1 | prefix = $prefix;
22 | }
23 |
24 | public function execute()
25 | {
26 | $s = new Stringizer($this->getValue());
27 | if ($s->startsWith($this->prefix)) {
28 | return $this->getValue();
29 | } else {
30 | return $this->prefix . $this->getValue();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Transformers/EnsureRight.php:
--------------------------------------------------------------------------------
1 | suffix = $suffix;
22 | }
23 |
24 | public function execute()
25 | {
26 | $s = new Stringizer($this->getValue());
27 | if ($s->endsWith($this->suffix)) {
28 | return $this->getValue();
29 | } else {
30 | return $this->getValue() . $this->suffix;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Transformers/Hash.php:
--------------------------------------------------------------------------------
1 | len = 0;
23 |
24 | $algo = mb_strtolower($hashAlgorithm);
25 |
26 | if ($algo == "crc32" || $algo == "crc32b") {
27 | $this->len = "8";
28 | } elseif ($algo == "md5" || $algo == "md4" || $algo == "ripemd128" || $algo == "tiger128") {
29 | $this->len = "32";
30 | } elseif ($algo == "sha1" || $algo == "ripemd160" || $algo == "tiger160") {
31 | $this->len = "40";
32 | } elseif ($algo == "tiger192") {
33 | $this->len = "48";
34 | } elseif ($algo == "sha256") {
35 | $this->len = "64";
36 | } elseif ($algo == "sha384") {
37 | $this->len = "96";
38 | } elseif ($algo == "sha512") {
39 | $this->len = "128";
40 | } else {
41 | return false;
42 | }
43 | }
44 |
45 | public function execute()
46 | {
47 | $pattern = '/^[0-9a-f]{'. $this->len .'}$/i';
48 |
49 | if (preg_match($pattern, $this->getValue())) {
50 | return true;
51 | } else {
52 | return false;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Transformers/HashCode.php:
--------------------------------------------------------------------------------
1 | hashCode($this->getValue());
27 | }
28 |
29 | private function hashCode($s)
30 | {
31 | $h = 0;
32 | $len = strlen($s);
33 |
34 | for ($i = 0; $i < $len; $i ++) {
35 | $h = $this->overflow32(31 * $h + ord($s[$i]));
36 | }
37 |
38 | return $h;
39 | }
40 |
41 | private function overflow32($v)
42 | {
43 | $v = $v % 4294967296;
44 |
45 | if ($v > 2147483647)
46 | return $v - 4294967296;
47 | elseif ($v < - 2147483648)
48 | return $v + 4294967296;
49 | else
50 | return $v;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Transformers/HexColor.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/HexDecimal.php:
--------------------------------------------------------------------------------
1 | getValue())) {
24 | return true;
25 | } else {
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Transformers/IndexOf.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
24 | $this->fromIndex = $fromIndex;
25 | }
26 |
27 | /**
28 | * IndexOf
29 | */
30 | public function execute()
31 | {
32 | if ($this->isCaseInsensitive())
33 | return mb_stripos($this->getValue(), $this->needle, $this->fromIndex);
34 | else
35 | return mb_strpos($this->getValue(), $this->needle, $this->fromIndex);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Transformers/Ipv4.php:
--------------------------------------------------------------------------------
1 | getValue(), FILTER_VALIDATE_IP) !== FALSE) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Ipv6.php:
--------------------------------------------------------------------------------
1 | getValue(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Isbn.php:
--------------------------------------------------------------------------------
1 | isCheckIsbn13 = false;
23 | }
24 |
25 | public function checkIsbn13()
26 | {
27 | $this->isCheckIsbn13 = true;
28 | }
29 |
30 | public function execute()
31 | {
32 | if ($this->isCheckIsbn13) {
33 | if ($this->findIsbn($this->getValue()) == 2)
34 | return true;
35 | else
36 | return false;
37 | } else {
38 | if ($this->findIsbn($this->getValue()) == 1)
39 | return true;
40 | else
41 | return false;
42 | }
43 | }
44 |
45 | private function findIsbn($str)
46 | {
47 | $regex = '/\b(?:ISBN(?:: ?| ))?((?:97[89])?\d{9}[\dx])\b/i';
48 |
49 | // 1 = ISBN-10
50 | // 2 = ISBN-13
51 | if (preg_match($regex, str_replace('-', '', $str), $matches)) {
52 | return (10 === strlen($matches[1])) ? 1 : 2;
53 | }
54 | return 0; // No valid ISBN found
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Transformers/Join.php:
--------------------------------------------------------------------------------
1 | arrayValues = $value;
25 | $this->separator = $separator;
26 | }
27 |
28 | public function execute()
29 | {
30 | if (is_array($this->arrayValues)) {
31 | return implode($this->separator, $this->arrayValues);
32 | } else {
33 | throw new \InvalidArgumentException("Value given is not an array");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Transformers/Json.php:
--------------------------------------------------------------------------------
1 | getValue(), true);
22 |
23 | return !empty($this->getValue()) && is_string($this->getValue()) && is_array($array) && !empty($array) && json_last_error() == 0;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Transformers/LastIndexOf.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
24 | $this->fromIndex = $fromIndex;
25 | }
26 |
27 | /**
28 | * LastIndexOf
29 | */
30 | public function execute()
31 | {
32 | if ($this->isCaseInsensitive())
33 | return mb_strripos($this->getValue(), $this->needle, $this->fromIndex);
34 | else
35 | return mb_strrpos($this->getValue(), $this->needle, $this->fromIndex);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Transformers/Latitude.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Length.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/Longitude.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Lowercase.php:
--------------------------------------------------------------------------------
1 | getValue(), \mb_internal_encoding());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/LowercaseCheck.php:
--------------------------------------------------------------------------------
1 | getValue());
24 | $s->replaceAccents();
25 | return ctype_lower($s->getString());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/LowercaseFirst.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/MultiByte.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Number.php:
--------------------------------------------------------------------------------
1 | getValue(), FILTER_VALIDATE_INT) !== FALSE) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/Pad.php:
--------------------------------------------------------------------------------
1 | padValue = $padValue;
29 |
30 | $this->padType = $padType;
31 |
32 | $this->padAmount = $padAmount;
33 | }
34 |
35 | /**
36 | * Pad
37 | */
38 | public function execute()
39 | {
40 | return $this->mbStrPad($this->getValue(), $this->padAmount, $this->padValue, $this->padType);
41 | }
42 |
43 | /**
44 | * Code from http://php.net/manual/en/function.str-pad.php
45 | */
46 | private function mbStrPad($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT, $encoding = NULL)
47 | {
48 | $encoding = $encoding === NULL ? mb_internal_encoding() : $encoding;
49 | $padBefore = $dir === STR_PAD_BOTH || $dir === STR_PAD_LEFT;
50 | $padAfter = $dir === STR_PAD_BOTH || $dir === STR_PAD_RIGHT;
51 | $pad_len -= mb_strlen($str, $encoding);
52 | $targetLen = $padBefore && $padAfter ? $pad_len / 2 : $pad_len;
53 | $strToRepeatLen = mb_strlen($pad_str, $encoding);
54 | $repeatTimes = ceil($targetLen / $strToRepeatLen);
55 | $repeatedString = str_repeat($pad_str, max(0, $repeatTimes)); // safe if used with valid utf-8 strings
56 | $before = $padBefore ? mb_substr($repeatedString, 0, floor($targetLen), $encoding) : '';
57 | $after = $padAfter ? mb_substr($repeatedString, 0, ceil($targetLen), $encoding) : '';
58 | return $before . $str . $after;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Transformers/Random.php:
--------------------------------------------------------------------------------
1 | genType = $type;
29 | $this->length = $length;
30 | }
31 |
32 | public function execute()
33 | {
34 | return $this->generateRandomString();
35 | }
36 |
37 | private function generateRandomString()
38 | {
39 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
40 |
41 | if ($this->genType == self::$RANDOM_ALPHA) {
42 | $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
43 | } elseif ($this->genType == self::$RANDOM_NUMERIC) {
44 | $characters = '0123456789';
45 | }
46 |
47 | $charactersLength = strlen($characters);
48 | $randomString = '';
49 | for ($i = 0; $i < $this->length; $i ++) {
50 | $randomString .= $characters[rand(0, $charactersLength - 1)];
51 | }
52 | return $randomString;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Transformers/RemoveNonAscii.php:
--------------------------------------------------------------------------------
1 | getValue());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/RemoveWhitespace.php:
--------------------------------------------------------------------------------
1 | getValue());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Transformers/Repeat.php:
--------------------------------------------------------------------------------
1 | repeatNum = $repeatNum;
23 | }
24 |
25 | public function execute()
26 | {
27 | $s = new Stringizer($this->repeatNum);
28 |
29 | if ($s->isNumber() && $this->repeatNum > 0) {
30 |
31 | $value = "";
32 |
33 | for ($i = 0; $i < $this->repeatNum; $i++) {
34 | $value .= $this->getValue();
35 | }
36 |
37 | return $value;
38 | } else {
39 | // Do nothing just return the same value
40 | return $this->getValue();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Transformers/Replace.php:
--------------------------------------------------------------------------------
1 | needles = $needles;
35 |
36 | $this->replacements = $replacements;
37 | }
38 |
39 | /**
40 | * String replace
41 | *
42 | * @return string Modified string
43 | */
44 | public function execute()
45 | {
46 | if ($this->isCaseInsensitive()) {
47 | return str_ireplace($this->needles, $this->replacements, $this->getValue());
48 | } else {
49 | return str_replace($this->needles, $this->replacements, $this->getValue());
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Transformers/ReplaceAccents.php:
--------------------------------------------------------------------------------
1 | slugify = new Slugify([
26 | 'lowercase' => false
27 | ]);
28 | }
29 |
30 | /**
31 | * Slugify string
32 | */
33 | public function execute()
34 | {
35 | return $this->slugify->slugify($this->getValue(), " ");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Transformers/Reverse.php:
--------------------------------------------------------------------------------
1 | getValue(), $array);
25 | return implode(array_reverse($array[0]));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/RgbColor.php:
--------------------------------------------------------------------------------
1 | getValue())) {
24 | return true;
25 | } else {
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Transformers/Semver.php:
--------------------------------------------------------------------------------
1 | getValue())) {
22 | return true;
23 | } else {
24 | return false;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/SentenceCount.php:
--------------------------------------------------------------------------------
1 | getValue();
24 |
25 | // Change all endings into dots
26 | $string = str_replace(array('!','?'), '.', $string);
27 |
28 | // Remove non essentials
29 | $string = preg_replace('/[^a-zA-Z0-9\.]/', '', $string);
30 |
31 | // Remove multiple sentence endings
32 | $string = preg_replace('/\.{2,}/', '.', $string);
33 |
34 | // Count sentence endings
35 | return substr_count($string, '.');
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Transformers/Split.php:
--------------------------------------------------------------------------------
1 | delimiter = $delimiter;
23 | }
24 |
25 | /**
26 | * Split string
27 | *
28 | * @return array
29 | */
30 | public function execute()
31 | {
32 | return explode($this->delimiter, $this->getValue());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Transformers/StartsWith.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
21 | }
22 |
23 | /**
24 | * StartsWith
25 | */
26 | public function execute()
27 | {
28 | return (mb_substr($this->getValue(), 0, mb_strlen($this->needle)) === $this->needle);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Transformers/StringFindPosition.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
24 | $this->offset = $offset;
25 | }
26 |
27 | public function execute()
28 | {
29 | if ($this->isCaseInsensitive()) {
30 | return mb_stripos($this->getValue(), $this->needle, $this->offset);
31 | } else {
32 | return mb_strpos($this->getValue(), $this->needle, $this->offset);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Transformers/StringFirstOccurrence.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
24 | $this->beforeNeedle = $beforeNeedle;
25 | }
26 |
27 | /**
28 | * StringFirstOccurrence
29 | */
30 | public function execute()
31 | {
32 | if ($this->isCaseInsensitive())
33 | return mb_stristr($this->getValue(), $this->needle, $this->beforeNeedle);
34 | else
35 | return mb_strstr($this->getValue(), $this->needle, $this->beforeNeedle);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Transformers/StripPunctuation.php:
--------------------------------------------------------------------------------
1 | getValue());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Transformers/StripTags.php:
--------------------------------------------------------------------------------
1 | allowableTags = $allowableTags;
20 | }
21 |
22 | public function execute()
23 | {
24 | return strip_tags($this->getValue(), $this->allowableTags);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/SubString.php:
--------------------------------------------------------------------------------
1 | start = $start;
22 | $this->length = $length;
23 | }
24 |
25 | /**
26 | * Truncate
27 | */
28 | public function execute()
29 | {
30 | return mb_substr($this->getValue(), $this->start, $this->length);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Transformers/SubStringCount.php:
--------------------------------------------------------------------------------
1 | needle = $needle;
20 | }
21 |
22 | public function execute()
23 | {
24 | if ($this->isCaseInsensitive()) {
25 | return mb_substr_count(mb_strtolower($this->getValue()), mb_strtolower($this->needle));
26 | } else {
27 | return mb_substr_count($this->getValue(), $this->needle);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Transformers/SwapCase.php:
--------------------------------------------------------------------------------
1 | swap($this->getValue());
22 | }
23 |
24 | /**
25 | *
26 | * @param string $str
27 | */
28 | private function swap($str)
29 | {
30 | $arr = preg_split('//u', $this->getValue(), - 1, PREG_SPLIT_NO_EMPTY);
31 |
32 | $len = count($arr);
33 |
34 | for ($i = 0; $i < $len; $i ++) {
35 |
36 | if (ctype_alpha($arr[$i])) {
37 |
38 | if (ctype_upper($arr[$i])) {
39 | $arr[$i] = mb_strtolower($arr[$i]);
40 | } elseif (ctype_lower($arr[$i])) {
41 |
42 | $arr[$i] = mb_strtoupper($arr[$i]);
43 | }
44 | }
45 | }
46 |
47 | $str = implode("", $arr);
48 |
49 | return $str;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Transformers/Transformer.php:
--------------------------------------------------------------------------------
1 | setValue($value);
24 | }
25 |
26 | /**
27 | * Getter
28 | *
29 | * @return string the value being transformed
30 | */
31 | public function getValue()
32 | {
33 | return $this->value;
34 | }
35 |
36 | /**
37 | * Setter
38 | *
39 | * @param string $value
40 | */
41 | private function setValue($value) {
42 |
43 | if (! isset($value) ) {
44 | throw new \InvalidArgumentException("String to transform contains a null");
45 | }
46 |
47 | $this->value = $value;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Transformers/TransformerCaseInsensitive.php:
--------------------------------------------------------------------------------
1 | caseInsensitive = false;
28 | }
29 |
30 | /**
31 | * Enable Case Insensitive (ignore case checking)
32 | *
33 | * @return \Stringizer\Transformers\TransformerCaseInsenitive
34 | */
35 | public function enableCaseInsensitive()
36 | {
37 | $this->caseInsensitive = true;
38 |
39 | return $this;
40 | }
41 |
42 | /**
43 | * Is Case Insensitive enabled
44 | *
45 | * @return boolean
46 | */
47 | public function isCaseInsensitive()
48 | {
49 | return $this->caseInsensitive;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Transformers/TransformerInterface.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/TrimLeft.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/TrimRight.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/Truncate.php:
--------------------------------------------------------------------------------
1 | numberToTruncate = $numberToTruncate;
23 | }
24 |
25 | /**
26 | * Truncate of string
27 | */
28 | public function execute()
29 | {
30 | $length = mb_strlen($this->getValue());
31 |
32 | if (filter_var($this->numberToTruncate, FILTER_VALIDATE_INT) === false) {
33 | throw new \InvalidArgumentException("Value to truncate by is not a number");
34 | } elseif (filter_var($this->numberToTruncate, FILTER_VALIDATE_INT, array(
35 | "options" => array(
36 | "min_range" => 0,
37 | "max_range" => $length
38 | )
39 | )) === false) {
40 | throw new \InvalidArgumentException("Value to truncate by is out of bounds");
41 | } else {
42 | return (new SubString($this->getValue(), 0, $length - $this->numberToTruncate))->execute();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Transformers/TruncateMatch.php:
--------------------------------------------------------------------------------
1 | stringToMatch = $stringToMatch;
25 | $this->truncateBefore = $truncateBefore;
26 | }
27 |
28 | /**
29 | * Truncate of string
30 | */
31 | public function execute()
32 | {
33 | if ($this->isCaseInsensitive())
34 | $result = (new StringFirstOccurrence($this->getValue(), $this->stringToMatch, $this->truncateBefore))->enableCaseInsensitive()->execute();
35 | else
36 | $result = (new StringFirstOccurrence($this->getValue(), $this->stringToMatch, $this->truncateBefore))->execute();
37 |
38 | return $result;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Transformers/Uppercase.php:
--------------------------------------------------------------------------------
1 | getValue(), \mb_internal_encoding());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/UppercaseCheck.php:
--------------------------------------------------------------------------------
1 | getValue());
24 | $s->replaceAccents();
25 | return ctype_upper($s->getString());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Transformers/UppercaseFirst.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/UppercaseWords.php:
--------------------------------------------------------------------------------
1 | getValue());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Transformers/Url.php:
--------------------------------------------------------------------------------
1 | getValue(), FILTER_VALIDATE_URL) === false;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/Transformers/Width.php:
--------------------------------------------------------------------------------
1 | getValue());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Transformers/WordCount.php:
--------------------------------------------------------------------------------
1 | getValue()))->trim()->length() == 0) {
24 | return 0;
25 | } else {
26 | return count(preg_split('~[^\p{L}\p{N}\']+~u', $this->getValue()));
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/AlphaNumericSpaceDashTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isAlphaNumericSpaceDash());
14 | }
15 |
16 | public function testValidAlphaNumericNumericOnly()
17 | {
18 | $s = new Stringizer("0123456789");
19 | $this->assertEquals(true, $s->isAlphaNumericSpaceDash());
20 | }
21 |
22 | public function testValidAlphaNumeric()
23 | {
24 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
25 | $this->assertEquals(true, $s->isAlphaNumericSpaceDash());
26 | }
27 |
28 | public function testValidAlphaNumericSpace()
29 | {
30 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
31 | $this->assertEquals(true, $s->isAlphaNumericSpaceDash());
32 | }
33 |
34 | public function testValidAlphaNumericSpaceDash()
35 | {
36 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyz - ABCDEFGHIJKLMNOPQRSTUVWXYZ - 0123456789");
37 | $this->assertEquals(true, $s->isAlphaNumericSpaceDash());
38 | }
39 |
40 | public function testValidWhitespaceOnly()
41 | {
42 | $s = new Stringizer(" ");
43 | $this->assertEquals(true, $s->isAlphaNumericSpaceDash());
44 | }
45 |
46 | public function testValidDashOnly()
47 | {
48 | $s = new Stringizer("-");
49 | $this->assertEquals(true, $s->isAlphaNumericSpaceDash());
50 | }
51 |
52 | public function testInValidNonAlpha()
53 | {
54 | $s = new Stringizer("John Doe ! ");
55 | $this->assertEquals(false, $s->isAlphaNumericSpaceDash());
56 | }
57 |
58 | public function testInValidMultiByte()
59 | {
60 | $s = new Stringizer("こんにちは");
61 | $this->assertEquals(false, $s->isAlphaNumericSpaceDash());
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tests/AlphaNumericSpaceTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isAlphaNumericSpace());
14 | }
15 |
16 | public function testValidAlphaNumericNumericOnly()
17 | {
18 | $s = new Stringizer("0123456789");
19 | $this->assertEquals(true, $s->isAlphaNumericSpace());
20 | }
21 |
22 | public function testValidAlphaNumeric()
23 | {
24 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
25 | $this->assertEquals(true, $s->isAlphaNumericSpace());
26 | }
27 |
28 | public function testValidAlphaNumericSpace()
29 | {
30 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
31 | $this->assertEquals(true, $s->isAlphaNumericSpace());
32 | }
33 |
34 | public function testValidWhitespaceOnly()
35 | {
36 | $s = new Stringizer(" ");
37 | $this->assertEquals(true, $s->isAlphaNumericSpace());
38 | }
39 |
40 | public function testInValidNonAlpha()
41 | {
42 | $s = new Stringizer("John Doe ! ");
43 | $this->assertEquals(false, $s->isAlphaNumericSpace());
44 | }
45 |
46 | public function testInValidMultiByte()
47 | {
48 | $s = new Stringizer("こんにちは");
49 | $this->assertEquals(false, $s->isAlphaNumeric());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/AlphaNumericTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isAlphaNumeric());
14 | }
15 |
16 | public function testValidAlphaNumericNumericOnly()
17 | {
18 | $s = new Stringizer("0123456789");
19 | $this->assertEquals(true, $s->isAlphaNumeric());
20 | }
21 |
22 | public function testValidAlphaNumeric()
23 | {
24 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
25 | $this->assertEquals(true, $s->isAlphaNumeric());
26 | }
27 |
28 | public function testInValidWhitespace()
29 | {
30 | $s = new Stringizer(" ");
31 | $this->assertEquals(false, $s->isAlphaNumeric());
32 | }
33 |
34 | public function testInValidNonAlpha()
35 | {
36 | $s = new Stringizer("JohnDoe!");
37 | $this->assertEquals(false, $s->isAlphaNumeric());
38 | }
39 |
40 | public function testInValidMultiByte()
41 | {
42 | $s = new Stringizer("こんにちは");
43 | $this->assertEquals(false, $s->isAlphaNumeric());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/AlphaTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isAlpha());
14 | }
15 |
16 | public function testInValidAlphaHasNumber()
17 | {
18 | $s = new Stringizer("1abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
19 | $this->assertEquals(false, $s->isAlpha());
20 | }
21 |
22 | public function testInValidAlphaHasSpace()
23 | {
24 | $s = new Stringizer("abc dedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
25 | $this->assertEquals(false, $s->isAlpha());
26 | }
27 |
28 | public function testInValidAlphaHasMultiByte()
29 | {
30 | $s = new Stringizer("こんにちは");
31 | $this->assertEquals(false, $s->isAlpha());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/AsciiTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isAscii());
14 |
15 | $s->setString("123");
16 | $this->assertEquals(true, $s->isAscii());
17 |
18 | $s->setString("abc");
19 | $this->assertEquals(true, $s->isAscii());
20 |
21 | $s->setString("abcdefghi....12334567890....ABC..XY!!!@#$%^&*()_+=-<>?:;/.,~][}{\|'");
22 | $this->assertEquals(true, $s->isAscii());
23 |
24 | $s->setString("Hello\n\t\r");
25 | $this->assertEquals(true, $s->isAscii());
26 |
27 | $s->setString("\x19test\x7F");
28 | $this->assertEquals(true, $s->isAscii());
29 | }
30 |
31 | public function testValidAsciiPrintableOnly()
32 | {
33 | $s = new Stringizer(" ");
34 | $this->assertEquals(true, $s->isAscii(true));
35 |
36 | $s->setString("123");
37 | $this->assertEquals(true, $s->isAscii(true));
38 |
39 | $s->setString("abc");
40 | $this->assertEquals(true, $s->isAscii(true));
41 |
42 | $s->setString("abcdefghi....12334567890....ABC..XY!!!@#$%^&*()_+=-<>?:;/.,~][}{\|'");
43 | $this->assertEquals(true, $s->isAscii(true));
44 |
45 | $s->setString("Hello\n\t\r");
46 | $this->assertEquals(false, $s->isAscii(true));
47 |
48 | $s->setString("\x19test\x7F");
49 | $this->assertEquals(false, $s->isAscii(true));
50 | }
51 |
52 | public function testInvalidAscii()
53 | {
54 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
55 | $this->assertEquals(false, $s->isAscii());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/Base64Test.php:
--------------------------------------------------------------------------------
1 | assertTrue($s->isBase64());
15 | $this->assertEquals("Stringizer", $s->base64Decode());
16 |
17 | // ȘŦŗÍñĝìzĕŕ
18 | $s = new Stringizer("yJjFpsWXw43DscSdw6x6xJXFlQ==");
19 | $this->assertTrue($s->isBase64());
20 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ", $s->base64Decode());
21 |
22 | // こんにちは
23 | $s = new Stringizer("44GT44KT44Gr44Gh44Gv");
24 | $this->assertTrue($s->isBase64());
25 | $this->assertEquals("こんにちは", $s->base64Decode());
26 | }
27 |
28 | public function testInvalidBase64()
29 | {
30 | $s = new Stringizer("#iu3498r");
31 | $this->assertFalse($s->isBase64());
32 |
33 | $s = new Stringizer("asiudfh9w=8uihf");
34 | $this->assertFalse($s->isBase64());
35 | }
36 |
37 | public function testBase64EncodeAndDecode()
38 | {
39 | $s = new Stringizer("Stringizer");
40 | $this->assertEquals("U3RyaW5naXplcg==", $s->base64Encode());
41 | $this->assertEquals("Stringizer", $s->base64Decode());
42 |
43 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
44 | $this->assertEquals("yJjFpsWXw43DscSdw6x6xJXFlQ==", $s->base64Encode());
45 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ", $s->base64Decode());
46 |
47 | $s = new Stringizer("こんにちは");
48 | $this->assertEquals("44GT44KT44Gr44Gh44Gv", $s->base64Encode());
49 | $this->assertEquals("こんにちは", $s->base64Decode());
50 | }
51 |
52 | public function testChaining()
53 | {
54 | $s = new Stringizer("Stringizer ");
55 | $this->assertEquals("Stringizer", $s->trim()
56 | ->base64Encode()
57 | ->base64Decode());
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/tests/BetweenTest.php:
--------------------------------------------------------------------------------
1 | Hello World");
12 | $this->assertEquals("Hello World", $s->between("
", "
"));
13 |
14 | // Right Side no match, retains the last right side
15 | $s = new Stringizer("Hello World
");
16 | $this->assertEquals("Hello World", $s->between("", "
"));
17 |
18 | $s = new Stringizer("Hello World");
19 | $this->assertEquals("Hello World", $s->between("
", "
"));
20 | }
21 |
22 | public function testValidMultiByte()
23 | {
24 | $s = new Stringizer("
ȘŦŗÍñĝìzĕŕ
");
25 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ", $s->between("
", "
"));
26 |
27 | $s = new Stringizer("
こんにちは
");
28 | $this->assertEquals("こんにちは", $s->between("
", "
"));
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/tests/BlankTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isBlank());
14 | }
15 |
16 | public function testBlankWithTab()
17 | {
18 | $s = new Stringizer("\t");
19 | $this->assertEquals(true, $s->isBlank());
20 | }
21 |
22 | public function testBlankWithNewLineFeed()
23 | {
24 | $s = new Stringizer("\n");
25 | $this->assertEquals(true, $s->isBlank());
26 | }
27 |
28 | public function testBlankWithCarriageReturn()
29 | {
30 | $s = new Stringizer("\r");
31 | $this->assertEquals(true, $s->isBlank());
32 | }
33 |
34 | public function testBlankWithWhitespaces()
35 | {
36 | $s = new Stringizer("\n \n\r\t ");
37 | $this->assertEquals(true, $s->isBlank());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/CamelToSnakeTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("hello_world", $s->camelToSnake());
14 |
15 | $s = new Stringizer("MyFunctionName");
16 | $this->assertEquals("my_function_name", $s->camelToSnake());
17 |
18 | $s = new Stringizer("helloSŦŗÍñĝìzĕŕ");
19 | $this->assertEquals("hello_sŧŗíñĝìzĕŕ", $s->camelToSnake());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/CamelizeTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("dataRate", $s->camelize());
14 |
15 | $s = new Stringizer("background-image");
16 | $this->assertEquals("backgroundImage", $s->camelize());
17 |
18 | $s = new Stringizer("--flag-off");
19 | $this->assertEquals("flagOff", $s->camelize());
20 |
21 | $s = new Stringizer("__constant_value__");
22 | $this->assertEquals("constantValue", $s->camelize());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CharsTest.php:
--------------------------------------------------------------------------------
1 | chars();
14 |
15 | $this->assertEquals(10, count($data));
16 |
17 | $this->assertEquals($data[0], "S");
18 | $this->assertEquals($data[1], "t");
19 | $this->assertEquals($data[2], "r");
20 | $this->assertEquals($data[3], "i");
21 | $this->assertEquals($data[4], "n");
22 | $this->assertEquals($data[5], "g");
23 | $this->assertEquals($data[6], "i");
24 | $this->assertEquals($data[7], "z");
25 | $this->assertEquals($data[8], "e");
26 | $this->assertEquals($data[9], "r");
27 | }
28 |
29 | public function testValidMultiByte1()
30 | {
31 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
32 | $data = $s->chars();
33 |
34 | $this->assertEquals(10, count($data));
35 |
36 | $this->assertEquals($data[0], "Ș");
37 | $this->assertEquals($data[1], "Ŧ");
38 | $this->assertEquals($data[2], "ŗ");
39 | $this->assertEquals($data[3], "Í");
40 | $this->assertEquals($data[4], "ñ");
41 | $this->assertEquals($data[5], "ĝ");
42 | $this->assertEquals($data[6], "ì");
43 | $this->assertEquals($data[7], "z");
44 | $this->assertEquals($data[8], "ĕ");
45 | $this->assertEquals($data[9], "ŕ");
46 | }
47 |
48 | /**
49 | * Kon'nichiwa ==> こんにちは
50 | */
51 | public function testValidMultiByteHelloInJapanese()
52 | {
53 | $s = new Stringizer("こんにちは");
54 | $data = $s->chars();
55 |
56 | $this->assertEquals(5, count($data));
57 |
58 | $this->assertEquals($data[0], "こ");
59 | $this->assertEquals($data[1], "ん");
60 | $this->assertEquals($data[2], "に");
61 | $this->assertEquals($data[3], "ち");
62 | $this->assertEquals($data[4], "は");
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/tests/ChartAtTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("B", $s->charAt(4));
14 |
15 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
16 | $this->assertEquals("Ŧ", $s->charAt(1));
17 |
18 | $s = new Stringizer("こんにちは");
19 | $this->assertEquals("こ", $s->charAt(0));
20 |
21 | $s = new Stringizer("こんにちは");
22 | $this->assertEquals("", $s->charAt(10));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/ChopLeftTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("bar", $s->chopLeft("foo"));
14 | }
15 |
16 | public function testValidNoMatch()
17 | {
18 | $s = new Stringizer("foobar");
19 | $this->assertEquals("foobar", $s->chopLeft("FU"));
20 | }
21 |
22 | public function testValidMultiByte()
23 | {
24 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
25 | $this->assertEquals("ìzĕŕ", $s->chopLeft("ȘŦŗÍñĝ"));
26 |
27 | $s = new Stringizer("
こんにちは");
28 | $this->assertEquals("こんにちは", $s->chopLeft("
"));
29 | }
30 |
31 | public function testValidMultiByteNoMatch()
32 | {
33 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
34 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ", $s->chopLeft("ȘŦŗÍñĝXXX"));
35 |
36 | $s = new Stringizer("
こんにちは");
37 | $this->assertEquals("
こんにちは", $s->chopLeft(""));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/ChopRightTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("foo", $s->chopRight("bar"));
14 | }
15 |
16 | public function testValidNoMatch()
17 | {
18 | $s = new Stringizer("foobar");
19 | $this->assertEquals("foobar", $s->chopRight("FU"));
20 | }
21 |
22 | public function testValidMultiByte()
23 | {
24 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
25 | $this->assertEquals("ȘŦŗÍñĝ", $s->chopRight("ìzĕŕ"));
26 |
27 | $s = new Stringizer("こんにちは
");
28 | $this->assertEquals("こんにちは", $s->chopRight("
"));
29 | }
30 |
31 | public function testValidMultiByteNoMatch()
32 | {
33 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
34 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ", $s->chopRight("ȘŦŗÍñĝXXX"));
35 |
36 | $s = new Stringizer("こんにちは
");
37 | $this->assertEquals("こんにちは
", $s->chopRight("
"));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/CollapseWhitespaceTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", $s->collapseWhitespace());
14 | }
15 |
16 | public function testValidNothingtoCollapseOnlySingleSpaces()
17 | {
18 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890");
19 | $this->assertEquals("abcdedfghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890", $s->collapseWhitespace());
20 | }
21 |
22 | public function testValidNothingtoCollapseOnlySingleSpacesSpaceOnEnds()
23 | {
24 | $s = new Stringizer(" abcdedfghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 ");
25 | $this->assertEquals("abcdedfghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890", $s->collapseWhitespace());
26 | }
27 |
28 | public function testValidMultiByte()
29 | {
30 | $s = new Stringizer(" ȘŦŗÍñĝìzĕŕ こんにちは ");
31 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ こんにちは", $s->collapseWhitespace());
32 |
33 | $s = new Stringizer(" Ș Ŧ ŗ Í ñ ĝ ì z ĕ ŕ こ ん に ち は ");
34 | $this->assertEquals("Ș Ŧ ŗ Í ñ ĝ ì z ĕ ŕ こ ん に ち は", $s->collapseWhitespace());
35 |
36 | $s = new Stringizer("ȘŦŗÍñĝ\n\nìzĕŕ \n\t \r");
37 | $this->assertEquals("ȘŦŗÍñĝ ìzĕŕ", $s->collapseWhitespace());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/ConcatTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("fizz buzz", $s->concat(" buzz"));
14 | }
15 |
16 | public function testPreConcat()
17 | {
18 | $s = new Stringizer("fizz");
19 | $this->assertEquals("buzz fizz", $s->concat("buzz ", true));
20 | }
21 |
22 | /**
23 | * @expectedException InvalidArgumentException
24 | */
25 | public function testInvalidArgumentNull()
26 | {
27 | $s = new Stringizer("fizz");
28 | $s->concat(null);
29 | }
30 |
31 | /**
32 | * @expectedException InvalidArgumentException
33 | */
34 | public function testInvalidArgumentNullPreAppend()
35 | {
36 | $s = new Stringizer("fizz");
37 | $s->concat(null, true);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/ContainsCountTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(1, $s->containsCount("buzz"));
14 |
15 | $s = new Stringizer("fizz buzz fizz buzz fizz buzz");
16 | $this->assertEquals(3, $s->containsCount("buzz"));
17 |
18 | $s = new Stringizer("fizz buzz foo bar");
19 | $this->assertEquals(0, $s->containsCount("nomatch"));
20 |
21 | // Case Sensitive, no match
22 | $s = new Stringizer("fizz buzz foo bar");
23 | $this->assertEquals(0, $s->containsCount("BUZZ"));
24 |
25 | $s = new Stringizer("fizz buzz foo bar");
26 | $this->assertEquals(1, $s->containsCountIncaseSensitive("BUZZ"));
27 |
28 | $s = new Stringizer("fizz buzz foo bar");
29 | $this->assertEquals(0, $s->containsCountIncaseSensitive("BUZZ-NO-MATCH"));
30 | }
31 |
32 | public function testContainsCountValidMultibyte()
33 | {
34 | $s = new Stringizer("文字列のそれ");
35 | $this->assertEquals(1, $s->containsCount("の"));
36 |
37 | $s = new Stringizer("文字列のそれ 文字列のそれ 文字列のそれ 文字列のそれ");
38 | $this->assertEquals(4, $s->containsCount("れ"));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/ContainsTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->contains("buzz"));
14 |
15 | $s = new Stringizer("fizz buzz John Doe foo bar");
16 | $this->assertEquals(true, $s->contains("John Doe"));
17 | }
18 |
19 | public function testContainsValidNoMatch()
20 | {
21 | // Case Sensitive, fails
22 | $s = new Stringizer("fizz buzz foo bar");
23 | $this->assertEquals(false, $s->contains("Buzz"));
24 | }
25 |
26 | public function testContainsValidIncaseSensitive()
27 | {
28 | $s = new Stringizer("fizz buzz foo bar");
29 | $this->assertEquals(true, $s->containsIncaseSensitive("bUzZ"));
30 | }
31 |
32 | public function testContainsValidIncaseSensitiveNoMatch()
33 | {
34 | $s = new Stringizer("fizz buzz foo bar");
35 | $this->assertEquals(false, $s->containsIncaseSensitive("bUzZz"));
36 | }
37 |
38 | public function testContainsValidMultiByte()
39 | {
40 | $s = new Stringizer("文字列のそれ");
41 | $this->assertEquals(true, $s->contains("列の"));
42 | }
43 |
44 | public function testContainsValidMultiByteNoMatch()
45 | {
46 | $s = new Stringizer("文字列のそれ");
47 | $this->assertEquals(false, $s->contains("の列の"));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/DasherizeTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("data-rate", $s->dasherize());
14 |
15 | $s = new Stringizer("backgroundImage");
16 | $this->assertEquals("background-image", $s->dasherize());
17 |
18 | $s = new Stringizer("HelloWorldThisIsCamelized");
19 | $this->assertEquals("-hello-world-this-is-camelized", $s->dasherize());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/DateTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isDate());
16 |
17 | $s = new Stringizer("2015-03-15");
18 | $this->assertEquals(true, $s->isDate());
19 |
20 | $s = new Stringizer("1 week ago");
21 | $this->assertEquals(true, $s->isDate());
22 | }
23 |
24 | public function testInValidDate()
25 | {
26 | date_default_timezone_set('America/Vancouver');
27 |
28 | $s = new Stringizer("Bad Date Input");
29 | $this->assertEquals(false, $s->isDate());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/DecimalTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isDecimal());
14 |
15 | $s = new Stringizer("987654321");
16 | $this->assertEquals(true, $s->isDecimal());
17 |
18 | $s = new Stringizer(".123456789");
19 | $this->assertEquals(true, $s->isDecimal());
20 |
21 | $s = new Stringizer("0.123456789");
22 | $this->assertEquals(true, $s->isDecimal());
23 |
24 | $s = new Stringizer("1");
25 | $this->assertEquals(true, $s->isDecimal());
26 |
27 | $s = new Stringizer("1.1");
28 | $this->assertEquals(true, $s->isDecimal());
29 |
30 | $s = new Stringizer("0");
31 | $this->assertEquals(true, $s->isDecimal());
32 |
33 | $s = new Stringizer("0.0");
34 | $this->assertEquals(true, $s->isDecimal());
35 |
36 | $s = new Stringizer("0.00");
37 | $this->assertEquals(true, $s->isDecimal());
38 |
39 | $s = new Stringizer("-0");
40 | $this->assertEquals(true, $s->isDecimal());
41 |
42 | $s = new Stringizer("-0.0");
43 | $this->assertEquals(true, $s->isDecimal());
44 |
45 | $s = new Stringizer("-0.00");
46 | $this->assertEquals(true, $s->isDecimal());
47 |
48 | $s = new Stringizer("-1.1");
49 | $this->assertEquals(true, $s->isDecimal());
50 |
51 | $s = new Stringizer("-1");
52 | $this->assertEquals(true, $s->isDecimal());
53 |
54 | $s = new Stringizer("-0.123456789");
55 | $this->assertEquals(true, $s->isDecimal());
56 |
57 | $s = new Stringizer("-.123456789");
58 | $this->assertEquals(true, $s->isDecimal());
59 |
60 | $s = new Stringizer("-987654321");
61 | $this->assertEquals(true, $s->isDecimal());
62 |
63 | $s = new Stringizer("-987654321.123456789");
64 | $this->assertEquals(true, $s->isDecimal());
65 | }
66 |
67 | public function testInValidDecimal()
68 | {
69 | $s = new Stringizer("123.0x");
70 | $this->assertEquals(false, $s->isDecimal());
71 |
72 | $s = new Stringizer("123.0.");
73 | $this->assertEquals(false, $s->isDecimal());
74 |
75 | $s = new Stringizer("1 23");
76 | $this->assertEquals(false, $s->isDecimal());
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/tests/DeleteTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("Fizz Fizz Fizz ", $s->delete("Buzz"));
14 |
15 | $s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
16 | $this->assertEquals("Fizz Fizz Fizz", $s->delete(" Buzz"));
17 | }
18 |
19 | public function testDeleteChar()
20 | {
21 | $s = new Stringizer("Fizz Fizz Fizz");
22 | $this->assertEquals("izz izz izz", $s->delete("F"));
23 | }
24 |
25 | public function testDeleteCharMultiByte()
26 | {
27 | $s = new Stringizer("Fizz 列Fizz列 Fizz");
28 | $this->assertEquals("Fizz Fizz Fizz", $s->delete("列"));
29 | }
30 |
31 | public function testDeleteStringArray()
32 | {
33 | $s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
34 | $this->assertEquals(" ", $s->delete(array(
35 | "Fizz",
36 | "Buzz"
37 | )));
38 | }
39 |
40 | public function testDeleteStringArrayMultiByte()
41 | {
42 | $s = new Stringizer("Fizz列Buzz列Fizz列Buzz列Fizz列Buzz");
43 | $this->assertEquals("列列列列列", $s->delete(array(
44 | "Fizz",
45 | "Buzz"
46 | )));
47 |
48 | $s = new Stringizer("Fizz列Buzz列Fizz列Buzz列Fizz列Buzz");
49 | $this->assertEquals("FizzFizzFizz", $s->delete(array(
50 | "Buzz",
51 | "列"
52 | )));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/tests/EmailTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isEmail());
14 |
15 | $s = new Stringizer("x@x.org");
16 | $this->assertEquals(true, $s->isEmail());
17 |
18 | $s = new Stringizer("111@somewhere.com");
19 | $this->assertEquals(true, $s->isEmail());
20 | }
21 |
22 | public function testInValidEmails()
23 | {
24 | $s = new Stringizer("invalid@gmail..com");
25 | $this->assertEquals(false, $s->isEmail());
26 |
27 | $s = new Stringizer("x@x@.org");
28 | $this->assertEquals(false, $s->isEmail());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/EmptyTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isEmpty());
14 | }
15 |
16 | public function testEmptyWithTab()
17 | {
18 | $s = new Stringizer("\t");
19 | $this->assertEquals(true, $s->isEmpty());
20 | }
21 |
22 | public function testEmptyWithNewLineFeed()
23 | {
24 | $s = new Stringizer("\n");
25 | $this->assertEquals(true, $s->isEmpty());
26 | }
27 |
28 | public function testEmptyWithCarriageReturn()
29 | {
30 | $s = new Stringizer("\r");
31 | $this->assertEquals(true, $s->isEmpty());
32 | }
33 |
34 | public function testEmptyWithWhitespaces()
35 | {
36 | $s = new Stringizer("\n \n\r\t ");
37 | $this->assertEquals(true, $s->isEmpty());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/EndsWithTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->endsWith("れ"));
14 |
15 | $s = new Stringizer("文字列のそれ");
16 | $this->assertEquals(false, $s->endsWith("れれれれ"));
17 |
18 | $s = new Stringizer("Fizz Buzz");
19 | $this->assertEquals(true, $s->endsWith("zz"));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/EnsureLeftTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("/myapp", $s->ensureLeft("/"));
14 | }
15 |
16 | public function testValidEnsureLeftPrefixExsists()
17 | {
18 | $s = new Stringizer("/myapp");
19 | $this->assertEquals("/myapp", $s->ensureLeft("/"));
20 | }
21 |
22 | public function testValidEnsureLeftMultiByte()
23 | {
24 | $s = new Stringizer("こんにちは世界");
25 | $this->assertEquals("/こんにちは世界", $s->ensureLeft("/"));
26 |
27 | $s = new Stringizer("こんにちは世界");
28 | $this->assertEquals("さようなら こんにちは世界", $s->ensureLeft("さようなら "));
29 | }
30 |
31 | public function testValidEnsureLeftPrefixExsistsMultiByte()
32 | {
33 | $s = new Stringizer("こんにちは世界");
34 | $this->assertEquals("こんにちは世界", $s->ensureLeft("こんにちは世界"));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/EnsureRightTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("myapp/", $s->ensureRight("/"));
14 | }
15 |
16 | public function testValidEnsureLeftPrefixExsists()
17 | {
18 | $s = new Stringizer("myapp/");
19 | $this->assertEquals("myapp/", $s->ensureRight("/"));
20 | }
21 |
22 | public function testValidEnsureLeftMultiByte()
23 | {
24 | $s = new Stringizer("こんにちは世界");
25 | $this->assertEquals("こんにちは世界/", $s->ensureRight("/"));
26 |
27 | $s = new Stringizer("こんにちは世界");
28 | $this->assertEquals("こんにちは世界 さようなら", $s->ensureRight(" さようなら"));
29 | }
30 |
31 | public function testValidEnsureLeftPrefixExsistsMultiByte()
32 | {
33 | $s = new Stringizer("こんにちは世界");
34 | $this->assertEquals("こんにちは世界", $s->ensureRight("こんにちは世界"));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/FirstTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("my", $s->first(2));
14 |
15 | $s = new Stringizer("myapp");
16 | $this->assertEquals("myapp", $s->first(5));
17 |
18 | $s = new Stringizer("myapp");
19 | $this->assertEquals("myapp", $s->first(6));
20 |
21 | $s = new Stringizer("myapp");
22 | $this->assertEquals("", $s->first(0));
23 | }
24 |
25 | public function testValidFirstMultiByte()
26 | {
27 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
28 | $this->assertEquals("ȘŦŗÍñĝ", $s->first(6));
29 |
30 | $s = new Stringizer("こんにちは");
31 | $this->assertEquals("こ", $s->first(1));
32 | }
33 |
34 | public function testInValidFirst()
35 | {
36 | $s = new Stringizer("myapp");
37 | $this->assertNotEquals("my", $s->first(3));
38 |
39 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
40 | $this->assertNotEquals("ȘŦŗÍñĝ", $s->first(5));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/HasLowercaseTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->hasLowercase());
14 |
15 | $s = new Stringizer("stŗiñĝìzĕŕ");
16 | $this->assertEquals(true, $s->hasLowercase());
17 | }
18 |
19 | public function testInValidHasLowercase()
20 | {
21 | $s = new Stringizer("Abcdedfghijklmnopqrstuvwxyz");
22 | $this->assertEquals(false, $s->hasLowercase());
23 |
24 | $s = new Stringizer("sTŗiñĝìzĕŕ");
25 | $this->assertEquals(false, $s->hasLowercase());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/HasUppercaseTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->hasUppercase());
14 |
15 | $s = new Stringizer("STÃÑ");
16 | $this->assertEquals(true, $s->hasUppercase());
17 | }
18 |
19 | public function testInValidHasUppercase()
20 | {
21 | $s = new Stringizer("ABcD");
22 | $this->assertEquals(false, $s->hasUppercase());
23 |
24 | $s = new Stringizer("sÑÃ");
25 | $this->assertEquals(false, $s->hasUppercase());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/HashCodeTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("-505841268", $s->hashCode());
26 |
27 | $s = new Stringizer("Hello, World");
28 | $this->assertNotEquals("bad-match", $s->hashCode());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/HashTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isHash("crc32"));
14 |
15 | $s = new Stringizer("d87f7e0c");
16 | $this->assertEquals(true, $s->isHash("crc32b"));
17 |
18 | $s = new Stringizer("3ca25ae354e192b26879f651a51d92aa8a34d8d3");
19 | $this->assertEquals(true, $s->isHash("sha1"));
20 |
21 | $s->setString("3ca25ae354e192b26879f651a51d92aa8a34d8d3");
22 | $this->assertEquals(true, $s->isHash("Tiger160"));
23 |
24 | $s->setString("579282cfb65ca1f109b78536effaf621b853c9f7079664a3fbe2b519f435898c");
25 | $this->assertEquals(true, $s->isHash("sha256"));
26 |
27 | $s->setString("bf547c3fc5841a377eb1519c2890344dbab15c40ae4150b4b34443d2212e5b04aa9d58865bf03d8ae27840fef430b891");
28 | $this->assertEquals(true, $s->isHash("sha384"));
29 |
30 | $s->setString("45bc5fa8cb45ee408c04b6269e9f1e1c17090c5ce26ffeeda2af097735b29953ce547e40ff3ad0d120e5361cc5f9cee35ea91ecd4077f3f589b4d439168f91b9");
31 | $this->assertEquals(true, $s->isHash("sha512"));
32 |
33 | $s->setString("46fc0125a148788a3ac1d649566fc04eb84a746f1a6e4fa7");
34 | $this->assertEquals(true, $s->isHash("tiger192"));
35 | }
36 |
37 | public function testInValidHash()
38 | {
39 | $s = new Stringizer("1260fc5e11");
40 | $this->assertEquals(false, $s->isHash("crc32"));
41 |
42 | $s = new Stringizer("d87f7e0c11");
43 | $this->assertEquals(false, $s->isHash("crc32b"));
44 |
45 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
46 | $this->assertEquals(false, $s->isHash("md4"));
47 |
48 | $s->setString("3ca25ae354e192b26879f651a51d34d8d3");
49 | $this->assertEquals(false, $s->isHash("sha1"));
50 |
51 | $s->setString("3ca25ae354e192b26879f651a51d34d8d3");
52 | $this->assertEquals(false, $s->isHash("ripemd160"));
53 |
54 | $s->setString("579282cfb65ca1f109b78536effaf621b853c9f7079664a3fbe2b519f435898casfdsafsadfsdf");
55 | $this->assertEquals(false, $s->isHash("sha256"));
56 |
57 | $s->setString("579282cfb65ca1f109b78536effaf621b853c9f7079664a3fbe2b519f435898casfdsafsadfsdf");
58 | $this->assertEquals(false, $s->isHash("sha384"));
59 |
60 | $s->setString("579282cfb65ca1f109b78536effaf621b853c9f7079664a3fbe2b519f435898casfdsafsadfsdf");
61 | $this->assertEquals(false, $s->isHash("sha512"));
62 |
63 | $s->setString("46fc0125a148788a3ac1d649566fc04eb84a746f1a6$$%@^");
64 | $this->assertEquals(false, $s->isHash("TIGER192"));
65 |
66 | $s->setString("46fc0125a148788a3ac1d649566fc04eb84a746f1a6$$%@^");
67 | $this->assertEquals(false, $s->isHash("SOMEHASH"));
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/tests/HexColorTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isHexColor());
14 |
15 | $s = new Stringizer("ffffff");
16 | $this->assertEquals(true, $s->isHexColor());
17 |
18 | $s = new Stringizer("CCDDEE");
19 | $this->assertEquals(true, $s->isHexColor());
20 |
21 | $s = new Stringizer("fff");
22 | $this->assertEquals(true, $s->isHexColor());
23 |
24 | $s = new Stringizer("#fff");
25 | $this->assertEquals(true, $s->isHexColor());
26 | }
27 |
28 | public function testInvValidHexColor()
29 | {
30 | $s = new Stringizer("");
31 | $this->assertEquals(false, $s->isHexColor());
32 |
33 | $s = new Stringizer("#ff");
34 | $this->assertEquals(false, $s->isHexColor());
35 |
36 | $s = new Stringizer("#fffffz");
37 | $this->assertEquals(false, $s->isHexColor());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/HexDecimalTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isHexDecimal());
14 |
15 | $s = new Stringizer("ab12bc99");
16 | $this->assertEquals(true, $s->isHexDecimal());
17 | }
18 |
19 | public function testInValidHexDecimal()
20 | {
21 | $s = new Stringizer("abcdedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
22 | $this->assertEquals(false, $s->isHexDecimal());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/IndexOfTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(2, $s->indexOf("列"));
14 |
15 | $s = new Stringizer("fòô bàř");
16 | $this->assertEquals(4, $s->indexOf("bàř"));
17 |
18 | $s = new Stringizer("Fizz Buzz Foo Bar");
19 | $this->assertEquals(10, $s->indexOf("Foo"));
20 |
21 | $s = new Stringizer("Fizz Buzz Foo Bar");
22 | $this->assertEquals(FALSE, $s->indexOf("bad"));
23 | }
24 |
25 | public function testValidIndexOfWithOffset()
26 | {
27 | $s = new Stringizer("Foo Buzz Foo Bar");
28 | $this->assertEquals(0, $s->indexOf("Foo", 0));
29 | $this->assertEquals(9, $s->indexOf("Foo", 1));
30 | }
31 |
32 | public function testValidIndexOfCaseInsenitive()
33 | {
34 | // Case Sensitive
35 | $s = new Stringizer("Fizz Buzz Foo Bar");
36 | $this->assertEquals(FALSE, $s->indexOf("foo"));
37 |
38 | // Case-InSensitive
39 | $s = new Stringizer("Fizz Buzz Foo Bar");
40 | $this->assertEquals(10, $s->indexOfCaseInsensitive("foo"));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/Ipv4Test.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isIpv4());
14 |
15 | $s = new Stringizer("1.1.1.1");
16 | $this->assertEquals(true, $s->isIpv4());
17 |
18 | $s = new Stringizer("0.0.0.0");
19 | $this->assertEquals(true, $s->isIpv4());
20 | }
21 |
22 | public function testInValidIp()
23 | {
24 | $s = new Stringizer("0.0.0.x");
25 | $this->assertEquals(false, $s->isIpv4());
26 |
27 | $s = new Stringizer("257.1.1.1");
28 | $this->assertEquals(false, $s->isIpv4());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Ipv6Test.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isIpv6());
14 | }
15 |
16 | public function testInValidIp()
17 | {
18 | $s = new Stringizer("xx");
19 | $this->assertEquals(false, $s->isIpv6());
20 |
21 | $s = new Stringizer("2001:cdba:0000:0000:0000:0000:3257:9652x");
22 | $this->assertEquals(false, $s->isIpv6());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/IsbnTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isIsbn10());
14 |
15 | $s->setString("0-306-40615-2");
16 | $this->assertEquals(true, $s->isIsbn10());
17 |
18 | $s->setString("ISBN:0306406152");
19 | $this->assertEquals(true, $s->isIsbn10());
20 |
21 | $s->setString("0306406152");
22 | $this->assertEquals(true, $s->isIsbn10());
23 | }
24 |
25 | public function testIsbn13Valid()
26 | {
27 | $s = new Stringizer("ISBN:979-1-090-63607-1");
28 | $this->assertEquals(true, $s->isIsbn13());
29 |
30 | $s->setString("979-1-090-63607-1");
31 | $this->assertEquals(true, $s->isIsbn13());
32 |
33 | $s->setString("ISBN:9791090636071");
34 | $this->assertEquals(true, $s->isIsbn13());
35 |
36 | $s->setString("9791090636071");
37 | $this->assertEquals(true, $s->isIsbn13());
38 | }
39 |
40 | public function testIsbn10Invalid()
41 | {
42 | $s = new Stringizer("");
43 | $this->assertEquals(false, $s->isIsbn10());
44 |
45 | $s->setString("bad");
46 | $this->assertEquals(false, $s->isIsbn10());
47 |
48 | $s->setString("928-9402221191");
49 | $this->assertEquals(false, $s->isIsbn10());
50 |
51 | $s->setString("3-353-22452-34");
52 | $this->assertEquals(false, $s->isIsbn10());
53 |
54 | $s->setString("3 399 21452 1");
55 | $this->assertEquals(false, $s->isIsbn10());
56 | }
57 |
58 | public function testIsbn13Invalid()
59 | {
60 | $s = new Stringizer("");
61 | $this->assertEquals(false, $s->isIsbn13());
62 |
63 | $s->setString("bad");
64 | $this->assertEquals(false, $s->isIsbn13());
65 |
66 | $s->setString("3-4893-2930-5");
67 | $this->assertEquals(false, $s->isIsbn13());
68 |
69 | $s->setString("01234567890ab");
70 | $this->assertEquals(false, $s->isIsbn13());
71 |
72 | $s->setString("978 3 8362 2119 0");
73 | $this->assertEquals(false, $s->isIsbn13());
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tests/JoinTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("Hello,World,Again", $s->join(array(
14 | "Hello",
15 | "World",
16 | "Again"
17 | )));
18 | $this->assertEquals("Hello, World, Again", $s->join(array(
19 | "Hello",
20 | "World",
21 | "Again"
22 | ), ", "));
23 | $this->assertEquals("Hello|World|Again", $s->join(array(
24 | "Hello",
25 | "World",
26 | "Again"
27 | ), "|"));
28 | }
29 |
30 | public function testJoinMultiByte()
31 | {
32 | $s = new Stringizer("こんにちは");
33 | $this->assertEquals("こ,ん,に,ち,は", $s->join(array(
34 | "こ",
35 | "ん",
36 | "に",
37 | "ち",
38 | "は"
39 | )));
40 | $this->assertEquals("こ, ん, に, ち, は", $s->join(array(
41 | "こ",
42 | "ん",
43 | "に",
44 | "ち",
45 | "は"
46 | ), ", "));
47 | $this->assertEquals("こ|ん|に|ち|は", $s->join(array(
48 | "こ",
49 | "ん",
50 | "に",
51 | "ち",
52 | "は"
53 | ), "|"));
54 | $this->assertEquals("こんにちは", $s->join(array(
55 | "こ",
56 | "ん",
57 | "に",
58 | "ち",
59 | "は"
60 | ), ""));
61 | }
62 |
63 | /**
64 | * @expectedException InvalidArgumentException
65 | */
66 | public function testNotArrayException()
67 | {
68 | $s = new Stringizer("");
69 | $this->assertEquals("Hello,World,Again", $s->join("bad-value-not-array"));
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/tests/JsonTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isJson());
14 |
15 | $s = new Stringizer("{\"foo\" : {
16 | \"bar\" : \"Hello\",
17 | \"baz\" : [ \"quuz\", \"norf\" ]
18 | }}");
19 | $this->assertEquals(true, $s->isJson());
20 |
21 | $s = new Stringizer("{\"foo\" : {
22 | \"bar\" : \"Hello\"
23 | }}");
24 | $this->assertEquals(true, $s->isJson());
25 | }
26 |
27 | public function testInValidJson()
28 | {
29 | $s = new Stringizer("{}");
30 | $this->assertEquals(false, $s->isJson());
31 |
32 | $s = new Stringizer("");
33 | $this->assertEquals(false, $s->isJson());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/LastIndexOfTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(2, $s->lastIndexOf("列"));
14 |
15 | $s = new Stringizer("fòô bàř fòô bàř fòô bàř");
16 | $this->assertEquals(16, $s->lastIndexOf("fòô"));
17 |
18 | $s = new Stringizer("Foo Buzz Foo Bar");
19 | $this->assertEquals(9, $s->lastIndexOf("Foo"));
20 |
21 | $s = new Stringizer("Fizz Buzz Foo Bar");
22 | $this->assertEquals(FALSE, $s->lastIndexOf("bad"));
23 | }
24 |
25 | public function testValidIndexOfWithOffset()
26 | {
27 | $s = new Stringizer("Foo Buzz Foo Bar");
28 | $this->assertEquals(9, $s->lastIndexOf("Foo", 0));
29 | $this->assertEquals(9, $s->lastIndexOf("Foo", 4));
30 | $this->assertEquals(false, $s->lastIndexOf("Foo", 10));
31 | }
32 |
33 | public function testValidIndexOfCaseInsenitive()
34 | {
35 | // Case Sensitive
36 | $s = new Stringizer("Fizz Buzz Foo Bar");
37 | $this->assertEquals(FALSE, $s->lastIndexOf("foo"));
38 |
39 | // Case-InSensitive
40 | $s = new Stringizer("Fizz Buzz Foo Bar");
41 | $this->assertEquals(10, $s->lastIndexOfCaseInsensitive("foo"));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/LastTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("app", $s->last(3));
14 |
15 | $s = new Stringizer("myapp");
16 | $this->assertEquals("myapp", $s->last(5));
17 |
18 | $s = new Stringizer("myapp");
19 | $this->assertEquals("", $s->last(0));
20 | }
21 |
22 | public function testValidFirstMultiByte()
23 | {
24 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
25 | $this->assertEquals("ìzĕŕ", $s->last(4));
26 |
27 | $s = new Stringizer("こんにちは");
28 | $this->assertEquals("は", $s->last(1));
29 | }
30 |
31 | public function testInValidFirst()
32 | {
33 | $s = new Stringizer("myapp");
34 | $this->assertNotEquals("my", $s->last(3));
35 |
36 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
37 | $this->assertNotEquals("ȘŦŗÍñĝ", $s->last(5));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/LatitudeTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isLatitude());
14 |
15 | $s = new Stringizer("37");
16 | $this->assertEquals(true, $s->isLatitude());
17 |
18 | $s = new Stringizer("-90");
19 | $this->assertEquals(true, $s->isLatitude());
20 |
21 | $s = new Stringizer("90");
22 | $this->assertEquals(true, $s->isLatitude());
23 | }
24 |
25 | public function testInValidLatitude()
26 | {
27 | $s = new Stringizer("x37.138");
28 | $this->assertEquals(false, $s->isLatitude());
29 |
30 | $s = new Stringizer("91");
31 | $this->assertEquals(false, $s->isLatitude());
32 |
33 | $s = new Stringizer("-91");
34 | $this->assertEquals(false, $s->isLatitude());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/LengthTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(6, $s->length());
14 |
15 | $s = new Stringizer("FizzBuzz");
16 | $this->assertEquals(8, $s->length());
17 | }
18 |
19 | public function testLengthMultiByte()
20 | {
21 | $s = new Stringizer("キラキラした");
22 | $this->assertEquals(6, $s->length());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/LineCountTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(0, $s->lineCount());
14 | }
15 |
16 | public function testValid1Line()
17 | {
18 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ\n");
19 | $this->assertEquals(1, $s->lineCount());
20 | }
21 |
22 | public function testValid2Lines()
23 | {
24 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ\nȘŦŗÍñĝìzĕŕ\nȘŦŗÍñĝìzĕŕ");
25 | $this->assertEquals(2, $s->lineCount());
26 | }
27 |
28 | public function testValidManyLines()
29 | {
30 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ\nȘŦŗÍñĝìzĕŕ\n\n\n\n\nȘŦŗÍñĝìzĕŕ\n\n\n\n\n\n\n\n");
31 | $this->assertEquals(14, $s->lineCount());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/LongitudeTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isLongitude());
14 |
15 | $s = new Stringizer("37");
16 | $this->assertEquals(true, $s->isLongitude());
17 |
18 | $s = new Stringizer("-180");
19 | $this->assertEquals(true, $s->isLongitude());
20 |
21 | $s = new Stringizer("180");
22 | $this->assertEquals(true, $s->isLongitude());
23 | }
24 |
25 | public function testInValidLongitude()
26 | {
27 | $s = new Stringizer("x37.138");
28 | $this->assertEquals(false, $s->isLongitude());
29 |
30 | $s = new Stringizer("191");
31 | $this->assertEquals(false, $s->isLongitude());
32 |
33 | $s = new Stringizer("-181");
34 | $this->assertEquals(false, $s->isLongitude());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/LowercaseFirstTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("fIZZ", $s->lowercaseFirst());
14 |
15 | $s = new Stringizer("fizz buzz FOO bar");
16 | $this->assertEquals("fIZZ BUZZ FOO BAR", $s->lowercaseFirst());
17 |
18 | $s = new Stringizer("ABCDEFG");
19 | $this->assertEquals("aBCDEFG", $s->lowercaseFirst());
20 |
21 | // Do not Upper case first
22 | $s = new Stringizer("FiZz");
23 | $this->assertEquals("fiZz", $s->lowercaseFirst(true));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/LowercaseTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("fizz", $s->lowercase());
14 | }
15 |
16 | public function testNoImpactToMultiByte()
17 | {
18 | $s = new Stringizer("こんにちは世界");
19 | $this->assertEquals("こんにちは世界", $s->lowercase());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/MultiByteTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isMultiByte());
14 |
15 | $s = new Stringizer("fòôbàř");
16 | $this->assertEquals(true, $s->isMultiByte());
17 |
18 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
19 | $this->assertEquals(true, $s->isMultiByte());
20 |
21 | $s = new Stringizer("Hello fòô");
22 | $this->assertEquals(true, $s->isMultiByte());
23 | }
24 |
25 | public function testInvValidMultiByte()
26 | {
27 | $s = new Stringizer("");
28 | $this->assertEquals(false, $s->isMultiByte());
29 |
30 | $s = new Stringizer("foobar");
31 | $this->assertEquals(false, $s->isMultiByte());
32 |
33 | $s = new Stringizer("Stringizer");
34 | $this->assertEquals(false, $s->isMultiByte());
35 |
36 | $s = new Stringizer("123");
37 | $this->assertEquals(false, $s->isMultiByte());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/NumberTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isNumber());
14 |
15 | $s = new Stringizer("-1234567890");
16 | $this->assertEquals(true, $s->isNumber());
17 |
18 | $s = new Stringizer("-1");
19 | $this->assertEquals(true, $s->isNumber());
20 |
21 | $s = new Stringizer("-0");
22 | $this->assertEquals(true, $s->isNumber());
23 |
24 | $s = new Stringizer("1");
25 | $this->assertEquals(true, $s->isNumber());
26 |
27 | $s = new Stringizer("0");
28 | $this->assertEquals(true, $s->isNumber());
29 | }
30 |
31 | public function testInValidHasAlpha()
32 | {
33 | $s = new Stringizer("abc123");
34 | $this->assertEquals(false, $s->isNumber());
35 | }
36 |
37 | public function testInValidHasDecimal()
38 | {
39 | $s = new Stringizer("19.99");
40 | $this->assertEquals(false, $s->isNumber());
41 | }
42 |
43 | public function testInValidHasCharacter()
44 | {
45 | $s = new Stringizer("x");
46 | $this->assertEquals(false, $s->isNumber());
47 | }
48 |
49 | public function testInValidAlphaHasMultiByte()
50 | {
51 | $s = new Stringizer("こんにちは");
52 | $this->assertEquals(false, $s->isNumber());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/tests/PadTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("fizzxxxxxx", $s->padRight("x", 10));
15 | }
16 |
17 | public function testPadLeft()
18 | {
19 | $s = new Stringizer("fizz");
20 | $this->assertEquals("xxxxxxfizz", $s->padLeft("x", 10));
21 | }
22 |
23 | public function testPadBothEven()
24 | {
25 | $s = new Stringizer("fizz");
26 | $this->assertEquals("xxxfizzxxx", $s->padBoth("x", 10));
27 | }
28 |
29 | public function testPadBothOdd()
30 | {
31 | $s = new Stringizer("fizz");
32 | $this->assertEquals("xxxfizzxxxx", $s->padBoth("x", 11));
33 | }
34 |
35 | public function testPadRightMultiByte()
36 | {
37 | $s = new Stringizer("文字列のそれ");
38 | $this->assertEquals("文字列のそれxxxx", $s->padRight("x", 10));
39 | }
40 |
41 | public function testPadLeftMultiByte()
42 | {
43 | $s = new Stringizer("文字列のそれ");
44 | $this->assertEquals("xxxx文字列のそれ", $s->padLeft("x", 10));
45 | }
46 |
47 | public function testPadBothMultiByteEven()
48 | {
49 | $s = new Stringizer("文字列のそれ");
50 | $this->assertEquals("xx文字列のそれxx", $s->padBoth("x", 10));
51 | }
52 |
53 | public function testPadBothMultiByteOdd()
54 | {
55 | $s = new Stringizer("文字列のそれ");
56 | $this->assertEquals("xx文字列のそれxxx", $s->padBoth("x", 11));
57 | }
58 |
59 | public function testPadwithZeros()
60 | {
61 | $s = new Stringizer("10");
62 | $this->assertEquals("00010", $s->padLeft("0", 5));
63 |
64 | $s = new Stringizer("10.00");
65 | $this->assertEquals("010.00", $s->padLeft("0", 6));
66 | }
67 |
68 | public function testPadSamplesFromPHPDotNet()
69 | {
70 | $s = new Stringizer("Alien");
71 | $this->assertEquals("Alien ", $s->padRight(" ", 10));
72 |
73 | $s = new Stringizer("Alien");
74 | $this->assertEquals("-=-=-Alien", $s->padLeft("-=", 10));
75 |
76 | $s = new Stringizer("Alien");
77 | $this->assertEquals("__Alien___", $s->padBoth("_", 10));
78 |
79 | $s = new Stringizer("Alien");
80 | $this->assertEquals("Alien_", $s->padRight("___", 6));
81 |
82 | $s = new Stringizer("Alien");
83 | $this->assertEquals("Alien", $s->padRight("*", 3));
84 | }
85 |
86 | /**
87 | * Stringizer doesn't ever send in the wrong pad but unit test completion
88 | * test the class directly
89 | *
90 | * @expectedException InvalidArgumentException
91 | */
92 | public function testPadBadPadType()
93 | {
94 | $pad = new Pad("theString", "padValue", 10, - 1);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/tests/RandomTest.php:
--------------------------------------------------------------------------------
1 | randomAlpha()->getString();
15 |
16 | // Default is size 10
17 | $this->assertEquals(10, $s->length());
18 |
19 | // Confirm is Alpha
20 | $this->assertEquals(true, $s->isAlpha());
21 |
22 | $randomString2 = $s->randomAlpha()->getString();
23 |
24 | $this->assertNotEquals($randomString1, $randomString2);
25 |
26 | // Test non default size
27 | $randomString2 = $s->randomAlpha(20)->getString();
28 | $this->assertEquals(20, $s->length());
29 | }
30 |
31 | public function testValidNumericRandom()
32 | {
33 | // Default is size 10
34 | $s = new Stringizer("");
35 | $randomNum1 = $s->randomNumeric()->getString();
36 |
37 | // Default is size 10
38 | $this->assertEquals(10, $s->length());
39 |
40 | // Confirm is Number, this potentially can fail because
41 | // a value with zero up front would make the value a string
42 | //$this->assertEquals(true, $s->isNumber());
43 | $s2 = new Stringizer(intval($s->getString()));
44 | $this->assertEquals(true, $s2->isNumber());
45 |
46 | $randonNum2 = $s->randomNumeric()->getString();
47 |
48 | $this->assertNotEquals($randomNum1, $randonNum2);
49 |
50 | // Test non default size
51 | $s->randomNumeric(20)->getString();
52 | $this->assertEquals(20, $s->length());
53 | }
54 |
55 | public function testValidAlphaNumericRandom()
56 | {
57 | // Default is size 10
58 | $s = new Stringizer("");
59 | $randomString1 = $s->randomAlphanumeric()->getString();
60 |
61 | // Default is size 10
62 | $this->assertEquals(10, $s->length());
63 |
64 | // Confirm is AlphaNumeric
65 | $this->assertEquals(true, $s->isAlphaNumeric());
66 |
67 | $randomString2 = $s->randomAlphanumeric()->getString();
68 |
69 | $this->assertNotEquals($randomString1, $randomString2);
70 |
71 | // Test non default size
72 | $randomString2 = $s->randomAlphanumeric(20)->getString();
73 | $this->assertEquals(20, $s->length());
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tests/RemoveNonAsciiTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("FizzBuzz Fizz Buzz Fizz Buzz", $s->removeNonAscii());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/RemoveWhitespaceTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("FizzBuzzFizzBuzzFizzBuzz", $s->removeWhitespace());
16 |
17 | $s = new Stringizer(" Ș Ŧ ŗ Í ñ ĝ ì z ĕ ŕ ");
18 | $this->assertEquals("ȘŦŗÍñĝìzĕŕ", $s->removeWhitespace());
19 |
20 | // For some reason HHVM fails on this, commenting for now, need to revisit
21 | /*
22 | * $s = new Stringizer(" Hello \t \n \r \x0B World ");
23 | * $this->assertEquals("HelloWorld", $s->removeWhitespace());
24 | */
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/RepeatTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("*", $s->repeat(0));
14 |
15 | $s = new Stringizer("*");
16 | $this->assertEquals("*****", $s->repeat(5));
17 |
18 | $s = new Stringizer("* ");
19 | $this->assertEquals("* * * * * ", $s->repeat(5));
20 | }
21 |
22 | public function testRepeatNonNumeric()
23 | {
24 | $s = new Stringizer("*");
25 | $this->assertEquals("*", $s->repeat('x'));
26 | }
27 |
28 | public function testRepeatNegativeNumeric()
29 | {
30 | $s = new Stringizer("*");
31 | $this->assertEquals("*", $s->repeat('-99'));
32 | }
33 |
34 | public function testInValidAlphaHasMultiByte()
35 | {
36 | $s = new Stringizer("こ");
37 | $this->assertEquals("こ", $s->repeat(1));
38 |
39 | $s = new Stringizer("こ");
40 | $this->assertEquals("こここここ", $s->repeat(5));
41 |
42 | $s = new Stringizer("こんにちは");
43 | $this->assertEquals("こんにちはこんにちは", $s->repeat(2));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/ReplaceAccentsTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("FizzoeBuzz Fizz Buzz Fizz Buzze", $s->replaceAccents());
19 |
20 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
21 | $this->assertEquals("STrIngizer", $s->replaceAccents());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/ReplaceTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("Fizz Bar Fizz Bar Fizz Bar", $s->replace("Buzz", "Bar"));
14 | }
15 |
16 | public function testReplaceMultipleMatchesWithSameReplacement()
17 | {
18 | $s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
19 | $this->assertEquals("Bar Bar Bar Bar Bar Bar", $s->replace(array(
20 | "Fizz",
21 | "Buzz"
22 | ), "Bar"));
23 | }
24 |
25 | public function testReplaceMultipleMatchesSameSizeArrays()
26 | {
27 | $s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
28 | $this->assertEquals("Foo Bar Foo Bar Foo Bar", $s->replace(array(
29 | "Fizz",
30 | "Buzz"
31 | ), array(
32 | "Foo",
33 | "Bar"
34 | )));
35 | $this->assertEquals("Buzz Fizz Buzz Fizz Buzz Fizz", $s->replace(array(
36 | "Foo",
37 | "Bar"
38 | ), array(
39 | "Buzz",
40 | "Fizz"
41 | )));
42 | }
43 |
44 | public function testStringReplaceIncaseSensitive()
45 | {
46 | // Replacement becase the case is not matching
47 | $s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
48 | $this->assertEquals("Fizz Buzz Fizz Buzz Fizz Buzz", $s->replace("buzz", "bar"));
49 |
50 | $s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
51 | $this->assertEquals("Fizz bar Fizz bar Fizz bar", $s->replaceIncaseSensitive("buzz", "bar"));
52 | }
53 |
54 | public function testMultiByte()
55 | {
56 | $s = new Stringizer("Fizz列Buzz列Fizz列Buzz列Fizz列Buzz");
57 | $this->assertEquals("Fizz Buzz Fizz Buzz Fizz Buzz", $s->replace("列", " "));
58 | $this->assertEquals("Fizz列Buzz列Fizz列Buzz列Fizz列Buzz", $s->replace(" ", "列"));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tests/ReverseTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("god", $s->reverse());
14 |
15 | $s = new Stringizer("stop");
16 | $this->assertEquals("pots", $s->reverse());
17 |
18 | $s = new Stringizer("mad");
19 | $this->assertEquals("dam", $s->reverse());
20 |
21 | $s = new Stringizer("mood");
22 | $this->assertEquals("doom", $s->reverse());
23 |
24 | $s = new Stringizer("文字列のそれ");
25 | $this->assertEquals("れその列字文", $s->reverse());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/RgbColorTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isRgbColor());
14 |
15 | $s = new Stringizer("rgb(0,0,0)");
16 | $this->assertEquals(true, $s->isRgbColor());
17 |
18 | $s = new Stringizer("rgb(255,255,255)");
19 | $this->assertEquals(true, $s->isRgbColor());
20 | }
21 |
22 | public function testInvValidRgbColor()
23 | {
24 | $s = new Stringizer("");
25 | $this->assertEquals(false, $s->isRgbColor());
26 |
27 | $s = new Stringizer("rgb(255,256,255)");
28 | $this->assertEquals(false, $s->isRgbColor());
29 |
30 | $s = new Stringizer("rgb(255,255,255)");
31 | $this->assertEquals(true, $s->isRgbColor());
32 |
33 | $s = new Stringizer("rgb(25.5,255,255)");
34 | $this->assertEquals(false, $s->isRgbColor());
35 |
36 | $s = new Stringizer("rgb(01,255,255)");
37 | $this->assertEquals(false, $s->isRgbColor());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/SemverTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->isSemver());
14 |
15 | $s->setString("0.0.1");
16 | $this->assertEquals(true, $s->isSemver());
17 |
18 | $s->setString("v0.0.1");
19 | $this->assertEquals(true, $s->isSemver());
20 |
21 | $s->setString("0.0.1-beta");
22 | $this->assertEquals(true, $s->isSemver());
23 |
24 | $s->setString("0.0.1-beta.10");
25 | $this->assertEquals(true, $s->isSemver());
26 |
27 | $s->setString("1.0.0-3.14.6");
28 | $this->assertEquals(true, $s->isSemver());
29 |
30 | $s->setString("1.0.0-x-3.14.6.z");
31 | $this->assertEquals(true, $s->isSemver());
32 | }
33 |
34 | public function testInValidSemver()
35 | {
36 | $s = new Stringizer("1");
37 | $this->assertEquals(false, $s->isSemver());
38 |
39 | $s->setString("1.0");
40 | $this->assertEquals(false, $s->isSemver());
41 |
42 | $s->setString("v1.0");
43 | $this->assertEquals(false, $s->isSemver());
44 |
45 | $s->setString("1.01.0");
46 | $this->assertEquals(false, $s->isSemver());
47 |
48 | $s->setString("1.1.01");
49 | $this->assertEquals(false, $s->isSemver());
50 |
51 | $s->setString("1.1!.1");
52 | $this->assertEquals(false, $s->isSemver());
53 |
54 | $s->setString("1.1.1-9+");
55 | $this->assertEquals(false, $s->isSemver());
56 |
57 | $s->setString("1.1.1z");
58 | $this->assertEquals(false, $s->isSemver());
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tests/SentenceCountTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(0, $s->sentenceCount());
15 | }
16 |
17 | public function testValid1Sentence()
18 | {
19 | $s = new Stringizer("Jack jumped over the candle stick.");
20 | $this->assertEquals(1, $s->sentenceCount());
21 | }
22 |
23 | public function testValid3Sentences()
24 | {
25 | $s = new Stringizer("ȘŦŗÍñĝìzĕŕ jumped over the stringy stick. ȘŦŗÍñĝìzĕŕ jumped over the stringy stick again! Or did it?");
26 | $this->assertEquals(3, $s->sentenceCount());
27 | }
28 |
29 | public function testValidMultiSentence()
30 | {
31 | $s = new Stringizer("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sed turpis ac elit viverra luctus id nec ex. Pellentesque consequat leo velit,
32 | pulvinar varius mauris interdum vehicula. Cras nisl risus, posuere ac mi ac, tempus blandit nunc. Praesent tempus lorem id urna mollis,
33 | quis mollis nisi convallis. Mauris nisi odio, placerat vitae risus eu, maximus tincidunt diam. Pellentesque hendrerit mi ut nunc lacinia
34 | tempus. Fusce ac eleifend nunc, consectetur elementum odio. Sed faucibus scelerisque lacus at pharetra. Etiam eu rutrum nulla. Suspendisse potenti.
35 | In interdum diam eros, vitae efficitur lacus dignissim vitae. Praesent malesuada euismod quam in volutpat. Aenean non varius ipsum. Vestibulum ante
36 | ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam euismod non urna ut porttitor. In euismod ornare felis, sed eleifend
37 | elit tempus ut! Vivamus auctor, odio quis commodo lacinia, elit turpis euismod dolor, ut mollis lacus risus non diam. In lorem neque, dictum et sapien
38 | ac, maximus luctus enim. Integer sed ex ac enim tempor commodo in dignissim felis. Phasellus at pulvinar mi. Vivamus quis ante at lectus lacinia
39 | condimentum non sit amet justo. Aenean eget leo semper, dignissim ligula nec, rhoncus lorem. Nullam vestibulum aliquet enim, a egestas est
40 | pellentesque at. Curabitur purus tortor, suscipit quis lacus quis, consequat rutrum felis.Duis vestibulum elit vel eros feugiat, eget ullamcorper dui
41 | condimentum. Maecenas maximus pretium diam, eget gravida odio malesuada consectetur. Fusce ullamcorper porta magna, sit amet elementum nisl porttitor vitae.
42 | Curabitur convallis in mauris eu posuere. Suspendisse eu condimentum leo, id laoreet ex. Maecenas id neque tristique, dapibus quam a, blandit leo. Fusce
43 | ornare semper massa, sed aliquet tortor condimentum ac. Nullam semper porta rutrum. Morbi arcu nunc, porta ut tellus varius, suscipit iaculis felis. Vestibulum
44 | ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse vestibulum faucibus dui, et cursus arcu malesuada quis. Sed
45 | eget sapien sit amet enim pretium mattis. Aenean pulvinar auctor leo, in lacinia urna ultricies in. Suspendisse at velit vestibulum, maximus risus sit amet,
46 | fringilla ipsum? Nullam congue, quam et tincidunt placerat, diam felis semper erat, at tempor libero neque eget magna. Quisque fermentum, massa eu sollicitudin
47 | mollis, libero urna tincidunt enim, laoreet laoreet nisl ligula sed felis. Ut id risus sagittis, tincidunt sem facilisis, tincidunt diam. Cras auctor mauris vel
48 | libero bibendum, eu sodales est tempus. Sed molestie eget ante a rhoncus. Praesent semper suscipit leo eget pharetra. In luctus mi dui, eget pellentesque arcu
49 | auctor nec. Suspendisse potenti.");
50 | $this->assertEquals(45, $s->sentenceCount());
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/SplitTest.php:
--------------------------------------------------------------------------------
1 | split(" ");
14 | $this->assertEquals(2, count($array));
15 | $this->assertEquals("Fizz", $array[0]);
16 | $this->assertEquals("Buzz", $array[1]);
17 |
18 | $s = new Stringizer("文字列のそれ");
19 | $array = $s->split("の");
20 | $this->assertEquals(2, count($array));
21 | $this->assertEquals("文字列", $array[0]);
22 | $this->assertEquals("それ", $array[1]);
23 |
24 | $s = new Stringizer("Foo|Bar|Fizz|Buzz|");
25 | $array = $s->split("|");
26 | $this->assertEquals(5, count($array));
27 | $this->assertEquals("Foo", $array[0]);
28 | $this->assertEquals("Bar", $array[1]);
29 | $this->assertEquals("Fizz", $array[2]);
30 | $this->assertEquals("Buzz", $array[3]);
31 | $this->assertEquals("", $array[4]);
32 | }
33 |
34 | public function testSplitValidButNoDelimiterMatch()
35 | {
36 | $s = new Stringizer("Fizz Buzz");
37 | $array = $s->split(",");
38 | $this->assertEquals(1, count($array));
39 | $this->assertEquals("Fizz Buzz", $array[0]);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/StartsWithTest.php:
--------------------------------------------------------------------------------
1 | assertEquals(true, $s->startsWith("文"));
14 |
15 | $s = new Stringizer("文字列のそれ");
16 | $this->assertEquals(false, $s->startsWith("文文文文"));
17 |
18 | $s = new Stringizer("Fizz Buzz");
19 | $this->assertEquals(true, $s->startsWith("Fizz B"));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/StringizerTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("fizz", $s);
14 | }
15 |
16 | public function testNoChangeToOriginal()
17 | {
18 | $s = new Stringizer("fizz");
19 | $this->assertEquals("fizz", $s->getStringOriginal());
20 | }
21 |
22 | /**
23 | * @expectedException InvalidArgumentException
24 | */
25 | public function testInvalidArgumentNull()
26 | {
27 | new Stringizer(null);
28 | }
29 |
30 | /**
31 | * @expectedException InvalidArgumentException
32 | */
33 | public function testInvalidArguementArrayEmpty()
34 | {
35 | new Stringizer(array());
36 | }
37 |
38 | /**
39 | * @expectedException InvalidArgumentException
40 | */
41 | public function testInvalidArguementArray()
42 | {
43 | new Stringizer(array(
44 | "string"
45 | ));
46 | }
47 |
48 | /**
49 | * @expectedException InvalidArgumentException
50 | */
51 | public function testInvalidObjectWithNoToString()
52 | {
53 | new Stringizer((object) array());
54 | }
55 |
56 | public function testSetter()
57 | {
58 | $s = new Stringizer("fizz");
59 | $this->assertEquals("fizz", $s);
60 |
61 | $s->setString("buzz");
62 | $this->assertEquals("buzz", $s);
63 | }
64 |
65 | public function testEncoding()
66 | {
67 | $s = new Stringizer("Fizz Buzz");
68 |
69 | $s->setEncoding("iso-8859-1");
70 | $this->assertEquals("iso-8859-1", $s->getEncoding());
71 |
72 | $s->setEncoding("UTF-8");
73 | $this->assertEquals("UTF-8", $s->getEncoding());
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/tests/StripPunctuationTest.php:
--------------------------------------------------------------------------------
1 | assertEquals("Hello World Its me stringizer", $s->stripPunctuation());
14 | }
15 |
16 | public function testValidStripMorePunctuation()
17 | {
18 | $s = new Stringizer("*-=!'\",?!Hello* World][");
19 | $this->assertEquals("Hello World", $s->stripPunctuation());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/StripTagsTest.php:
--------------------------------------------------------------------------------
1 | Hello