Skip to content

gowthaman-01/pystring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pystring

A Python-style string manipulation library in modern C++.

  • Python-like slicing: s(1, 4)"bcd"
  • Negative indices
  • +, *, ==, [] operators
  • split(), join(), strip(), startswith(), endswith(), count()
  • Prefix/suffix checks: starts_with(), ends_with()
  • Substring counting: count("na")2

Installation

  1. Clone pystring into your own project directory:
git clone https://github.com/gowthaman-01/pystring.git
  1. Your project structure might look like:
your_project/
├── CMakeLists.txt
├── main.cpp
└── pystring/              ← cloned here
  1. In your own CMakeLists.txt, add these lines to build your app and link pystring:
add_executable(my_app main.cpp)

add_subdirectory(pystring)
target_link_libraries(my_app PRIVATE pystring::pystring)

💡 Replace my_app with the name of your own CMake executable target.

⚠️ Warning

This library uses modern C++ features like if constexpr and std::is_arithmetic_v, so you must enable C++17 in your project:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

If you don’t, you may get errors like:

error: no template named 'is_arithmetic_v' in namespace 'std'

Usage

See docs/usage.md for more detailed examples.

#include <pystring.hpp>

int main() {
    pystring s("hello world");
    auto sliced = s(0, 5);
    std::cout << sliced.get() << "\n";    // "hello"
}

About

lightweight c++ library that brings pythonic string manipulation to c++

Resources

Stars

Watchers

Forks