Thanks to visit codestin.com
Credit goes to github.com

Skip to content

seanpd/cpp_fixedstr_utility

Repository files navigation

FixedStr utility C++ class

1-feb-2021

Sean Dempsey

This is a very simple string class which attempts to allocate its storage within the object itself using an embedded array. If there's insufficient space to store the content it automatically uses the heap.

Let's say you need a string to hold what's normally a smallish size. You might do something like this:

char myStr [20];

This is allocated efficiently on the stack. But what if there's a chance the string can overflow? That's the problem FixedStr tries to solve.

You'd say:

FixedStr<20>  myStr;

WFixedStr<20> myWideCharStr;

The unit test FixedStrTest.cpp has example usage. It has functions for copying, appending, printf-type formatting etc.

Notes:

  1. This is not intended to be a comprehensive string class. If you need more stuff, use std::string or whatever. It only has the bare essentials.

  2. It's intended only for strings expected to fit inside. Otherwise this doesn't provide much value.

  3. The main goal is to avoid unneeded heap usage.

About

FixedStr utility C++ class

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages