Metadata-Version: 2.4
Name: strsplitter
Version: 1.0.2
Summary: A string splitting utility with customizable splitters and filtering.
Author-email: Kessoum Khaled <khaled.kessoum@univ-bejaia.dz>
Project-URL: Homepage, https://github.com/ckalandk/strsplit
Project-URL: Issues, https://github.com/ckalandk/strsplit/issues
Keywords: string,split,utility,filtering
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: click>=8.2.1
Dynamic: license-file

# strsplit

A flexible string splitting utility for Python that allows splitting by different strategies and filtering the results using predicates.
This package is inspired by the abseil StrSplit library.

[![PyPI version](https://img.shields.io/pypi/v/strsplitter.svg)](https://pypi.org/project/strsplitter/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/strsplitter.svg)](https://pypi.org/project/strsplitter/)
[![Build](https://github.com/ckalandk/strsplit/actions/workflows/test.yml/badge.svg)](https://github.com/ckalandk/strsplit/actions)
[![License](https://img.shields.io/github/license/ckalandk/strsplit.svg)](LICENSE)

## Features

- Split by a delimiter string (`SplitByStr`)
- Split by fixed length chunks (`SplitByLength`)
- Split by any character in a set (`SplitByAnyChar`)
- Control maximum splits with `maxsplit` parameter (default `-1` = no limit)
- Filter out substrings via a predicate function in the main `split` function

## Usage

```python
from strsplit import split, SplitByStr, SplitByAnyChar, SplitByLength
# Split using a string delimiter
it = split(text="a,b,c", ",") # <=> it = split(text="a,b,c", splitter=SplitByStr(","))
print(list(it)) # --> ['a', 'b', 'c']

# Split by any chars
it = split(text="a,b;c-d", [",", ";", "-"]) # <=> it = split(text="a,b,c", splitter=SplitByAnChar(",;-"))
print(list(it)) # --> ['a', 'b', 'c', 'd']

# Split by length
it = split(text="abcdef", splitter=SplitByLength(2)) # <=> it = split(text="abcdef", 2)
print(list(it)) # --> ["ab", "cd", "ef"]

# Use a predicat to filter the result 
it = split(",a,,b,c,", ",", lambda x : len(x) > 0)
print(list(it)) # --> ['a', 'b', 'c']

# Limit the number of substr
# Every splitter accepts another parameter maxsplit to limit the number of splits
it = split(text="a,b,c,d", SplitByStr(delimiter=",", maxsplit=2))
print(list(it)) # --> ['a', 'b']
```
