Skip to content

PString: A C++ String Library with Python-style Operations

License

Notifications You must be signed in to change notification settings

EPTansuo/PString

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: BSD3

PString: A C++ String Library with Python-style Operations

PString is a C++ string library designed to emulate the behavior and functionality of Python's str type. Developed as a modified component of the sapy project.

Install

git clone https://github.com/EPTansuo/PString
cd PString && mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make && sudo make install 

Example

demo.cpp:

#include <iostream>
#include <pstring.h>

int main(){
    PString str = "  Hello, World!  ";

    // Python-style split
    auto str_split = str.split(",");
    std::cout << str_split[0].upper() << std::endl;
    
    // Python-style join
    auto str_joined = PString(":").join(str_split);
    std::cout << str_joined << std::endl;

    // Python-style slice
    auto str_sliced = str.slice(6, 1, -1);
    std::cout << str_sliced << std::endl;

    // Python-style strip
    auto str_stripped = str.strip();
    std::cout << str_stripped << std::endl;

    // ...
}

Compile and run:

g++ demo.cpp -lpstring -o demo
./demo

Bug List

  • " \r\n\thello world\t\r\n ".rstrip
  • " \r\n\thello world\t\r\n ".rsplit
  • " \r\n\thello world\t\r\n ".expandtabs
  • "'\"\\".strip
  • "'\"\\".lstrip
  • "\t\n\r\x0b\x0c".strip
  • "\t\n\r\x0b\x0c".lstrip
  • "\t\n\r\x0b\x0c".rstrip
  • "\t\n\r\x0b\x0c".split
  • "\t\n\r\x0b\x0c".rsplit
  • "\t\n\r\x0b\x0c".splitlines
  • "4t\x0cGF\x0cU'.split"
  • "4t\x0cGF\x0cU'.split(maxsplit=)"
  • '\x0bW4inVjunmlP\t'.rsplit(maxsplit=1)"
  • 'AFv\tDE4x8Y19\x0c VsIV7PlYwV6dk1xn0 Ik'.rsplit('A', maxsplit=1)

Description:

  • means the bug haven't fixed yet.
  • means the bug have been fixed.

Limitations

  • No support for Unicode character operations.

About

PString: A C++ String Library with Python-style Operations

Resources

License

Stars

Watchers

Forks

Packages

No packages published