定制 danielstjules/sliceable-stringy 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danielstjules/sliceable-stringy

Composer 安装命令:

composer require danielstjules/sliceable-stringy

包简介

Python string slices in PHP

README 文档

README

Python string slices in PHP. The class extends Stringy, and implements the ArrayAccess interface.

Build Status

Installation

If you're using Composer to manage dependencies, you can include the following in your composer.json file:

"require": {
    "danielstjules/sliceable-stringy": "dev-master"
}

Then, after running composer update or php composer.phar update, you can load the class using Composer's autoloader:

require 'vendor/autoload.php';

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

use SliceableStringy\SliceableStringy as S;

$sliceable = S::create('Fòô Bàř', 'UTF-8');

Specific offset

$sliceable[1];    // 'ò'
$sliceable['-2']; // 'à'

Using start and stop

$sliceable[':'];   // 'Fòô Bàř'
$sliceable['4:'];  // 'Bàř'
$sliceable['4:6']; // 'Bà'

Negative indices

$sliceable['-1:'];  // 'ř'
$sliceable[':-1'];  // 'Fòô Bà'
$sliceable['-3:6']; // 'Bà'
$sliceable['2:-6']; // ''

Passing a step

$sliceable['::-1'];   // 'řàB ôòF'
$sliceable['::2'];    // 'FôBř'
$sliceable['-3::-2']; // 'BôF'

Possible exceptions

$sliceable[20];        // OutOfBoundsException
$sliceable['1:2:3:4']; // InvalidArgumentException, too many slice args
$sliceable['::0'];     // InvalidArgumentException, step cannot equal 0

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.

统计信息

  • 总下载量: 51.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 47
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 47
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固