From f12c1fffdd796ede4e70df188d961772232f1933 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 14 Mar 2022 17:11:25 +0000 Subject: [PATCH] view: added `sv_copy_to()`: copy a `view_t` to a nul-terminated buffer. (`snprintf()` for `view_t`) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for sink's current commit: Future small blessing − 末小吉 --- view.c | 32 ++++++++++++++++++++++++++++---- view.h | 11 +++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/view.c b/view.c index b96a9bf..2d7fac3 100644 --- a/view.c +++ b/view.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "view.h" @@ -74,16 +75,39 @@ static struct string_data* _s_data(char* str, bool check) { } __attribute__((pure)) -str_info_t s_get_info(sv_t str) +str_info_t s_get_info(view_t str) { return _s_data($nullchk(str.ptr, return NULL), true); } __attribute__((pure)) -sv_t s_get_str(str_info_t data) +view_t s_get_str(str_info_t data) { - return (sv_t) { + return (view_t) { .len = data->len, - .ptr = (unsigned char*)data->ptr, + .ptr = data->ptr, }; } + +__attribute__((cold)) +static size_t _sv_copy_manual(size_t sz, char buffer[restrict static sz], view_t view) +{ + size_t i=0; + for(;i< (sz-1) && i