Skip to content
Snippets Groups Projects
Commit 662069f4 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add Pascal::String::max_size() method

Rename len() method to length() to align with std::string.
parent a08bed3b
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2867 passed
......@@ -28,19 +28,25 @@
namespace Pascal {
// Statically-allocated String
template <size_t size>
class String {
static_assert(size <= UCHAR_MAX, "PascalString size cannot be > 255");
static_assert(size <= UCHAR_MAX, "Pascal::String size cannot be > 255");
uint8_t buf[size + 1]{};
public:
size_t len() {
// Current string length (ala std::string::length)
size_t length() {
return buf[0];
}
// Maximum string length (ala std::string::max_size)
size_t max_size() const {
return size;
}
void operator = (const char* s) {
using std::min;
memset(buf, 0, size);
buf[0] = (uint8_t)min(size, strlen(s));
memcpy(buf + 1, s, len());
memcpy(buf + 1, s, length());
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment