28 namespace fleece {
struct alloc_slice; }
51 constexpr size_t size_bytes() const noexcept
FLPURE {
return size;}
52 constexpr bool empty() const noexcept
FLPURE {
return size == 0;}
53 constexpr explicit operator bool() const noexcept
FLPURE {
return buf !=
nullptr;}
54 explicit operator std::string()
const {
return std::string((
char*)
buf,
size);}
72 constexpr size_t size_bytes() const noexcept
FLPURE {
return size;}
73 constexpr bool empty() const noexcept
FLPURE {
return size == 0;}
74 constexpr explicit operator bool() const noexcept
FLPURE {
return buf !=
nullptr;}
75 constexpr explicit operator FLSlice ()
const {
return {buf, size};}
76 inline explicit operator std::string()
const;
87 constexpr FLHeapSlice() noexcept :FLSlice{
nullptr, 0} { }
90 friend struct fleece::alloc_slice;
106 #define kFLSliceNull ((FLSlice){NULL, 0})
117 return memcmp(a, b, size);
124 memcpy(dst, src, size);
133 FLSlice foo = { str, str ? strlen(str) : 0 };
140 #define FLSTR(STR) (FLSlice {("" STR), sizeof(("" STR))-1})
142 #define FLSTR(STR) ((FLSlice){("" STR), sizeof(("" STR))-1})
196 memcpy(&ret, &sr,
sizeof(ret));
219 FLSliceResult::operator std::string ()
const {
220 auto str = std::string((
char*)buf, size);
#define FL_NULLABLE
Definition CompilerSupport.h:94
#define LIFETIMEBOUND
Definition CompilerSupport.h:293
#define FLEECE_PUBLIC
Definition CompilerSupport.h:269
#define FL_ASSUME_NONNULL_BEGIN
Definition CompilerSupport.h:92
#define _usuallyTrue(VAL)
Definition CompilerSupport.h:75
#define _usuallyFalse(VAL)
Definition CompilerSupport.h:76
#define FLPURE
Definition CompilerSupport.h:130
#define NODISCARD
Definition CompilerSupport.h:63
#define FL_ASSUME_NONNULL_END
Definition CompilerSupport.h:93
#define FLAPI
Definition CompilerSupport.h:292
FLEECE_PUBLIC void _FLBuf_Release(const void *FL_NULLABLE)
FLEECE_PUBLIC void FL_WipeMemory(void *dst, size_t size)
Writes zeroes to size bytes of memory starting at dst.
FLSlice FLStr(const char *FL_NULLABLE str LIFETIMEBOUND)
Returns a slice pointing to the contents of a C string.
Definition FLSlice.h:132
FLEECE_PUBLIC void _FLBuf_Retain(const void *FL_NULLABLE)
FLEECE_PUBLIC FLSliceResult FLSliceResult_New(size_t)
Allocates an FLSliceResult of the given size, without initializing the buffer.
#define kFLSliceNull
A convenient constant denoting a null slice.
Definition FLSlice.h:106
FLSliceResult FLSliceResult_Retain(FLSliceResult s)
Increments the ref-count of a FLSliceResult.
Definition FLSlice.h:183
FLEECE_PUBLIC bool FLSlice_Equal(FLSlice a, FLSlice b) FLPURE
Equality test of two slices.
void FLSliceResult_Release(FLSliceResult s)
Decrements the ref-count of a FLSliceResult, freeing its memory if it reached zero.
Definition FLSlice.h:189
FLSlice FLSliceResult_AsSlice(FLSliceResult sr LIFETIMEBOUND)
Type-casts a FLSliceResult to FLSlice, since C doesn't know it's a subclass.
Definition FLSlice.h:194
FLSliceResult FLStringResult
Definition FLSlice.h:99
FLPURE int FLMemCmp(const void *FL_NULLABLE a, const void *FL_NULLABLE b, size_t size)
Exactly like memcmp, but safely handles the case where a or b is NULL and size is 0 (by returning 0),...
Definition FLSlice.h:112
FLSlice FLString
Definition FLSlice.h:98
FLSlice FLHeapSlice
A heap-allocated, reference-counted slice.
Definition FLSlice.h:93
FLEECE_PUBLIC bool FLSlice_ToCString(FLSlice s, char *buffer, size_t capacity)
Copies a slice to a buffer, adding a trailing zero byte to make it a valid C string.
FLSliceResult FLSliceResult_CreateWith(const void *FL_NULLABLE bytes, size_t size)
Allocates an FLSliceResult, copying size bytes starting at buf.
Definition FLSlice.h:173
FLEECE_PUBLIC int FLSlice_Compare(FLSlice, FLSlice) FLPURE
Lexicographic comparison of two slices; basically like memcmp(), but taking into account differences ...
FLEECE_PUBLIC uint32_t FLSlice_Hash(FLSlice s) FLPURE
Computes a 32-bit hash of a slice's data, suitable for use in hash tables.
void FLMemCpy(void *FL_NULLABLE dst, const void *FL_NULLABLE src, size_t size)
Exactly like memcmp, but safely handles the case where dst or src is NULL and size is 0 (as a no-op),...
Definition FLSlice.h:122
FLEECE_PUBLIC FLSliceResult FLSlice_Copy(FLSlice)
Allocates an FLSliceResult, copying the given slice.
A simple reference to a block of memory.
Definition FLSlice.h:45
size_t size
Definition FLSlice.h:47
const void *FL_NULLABLE buf
Definition FLSlice.h:46
A heap-allocated block of memory returned from an API call.
Definition FLSlice.h:66
const void *FL_NULLABLE buf
Definition FLSlice.h:67
size_t size
Definition FLSlice.h:68