serial: toml: replace b_string usage with b_stringstream in refill_linebuf

This commit is contained in:
2025-10-24 12:44:45 +01:00
parent 68ed163040
commit f941c470b6

View File

@@ -1,3 +1,4 @@
#include "blue/core/stringstream.h"
#include "serial.h"
#include <blue/core/status.h>
@@ -110,7 +111,6 @@ struct ctx {
b_stream *ctx_src;
b_string *ctx_wordbuf;
b_string *ctx_linebuf;
b_stream *ctx_linebuf_stream;
b_string_iterator ctx_linebuf_ptr;
enum b_status ctx_status;
b_hashmap *ctx_objects_flags;
@@ -218,14 +218,22 @@ static enum b_status data_available(struct ctx *ctx)
static enum b_status refill_linebuf(struct ctx *ctx)
{
b_string_clear(ctx->ctx_linebuf);
b_stream_seek(ctx->ctx_linebuf_stream, 0, B_STREAM_SEEK_START);
enum b_status status
= b_stream_read_line_s(ctx->ctx_src, ctx->ctx_linebuf_stream);
b_stringstream *buf = b_stringstream_create();
enum b_status status = b_stream_read_line_s(ctx->ctx_src, buf);
if (!B_OK(status)) {
return status;
}
b_string_clear(ctx->ctx_linebuf);
status = b_string_append_cstr(ctx->ctx_linebuf, b_stringstream_ptr(buf));
if (!B_OK(status)) {
return status;
}
b_stringstream_unref(buf);
b_string_iterator_begin(ctx->ctx_linebuf, &ctx->ctx_linebuf_ptr);
return B_SUCCESS;
@@ -1507,11 +1515,6 @@ static struct token *peek_token(struct ctx *ctx)
static void ctx_cleanup(struct ctx *ctx)
{
if (ctx->ctx_linebuf_stream) {
b_stream_close(ctx->ctx_linebuf_stream);
ctx->ctx_linebuf_stream = NULL;
}
if (ctx->ctx_linebuf) {
b_string_unref(ctx->ctx_linebuf);
ctx->ctx_linebuf = NULL;
@@ -1535,15 +1538,13 @@ static enum b_status ctx_init(struct ctx *ctx)
ctx->ctx_linebuf = b_string_create();
ctx->ctx_wordbuf = b_string_create();
b_string_open_stream(ctx->ctx_linebuf, &ctx->ctx_linebuf_stream);
ctx->ctx_objects_flags = b_hashmap_create(NULL, NULL);
return B_SUCCESS;
}
static enum b_status toml_serialise(
struct b_serial_ctx *serial, b_object *src, struct b_stream *dest,
struct b_serial_ctx *serial, b_object *src, b_stream *dest,
enum b_serial_flags flags)
{
return B_SUCCESS;
@@ -2221,7 +2222,7 @@ static enum b_status parse_root(struct ctx *ctx, b_dict **result)
}
static enum b_status toml_deserialise(
struct b_serial_ctx *serial, struct b_stream *src, b_object **dest,
struct b_serial_ctx *serial, b_stream *src, b_object **dest,
enum b_serial_flags flags)
{
struct ctx ctx = {0};