Skip to content

Bucephalus-Studios/stevensStringLib

Repository files navigation

stevensStringLib

Static Badge

Welcome! StevensStringLib is a string library for the rest of us who just want working with strings in C++ to be easier. We have lots of convenient functions for manipulating and processing strings. Check them out below!

Simple installation and usage:

You can use this string library with the Beldum Package Manager:

Install

Import "stevensStringLib.h" into your own project

or

mkdir new_project
cd new_project
beldum init
beldum install stevensStringLib

Usage

src/main.cpp

#include "stevensStringLib.h"

int main()
{
    stevensStringLib::containsOnly("111011112222", "12");
    return 0;
}

Demo

Separate a string:

std::string myString = "Charmander,Squirtle,Bulbasaur";

std::vector<std::string> myVector = stevensStringLib::separate(myString, ',');

// myVector == {"Charmander, "Squirtle", "Bulbasaur"};

Remove all whitespace from a string:

std::string data = "   Flowers,\nRamona,  Toronto\r,Canada\t,212-664-7665    "

std::string cleanData = stevensStringLib::removeWhitespace(data);

// cleanData = "Flowers,Ramona,Toronto,Canada,212-664-7665"

Wrap a string to a certain width:

std::string textToWrap = "111222333";

std::string wrappedText = stevensStringLib::wrapToWidth(textToWrap, 3);

// wrappedText == "111\n222\n333\n";

Requirements

To use the library: C++ 17

If you'd like to build the test or benchmark files: CMake 3.22.1

Easy Installation!

To get started, you can copy and paste the stevensStringLib.h file into your project's folder.

Then you should add an include statement at the top of the .cpp file you would like to use the library in. Make sure to NOT include the { } characters in your statement.

#include "{insert relative path from file to the library here}stevensStringLib.h"

For example, if stevensStringLib.h is in the same folder as your .cpp file, then it would look like this:

#include "stevensStringLib.h"

In your .cpp file you can give the library namespace a different name if you'd rather not keep typing stevensStringLib:

namespace strlib = stevensStringLib;

And then you're good to go!

std::vector<std::string> words = strlib::separate("Hello world!, ' ');

Documentation

The documentation for this library is written to a series of offline webpages that can be viewed by clicking the "Open Documation" link in the docs folder. This documentation was generated by Doxygen.

If you're viewing this README file as one of the Doxygen webpages, you can view the list of functions and all of their documentation by clicking here: stevensStringLib.h.

Testing

stevensStringLib contains a suite of tests to validate its functionality within the testing folder. All testing is carried out with Google Test.

To run these tests on your computer, you should use the cmake tool in the testing folder by running the command cmake -S . -B ./build. This will generate an makefile to create an executable in the testing/build folder. Then, go to the testing/build folder and run the command make. Once you have done this, you should have an executable named stevensStringLibTest in the testing/build folder which you can run the tests with.

Benchmarking

stevensStringLib also contains benchmarking so you can see how fast and efficient its functions are in the benchmarking folder. All benchmarking is carried out with Google Benchmark.

To run the benchmark on your computer, the process of creating the benchmark executable works very much the same way as the test executable: you should use the cmake tool in the benchmarking folder by running the command cmake -S . -B ./build. This will generate a makefile to create an executable in the benchmarking/build folder. Then, go to the benchmarking/build folder and run the command make. Once you have done this, you should have an executable named stevensStringLibBenchmark in the benchmarking/build folder which you can run to benchmark the library.

Special Thanks

Julien Jorge for his detailed code review

r/cpp for their collective critiques and contributions

Rhymu for his guide on using CMake to link GoogleTest with a unit test program

About

Simple C++ library with useful string functions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •