defines a 'safe' name buffer
More...
#include <NameBuffer.h>
defines a 'safe' name buffer
- Note
- Instead of including a fixed name array in Stat (and IFileSystem::Info) structures, we use a NameBuffer to identify a separate buffer. This has several advantages:
- Maximum size is not fixed
- Finding and copying the name is optional
- Actual name length is returned in the 'length' field, regardless of size
- A NameBuffer structure (or one containing it) only requires initialising once before
a loop operation as buffer/size are preserved.
There are fancier ways to do this but a structure is transparent and requires no heap allocation.
-
length
always reflects the required name/path length, and may be longer than size.
◆ NameBuffer() [1/3]
IFS::NameBuffer::NameBuffer |
( |
| ) |
|
|
inline |
◆ NameBuffer() [2/3]
IFS::NameBuffer::NameBuffer |
( |
char * |
buffer, |
|
|
uint16_t |
size, |
|
|
uint16_t |
length = 0 |
|
) |
| |
|
inline |
◆ NameBuffer() [3/3]
IFS::NameBuffer::NameBuffer |
( |
String & |
s | ) |
|
|
inline |
◆ addSep()
int IFS::NameBuffer::addSep |
( |
| ) |
|
|
inline |
When building file paths this method simplified appending separators.
- Return values
-
- Note
- if the path is not empty, a separator character is appended
◆ begin()
char* IFS::NameBuffer::begin |
( |
| ) |
|
|
inline |
◆ c_str()
const char* IFS::NameBuffer::c_str |
( |
| ) |
const |
|
inline |
◆ copy() [1/3]
int IFS::NameBuffer::copy |
( |
const char * |
src | ) |
|
|
inline |
◆ copy() [2/3]
int IFS::NameBuffer::copy |
( |
const char * |
src, |
|
|
uint16_t |
srclen |
|
) |
| |
|
inline |
copies text from a source buffer into a name buffer
- Parameters
-
src | source name |
srclen | number of characters in name |
- Note
- length field is always set to srclen, regardless of number of characters copied.
◆ copy() [3/3]
int IFS::NameBuffer::copy |
( |
const NameBuffer & |
name | ) |
|
|
inline |
◆ endptr()
char* IFS::NameBuffer::endptr |
( |
| ) |
|
|
inline |
get a pointer to the next write position
- Return values
-
- Note
- use space() to ensure buffer doesn't overrun When writing text be sure to call terminate() when complete
◆ endsWith()
bool IFS::NameBuffer::endsWith |
( |
const char * |
suffix | ) |
const |
|
inline |
◆ operator const char *()
IFS::NameBuffer::operator const char * |
( |
| ) |
const |
|
inline |
◆ operator String()
IFS::NameBuffer::operator String |
( |
| ) |
const |
|
inlineexplicit |
◆ operator==()
bool IFS::NameBuffer::operator== |
( |
const char * |
other | ) |
|
|
inline |
◆ overflow()
bool IFS::NameBuffer::overflow |
( |
| ) |
const |
|
inline |
determine if name buffer overflowed
- Note
- Compares returned length with buffer size; A nul terminator is always appended, so size should be >= (length + 1)
◆ space()
uint16_t IFS::NameBuffer::space |
( |
| ) |
|
|
inline |
get the number of free characters available
- Return values
-
- Note
- returns 0 if buffer has overrun
◆ terminate()
void IFS::NameBuffer::terminate |
( |
| ) |
|
|
inline |
ensure the buffer has a nul terminator, even if it means overwriting content
◆ buffer
char* IFS::NameBuffer::buffer {nullptr} |
◆ length
uint16_t IFS::NameBuffer::length {0} |
◆ size
uint16_t IFS::NameBuffer::size {0} |
The documentation for this struct was generated from the following file: