meta: rename to fx
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
struct b_stringstream_p {
|
||||
struct fx_stringstream_p {
|
||||
char *ss_buf;
|
||||
size_t ss_ptr;
|
||||
size_t ss_len;
|
||||
@@ -18,31 +18,31 @@ struct b_stringstream_p {
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
static enum b_status __getc(struct b_stringstream_p *ss, b_wchar *out)
|
||||
static enum fx_status __getc(struct fx_stringstream_p *ss, fx_wchar *out)
|
||||
{
|
||||
size_t available = ss->ss_len - ss->ss_ptr;
|
||||
|
||||
const char *p = ss->ss_buf + ss->ss_ptr;
|
||||
|
||||
size_t to_copy = b_wchar_utf8_codepoint_stride(p);
|
||||
size_t to_copy = fx_wchar_utf8_codepoint_stride(p);
|
||||
if (to_copy > available) {
|
||||
return B_ERR_BAD_STATE;
|
||||
return FX_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
b_wchar c = b_wchar_utf8_codepoint_decode(p);
|
||||
fx_wchar c = fx_wchar_utf8_codepoint_decode(p);
|
||||
*out = c;
|
||||
|
||||
if (c == B_WCHAR_INVALID) {
|
||||
return B_ERR_BAD_STATE;
|
||||
if (c == FX_WCHAR_INVALID) {
|
||||
return FX_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
ss->ss_ptr += to_copy;
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum b_status __gets(
|
||||
struct b_stringstream_p *ss, char *s, size_t len, size_t *nr_read)
|
||||
static enum fx_status __gets(
|
||||
struct fx_stringstream_p *ss, char *s, size_t len, size_t *nr_read)
|
||||
{
|
||||
size_t available = ss->ss_len - ss->ss_ptr;
|
||||
size_t to_copy = len;
|
||||
@@ -59,11 +59,11 @@ static enum b_status __gets(
|
||||
*nr_read = to_copy;
|
||||
}
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum b_status __puts(
|
||||
struct b_stringstream_p *ss, const char *s, size_t len, size_t *nr_written)
|
||||
static enum fx_status __puts(
|
||||
struct fx_stringstream_p *ss, const char *s, size_t len, size_t *nr_written)
|
||||
{
|
||||
size_t available = ss->ss_max - ss->ss_len;
|
||||
size_t to_copy = len;
|
||||
@@ -71,7 +71,7 @@ static enum b_status __puts(
|
||||
if (to_copy > available && ss->ss_alloc == 1) {
|
||||
char *new_buf = realloc(ss->ss_buf, ss->ss_len + to_copy + 1);
|
||||
if (!new_buf) {
|
||||
return B_ERR_NO_MEMORY;
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
ss->ss_buf = new_buf;
|
||||
@@ -93,10 +93,10 @@ static enum b_status __puts(
|
||||
*nr_written = to_copy;
|
||||
}
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum b_status stringstream_reset(struct b_stringstream_p *ss)
|
||||
static enum fx_status stringstream_reset(struct fx_stringstream_p *ss)
|
||||
{
|
||||
ss->ss_len = 0;
|
||||
|
||||
@@ -104,11 +104,11 @@ static enum b_status stringstream_reset(struct b_stringstream_p *ss)
|
||||
*ss->ss_buf = 0;
|
||||
}
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum b_status stringstream_reset_with_buffer(
|
||||
struct b_stringstream_p *ss, char *buf, size_t max)
|
||||
static enum fx_status stringstream_reset_with_buffer(
|
||||
struct fx_stringstream_p *ss, char *buf, size_t max)
|
||||
{
|
||||
ss->ss_len = 0;
|
||||
|
||||
@@ -120,20 +120,20 @@ static enum b_status stringstream_reset_with_buffer(
|
||||
ss->ss_max = max;
|
||||
ss->ss_alloc = 0;
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static size_t stringstream_get_length(const struct b_stringstream_p *strv)
|
||||
static size_t stringstream_get_length(const struct fx_stringstream_p *strv)
|
||||
{
|
||||
return strv->ss_len;
|
||||
}
|
||||
|
||||
static const char *stringstream_ptr(const struct b_stringstream_p *ss)
|
||||
static const char *stringstream_ptr(const struct fx_stringstream_p *ss)
|
||||
{
|
||||
return ss->ss_buf;
|
||||
}
|
||||
|
||||
static char *stringstream_steal(struct b_stringstream_p *ss)
|
||||
static char *stringstream_steal(struct fx_stringstream_p *ss)
|
||||
{
|
||||
char *out = ss->ss_buf;
|
||||
|
||||
@@ -146,17 +146,17 @@ static char *stringstream_steal(struct b_stringstream_p *ss)
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
b_stringstream *b_stringstream_create_with_buffer(char *buf, size_t max)
|
||||
fx_stringstream *fx_stringstream_create_with_buffer(char *buf, size_t max)
|
||||
{
|
||||
b_stringstream *s = b_object_create(B_TYPE_STRINGSTREAM);
|
||||
fx_stringstream *s = fx_object_create(FX_TYPE_STRINGSTREAM);
|
||||
if (!s) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_stream_cfg *cfg = b_object_get_protected(s, B_TYPE_STREAM);
|
||||
struct b_stringstream_p *p = b_object_get_private(s, B_TYPE_STRINGSTREAM);
|
||||
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
||||
struct fx_stringstream_p *p = fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
cfg->s_mode = B_STREAM_READ | B_STREAM_WRITE | Z__B_STREAM_STATIC;
|
||||
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
||||
|
||||
p->ss_buf = buf;
|
||||
p->ss_max = max;
|
||||
@@ -166,21 +166,21 @@ b_stringstream *b_stringstream_create_with_buffer(char *buf, size_t max)
|
||||
return s;
|
||||
}
|
||||
|
||||
b_stringstream *b_stringstream_create(void)
|
||||
fx_stringstream *fx_stringstream_create(void)
|
||||
{
|
||||
b_stringstream *s = b_object_create(B_TYPE_STRINGSTREAM);
|
||||
fx_stringstream *s = fx_object_create(FX_TYPE_STRINGSTREAM);
|
||||
if (!s) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_stream_cfg *cfg = b_object_get_protected(s, B_TYPE_STREAM);
|
||||
struct b_stringstream_p *p = b_object_get_private(s, B_TYPE_STRINGSTREAM);
|
||||
fx_stream_cfg *cfg = fx_object_get_protected(s, FX_TYPE_STREAM);
|
||||
struct fx_stringstream_p *p = fx_object_get_private(s, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
cfg->s_mode = B_STREAM_READ | B_STREAM_WRITE | Z__B_STREAM_STATIC;
|
||||
cfg->s_mode = FX_STREAM_READ | FX_STREAM_WRITE | Z__FX_STREAM_STATIC;
|
||||
|
||||
p->ss_buf = malloc(DEFAULT_CAPACITY + 1);
|
||||
if (!p->ss_buf) {
|
||||
b_stringstream_unref(s);
|
||||
fx_stringstream_unref(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -192,106 +192,106 @@ b_stringstream *b_stringstream_create(void)
|
||||
return s;
|
||||
}
|
||||
|
||||
size_t b_stringstream_get_length(const b_stringstream *strv)
|
||||
size_t fx_stringstream_get_length(const fx_stringstream *strv)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC_0(
|
||||
B_TYPE_STRINGSTREAM, stringstream_get_length, strv);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_STRINGSTREAM, stringstream_get_length, strv);
|
||||
}
|
||||
|
||||
enum b_status b_stringstream_reset(b_stringstream *strv)
|
||||
enum fx_status fx_stringstream_reset(fx_stringstream *strv)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC_0(B_TYPE_STRINGSTREAM, stringstream_reset, strv);
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRINGSTREAM, stringstream_reset, strv);
|
||||
}
|
||||
|
||||
enum b_status b_stringstream_reset_with_buffer(
|
||||
b_stringstream *strv, char *buf, size_t max)
|
||||
enum fx_status fx_stringstream_reset_with_buffer(
|
||||
fx_stringstream *strv, char *buf, size_t max)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC(
|
||||
B_TYPE_STRINGSTREAM, stringstream_reset_with_buffer, strv, buf,
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRINGSTREAM, stringstream_reset_with_buffer, strv, buf,
|
||||
max);
|
||||
}
|
||||
|
||||
const char *b_stringstream_ptr(const b_stringstream *ss)
|
||||
const char *fx_stringstream_ptr(const fx_stringstream *ss)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC_0(B_TYPE_STRINGSTREAM, stringstream_ptr, ss);
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRINGSTREAM, stringstream_ptr, ss);
|
||||
}
|
||||
|
||||
char *b_stringstream_steal(b_stringstream *ss)
|
||||
char *fx_stringstream_steal(fx_stringstream *ss)
|
||||
{
|
||||
B_CLASS_DISPATCH_STATIC_0(B_TYPE_STRINGSTREAM, stringstream_steal, ss);
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRINGSTREAM, stringstream_steal, ss);
|
||||
}
|
||||
|
||||
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static void stringstream_init(b_object *obj, void *priv)
|
||||
static void stringstream_init(fx_object *obj, void *priv)
|
||||
{
|
||||
struct b_stringstream_p *stream = priv;
|
||||
struct fx_stringstream_p *stream = priv;
|
||||
}
|
||||
|
||||
static void stringstream_fini(b_object *obj, void *priv)
|
||||
static void stringstream_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
struct b_stringstream_p *stream = priv;
|
||||
struct fx_stringstream_p *stream = priv;
|
||||
|
||||
if (stream->ss_alloc && stream->ss_buf) {
|
||||
free(stream->ss_buf);
|
||||
}
|
||||
}
|
||||
|
||||
enum b_status stream_getc(b_stream *stream, b_wchar *c)
|
||||
enum fx_status stream_getc(fx_stream *stream, fx_wchar *c)
|
||||
{
|
||||
struct b_stringstream_p *s
|
||||
= b_object_get_private(stream, B_TYPE_STRINGSTREAM);
|
||||
struct fx_stringstream_p *s
|
||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
enum b_status status = __getc(s, c);
|
||||
enum fx_status status = __getc(s, c);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
enum b_status stream_read(b_stream *stream, void *buf, size_t count, size_t *nr_read)
|
||||
enum fx_status stream_read(fx_stream *stream, void *buf, size_t count, size_t *nr_read)
|
||||
{
|
||||
struct b_stringstream_p *s
|
||||
= b_object_get_private(stream, B_TYPE_STRINGSTREAM);
|
||||
struct fx_stringstream_p *s
|
||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
enum b_status status = __gets(s, buf, count, nr_read);
|
||||
enum fx_status status = __gets(s, buf, count, nr_read);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
enum b_status stream_write(
|
||||
b_stream *stream, const void *buf, size_t count, size_t *nr_written)
|
||||
enum fx_status stream_write(
|
||||
fx_stream *stream, const void *buf, size_t count, size_t *nr_written)
|
||||
{
|
||||
struct b_stringstream_p *s
|
||||
= b_object_get_private(stream, B_TYPE_STRINGSTREAM);
|
||||
struct fx_stringstream_p *s
|
||||
= fx_object_get_private(stream, FX_TYPE_STRINGSTREAM);
|
||||
|
||||
enum b_status status = __puts(s, (const char *)buf, count, nr_written);
|
||||
enum fx_status status = __puts(s, (const char *)buf, count, nr_written);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
B_TYPE_CLASS_DEFINITION_BEGIN(b_stringstream)
|
||||
B_TYPE_CLASS_INTERFACE_BEGIN(b_object, B_TYPE_OBJECT)
|
||||
B_INTERFACE_ENTRY(to_string) = NULL;
|
||||
B_TYPE_CLASS_INTERFACE_END(b_object, B_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stringstream)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
B_TYPE_CLASS_INTERFACE_BEGIN(b_stream, B_TYPE_STREAM)
|
||||
B_INTERFACE_ENTRY(s_close) = NULL;
|
||||
B_INTERFACE_ENTRY(s_seek) = NULL;
|
||||
B_INTERFACE_ENTRY(s_tell) = NULL;
|
||||
B_INTERFACE_ENTRY(s_getc) = stream_getc;
|
||||
B_INTERFACE_ENTRY(s_read) = stream_read;
|
||||
B_INTERFACE_ENTRY(s_write) = stream_write;
|
||||
B_INTERFACE_ENTRY(s_reserve) = NULL;
|
||||
B_TYPE_CLASS_INTERFACE_END(b_stream, B_TYPE_STREAM)
|
||||
B_TYPE_CLASS_DEFINITION_END(b_stringstream)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_INTERFACE_ENTRY(s_close) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_seek) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_tell) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_getc) = stream_getc;
|
||||
FX_INTERFACE_ENTRY(s_read) = stream_read;
|
||||
FX_INTERFACE_ENTRY(s_write) = stream_write;
|
||||
FX_INTERFACE_ENTRY(s_reserve) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_stringstream)
|
||||
|
||||
B_TYPE_DEFINITION_BEGIN(b_stringstream)
|
||||
B_TYPE_ID(0x508a609a, 0xfac5, 0x4d31, 0x843a, 0x44b68ad329f3);
|
||||
B_TYPE_EXTENDS(B_TYPE_STREAM);
|
||||
B_TYPE_CLASS(b_stringstream_class);
|
||||
B_TYPE_INSTANCE_PRIVATE(struct b_stringstream_p);
|
||||
B_TYPE_INSTANCE_INIT(stringstream_init);
|
||||
B_TYPE_INSTANCE_FINI(stringstream_fini);
|
||||
B_TYPE_DEFINITION_END(b_stringstream)
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_stringstream)
|
||||
FX_TYPE_ID(0x508a609a, 0xfac5, 0x4d31, 0x843a, 0x44b68ad329f3);
|
||||
FX_TYPE_EXTENDS(FX_TYPE_STREAM);
|
||||
FX_TYPE_CLASS(fx_stringstream_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_stringstream_p);
|
||||
FX_TYPE_INSTANCE_INIT(stringstream_init);
|
||||
FX_TYPE_INSTANCE_FINI(stringstream_fini);
|
||||
FX_TYPE_DEFINITION_END(fx_stringstream)
|
||||
|
||||
Reference in New Issue
Block a user