format using clang-format to formate code
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
#include <core_stream.h>
|
||||
|
||||
// 内存流的具体实现结构
|
||||
static usize read_buf(core_stream_t* _stream, char* buffer, usize count) {
|
||||
static usize read_buf(core_stream_t *_stream, char *buffer, usize count) {
|
||||
Assert(buffer != null && buffer != null);
|
||||
core_mem_stream_t* stream = (core_mem_stream_t*)_stream;
|
||||
core_mem_stream_t *stream = (core_mem_stream_t *)_stream;
|
||||
|
||||
usize remaining = stream->data_length - stream->curr_pos;
|
||||
usize to_read = (remaining < count) ? remaining : count;
|
||||
@@ -13,15 +13,16 @@ static usize read_buf(core_stream_t* _stream, char* buffer, usize count) {
|
||||
smcc_memcpy(buffer, stream->data + stream->curr_pos, to_read);
|
||||
stream->curr_pos += to_read;
|
||||
} else {
|
||||
LOG_WARN("Reading past end of stream [maybe count is too large or negative?]");
|
||||
LOG_WARN("Reading past end of stream "
|
||||
"[maybe count is too large or negative?]");
|
||||
}
|
||||
|
||||
return to_read;
|
||||
}
|
||||
|
||||
static int peek_char(core_stream_t* _stream) {
|
||||
static int peek_char(core_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_stream_t* stream = (core_mem_stream_t*)_stream;
|
||||
core_mem_stream_t *stream = (core_mem_stream_t *)_stream;
|
||||
|
||||
// 如果已经到达末尾,返回EOF
|
||||
if (stream->peek_pos >= stream->data_length) {
|
||||
@@ -31,15 +32,15 @@ static int peek_char(core_stream_t* _stream) {
|
||||
return (int)(unsigned char)stream->data[stream->peek_pos++];
|
||||
}
|
||||
|
||||
static int next_char(core_stream_t* _stream) {
|
||||
static int next_char(core_stream_t *_stream) {
|
||||
Assert(_stream != NULL);
|
||||
core_mem_stream_t* stream = (core_mem_stream_t*)_stream;
|
||||
core_mem_stream_t *stream = (core_mem_stream_t *)_stream;
|
||||
|
||||
// 如果已经到达末尾,返回EOF
|
||||
if (stream->curr_pos >= stream->data_length) {
|
||||
return core_stream_eof; // EOF
|
||||
}
|
||||
|
||||
|
||||
unsigned char ch = stream->data[stream->curr_pos++];
|
||||
if (stream->peek_pos < stream->curr_pos) {
|
||||
stream->peek_pos = stream->curr_pos;
|
||||
@@ -47,26 +48,27 @@ static int next_char(core_stream_t* _stream) {
|
||||
return (int)ch;
|
||||
}
|
||||
|
||||
static void reset_char(core_stream_t* _stream) {
|
||||
static void reset_char(core_stream_t *_stream) {
|
||||
Assert(_stream != NULL);
|
||||
core_mem_stream_t* stream = (core_mem_stream_t*)_stream;
|
||||
core_mem_stream_t *stream = (core_mem_stream_t *)_stream;
|
||||
|
||||
stream->peek_pos = stream->curr_pos;
|
||||
}
|
||||
|
||||
static void free_stream(core_stream_t* _stream) {
|
||||
static void free_stream(core_stream_t *_stream) {
|
||||
Assert(_stream != null);
|
||||
core_mem_stream_t* stream = (core_mem_stream_t*)_stream;
|
||||
core_mem_stream_t *stream = (core_mem_stream_t *)_stream;
|
||||
|
||||
// FIXME maybe double free?
|
||||
cstring_free(&stream->stream.name);
|
||||
|
||||
if (stream->owned) {
|
||||
smcc_free((void*)stream->data);
|
||||
smcc_free((void *)stream->data);
|
||||
}
|
||||
}
|
||||
|
||||
core_stream_t* core_mem_stream_init(core_mem_stream_t* stream, const char* data, usize length, cbool need_copy) {
|
||||
core_stream_t *core_mem_stream_init(core_mem_stream_t *stream, const char *data,
|
||||
usize length, cbool need_copy) {
|
||||
if (stream == null || data == NULL || length == 0) {
|
||||
LOG_ERROR("param error");
|
||||
return null;
|
||||
@@ -74,7 +76,7 @@ core_stream_t* core_mem_stream_init(core_mem_stream_t* stream, const char* data,
|
||||
|
||||
stream->owned = need_copy;
|
||||
if (need_copy) {
|
||||
char* buf = (char*)smcc_malloc(length);
|
||||
char *buf = (char *)smcc_malloc(length);
|
||||
if (buf == null) {
|
||||
LOG_ERROR("malloc error");
|
||||
return null;
|
||||
@@ -90,12 +92,12 @@ core_stream_t* core_mem_stream_init(core_mem_stream_t* stream, const char* data,
|
||||
stream->peek_pos = 0;
|
||||
|
||||
stream->stream.name = cstring_from_cstr("mem_stream");
|
||||
|
||||
|
||||
stream->stream.read_buf = read_buf;
|
||||
stream->stream.peek_char = peek_char;
|
||||
stream->stream.next_char = next_char;
|
||||
stream->stream.reset_char = reset_char;
|
||||
stream->stream.free_stream = free_stream;
|
||||
|
||||
return (void*)stream;
|
||||
return (void *)stream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user