Skip to main content

Custom string utility functions implemented from scratch

Project description

Strio

A Python library that implements custom string utility functions from scratch without using Python's built-in string methods.

Features

Strio provides a comprehensive set of string manipulation functions, all implemented manually using basic operations, loops, and character-level manipulations. This makes it an excellent learning resource and a foundation for understanding how string operations work under the hood.

Installation

pip install strio

Available Functions

  • capitalize(s) - Capitalize the first character and lowercase the rest
  • casefold(s) - Return a casefolded copy of the string
  • count(s, sub, start=0, end=None) - Count occurrences of substring
  • endswith(s, suffix, start=0, end=None) - Check if string ends with suffix
  • find(s, sub, start=0, end=None) - Find first occurrence of substring (returns -1 if not found)
  • index(s, sub, start=0, end=None) - Find first occurrence of substring (raises ValueError if not found)
  • isdigit(s) - Check if all characters are digits
  • islower(s) - Check if all cased characters are lowercase
  • isupper(s) - Check if all cased characters are uppercase
  • strip(s, chars=None) - Remove leading and trailing whitespace (or specified characters)
  • lstrip(s, chars=None) - Remove leading whitespace (or specified characters)
  • rstrip(s, chars=None) - Remove trailing whitespace (or specified characters)
  • replace(s, old, new, count=-1) - Replace occurrences of substring
  • split(s, sep=None, maxsplit=-1) - Split string by delimiter
  • rsplit(s, sep=None, maxsplit=-1) - Split string from right
  • swapcase(s) - Swap case of all characters

Usage Examples

from strio import capitalize, count, find, replace, split

# Capitalize a string
result = capitalize("hello world")
print(result)  # "Hello world"

# Count occurrences
count_val = count("hello hello", "hello")
print(count_val)  # 2

# Find substring
index = find("hello world", "world")
print(index)  # 6

# Replace substrings
new_str = replace("hello world", "world", "python")
print(new_str)  # "hello python"

# Split string
parts = split("a,b,c", ",")
print(parts)  # ["a", "b", "c"]

# Split on whitespace
words = split("hello world python")
print(words)  # ["hello", "world", "python"]

More Examples

from strio import (
    isdigit, islower, isupper, strip, 
    lstrip, rstrip, swapcase, endswith
)

# Check string properties
print(isdigit("123"))      # True
print(islower("hello"))    # True
print(isupper("HELLO"))    # True

# Strip whitespace
print(strip("  hello  "))   # "hello"
print(lstrip("  hello  "))  # "hello  "
print(rstrip("  hello  "))  # "  hello"

# Swap case
print(swapcase("Hello"))    # "hELLO"

# Check suffix
print(endswith("hello.py", ".py"))  # True

Development

Running Tests

pytest strio/tests/

Building the Package

python setup.py sdist bdist_wheel

Publishing to PyPI

twine upload dist/*

Implementation Details

All functions in Strio are implemented from scratch without using Python's built-in string methods. The implementation uses:

  • Character-level operations with ord() and chr()
  • Manual loops and indexing
  • Basic string slicing
  • No reliance on built-in string methods like .lower(), .upper(), .strip(), etc.

This makes Strio a great educational resource for understanding string manipulation algorithms.

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strio-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strio-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file strio-0.1.0.tar.gz.

File metadata

  • Download URL: strio-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for strio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5935ea8c8acaadd35ec9f573e3339fecb3f0fbaef98a3c8792c769536d22ef16
MD5 17216d3b99b7b87441d1327ff7ff8cc0
BLAKE2b-256 8bbf0b4a0d79d0f74de0dbe2a6b67ff5d5ecf20b1a8bdf8068a4ec564c67a32f

See more details on using hashes here.

File details

Details for the file strio-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: strio-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for strio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77de794730eae793a3e0ba73776a9080ccc95f1e63e9478a97759057abf483d5
MD5 18f8cb1fd10c85333395125e6b5c6db9
BLAKE2b-256 d98a105552c8363d065a6232535b8f41c24da9f789d10fbab8db140c2d8ad394

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page