Download the PHP package danielstjules/sliceable-stringy without Composer
On this page you can find all versions of the php package danielstjules/sliceable-stringy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danielstjules/sliceable-stringy
More information about danielstjules/sliceable-stringy
Files in danielstjules/sliceable-stringy
Package sliceable-stringy
Short Description Python string slices in PHP
License MIT
Homepage https://github.com/danielstjules/SliceableStringy
Informations about the package sliceable-stringy
SliceableStringy
Python string slices in PHP. The class extends
Stringy, and implements the
ArrayAccess
interface.
- Installation
- Overview
- Examples
- Implementation Fidelity
- TL;DR
Installation
If you're using Composer to manage dependencies, you can include the following in your composer.json file:
Then, after running composer update
or php composer.phar update
, you can
load the class using Composer's autoloader:
Overview
SliceableStringy
returns a slice when passed a string offset containing
one or more colons. Up to 3 arguments may be passed: 'start:stop:step'
.
Start, which indicates the starting index of the slice, defaults to the first
character in the string if step is positive, and the last character if negative.
Stop, which indicates the exclusive boundary of the range, defaults to the
length of the string if step is positive, and before the first character if
negative. And step allows the user to include only every nth character in the
result, with its sign determining the direction in which indices are sampled.
Just like Stringy
, SliceableStringy
is immutable and returns a new
instance with each slice.
Examples
Specific offset
Using start and stop
Negative indices
Passing a step
Possible exceptions
Implementation Fidelity
A number of specs in spec/SliceableStringySpec.php
assert that the library
mimics Python's native slice notation. On top of the handful of unit tests,
spec/fixtures/resultGenerator.py
has been used to generate test fixtures.
Each of the slices in expectedResults.csv
are checked against SliceableStringy
to ensure correct functionality.
TL;DR
Butchering two languages with a single library.