2017 © Pedro Peláez
 

library string-util

Provides a consistent, self-explaining layer to accomplish common string operations.

image

wuzzitor/string-util

Provides a consistent, self-explaining layer to accomplish common string operations.

  • Monday, July 20, 2015
  • by Matthimatiker
  • Repository
  • 3 Watchers
  • 2 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

StringUtil

Build Status Coverage Status, (*1)

Overview

This library provides a consistent, self-explaining layer to accomplish string related tasks., (*2)

Speaking method names make string operations more readable and reveal the intention clearly. Please compare the following, common snippets regarding readability:, (*3)

// Native:
if (strpos($log, 'failure') !== false) {
    // [...]
}

// With StringUtil:
if (StringUtil::contains($log, 'failure')) {
    // [...]
}

In contrast to the built-in PHP string functions, the library provides methods with consistent signatures, which always expect the subject string as first parameter., (*4)

Known Restrictions

This library is meant for common, light-weight string operations. It is currently not designed for heavy, complex string tasks such as transparent charset handling., (*5)

Installation

Add the following to your composer.json (see getcomposer.org):, (*6)

"require" :  {
    // ...
    "wuzzitor/string-util": "~1.0"
}

Concept

The library provides a single class (Wuzzitor\StringUtil), whose static methods are the entry points for all string operations., (*7)

All methods are stateless to ensure full testability and to avoid code that is hard to debug., (*8)

Usage

Example:, (*9)

use Wuzzitor\StringUtil;

$filename = 'example.php';
$withoutExtension = StringUtil::removeSuffix($filename, '.php);
// $withoutExtension == 'example'

The following signatures show all available operations:, (*10)

  • StringUtil::startsWith(string $subject, string $prefix) : boolean
  • StringUtil::endsWith(string $subject, string $suffix) : boolean
  • StringUtil::contains(string $subject, string $needle) : boolean
  • StringUtil::containsAny(string $subject, string[] $needles) : boolean
  • StringUtil::containsAll(string $subject, string[] $needles) : boolean
  • StringUtil::removePrefix(string $subject, string $prefix) : string
  • StringUtil::removeSuffix(string $subject, string $suffix) : string
  • StringUtil::replace(string $subject, string $search, string $replace) : string
  • StringUtil::replace(string $subject, array<string, string> $searchReplaceMapping) : string

License

Code released under the MIT license., (*11)

The Versions

20/07 2015

dev-master

9999999-dev

Provides a consistent, self-explaining layer to accomplish common string operations.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

20/07 2015

1.0.0

1.0.0.0

Provides a consistent, self-explaining layer to accomplish common string operations.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

20/07 2015

0.0.1

0.0.1.0

Provides a consistent, self-explaining layer to accomplish common string operations.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires