Commit 662069f4 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Add Pascal::String::max_size() method

Rename len() method to length() to align with std::string.
parent a08bed3b
Pipeline #2867 passed with stage
in 9 minutes and 44 seconds
......@@ -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());
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment