Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Commits
662069f4
Commit
662069f4
authored
Mar 10, 2022
by
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
src/encode/pascal_types.hpp
src/encode/pascal_types.hpp
+9
-3
No files found.
src/encode/pascal_types.hpp
View file @
662069f4
...
...
@@ -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
,
len
gth
());
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment