Skip to content

embmike/fixed-string-embedded-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fixed-string-embedded-cpp

A small fixed-capacity string type for embedded C++ projects.

mne::embedded::fixed_string<N> stores characters in a statically sized std::array<char, N> and avoids dynamic allocation in the string object itself. It is intended for microcontroller code where bounded memory usage, predictable behavior and simple interfaces matter.

Status

This repository is an initial extraction of fixed_string.hpp from a private embedded C++ framework.

The header is usable as a starting point, but the repository is still young:

  • unit tests are not included yet,
  • CI is not configured yet,
  • the public API may still change.

Features

  • fixed maximum capacity at compile time,
  • null-terminated internal character buffer,
  • assignment from std::string_view,
  • conversion to std::string_view,
  • c_str(), data(), size(), empty(), capacity() and clear(),
  • simple error code for assignment overflow/out-of-range cases.

Repository Layout

include/
  mne/
    embedded/
      fixed_string.hpp
README.md
LICENSE

Usage

#include "mne/embedded/fixed_string.hpp"

#include <string_view>

void consume(std::string_view text);

int main()
{
    mne::embedded::fixed_string<32> message {};

    const auto result = message.assign("Hello embedded C++");
    if (result == mne::embedded::FixedStringError::none)
    {
        consume(message);
    }
}

Design Notes

The type is meant for code where the maximum string size is known at compile time. It can be useful for small status texts, protocol fields, labels, diagnostics or configuration values with fixed upper bounds.

For strict embedded projects, review the header against your project rules before production use. In particular, check allowed standard library headers, stream usage, exception policy and naming conventions.

Planned Improvements

  • Add unit tests.
  • Add examples.
  • Review includes and remove unused dependencies.
  • Add CI for common compilers.

License

This project is licensed under the terms of the License: MIT

About

A small fixed-capacity string type for embedded C++ projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages