Compare commits
9 Commits
912c450e6e
...
cb39baa233
| Author | SHA1 | Date | |
|---|---|---|---|
| cb39baa233 | |||
| 5646c8c2b8 | |||
| 3529e8525a | |||
| 6a26e00438 | |||
| c76008e498 | |||
| 321622ac16 | |||
| c39f50a0ee | |||
| 5ab348fd30 | |||
| 709d11331c |
+63
-5
@@ -1,7 +1,7 @@
|
||||
BasedOnStyle: WebKit
|
||||
IndentWidth: 8
|
||||
---
|
||||
Language: Cpp
|
||||
Language: C
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Right
|
||||
ColumnLimit: 80
|
||||
@@ -26,8 +26,8 @@ AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: OnePerLine
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
BitFieldColonSpacing: Both
|
||||
BreakBeforeBraces: Linux
|
||||
@@ -47,7 +47,7 @@ SpacesBeforeTrailingComments: 3
|
||||
TabWidth: 8
|
||||
UseTab: AlignWithSpaces
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000000
|
||||
PenaltyExcessCharacter: 5
|
||||
PenaltyExcessCharacter: 999999999
|
||||
PenaltyBreakOpenParenthesis: 5
|
||||
PenaltyBreakBeforeFirstCallParameter: 5
|
||||
PenaltyIndentedWhitespace: 0
|
||||
@@ -84,7 +84,7 @@ AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackArguments: false
|
||||
BinPackParameters: true
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
BitFieldColonSpacing: Both
|
||||
@@ -116,3 +116,61 @@ ForEachMacros:
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
---
|
||||
Language: Cpp
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Right
|
||||
ColumnLimit: 80
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: OnePerLine
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
BitFieldColonSpacing: Both
|
||||
BreakBeforeBraces: Linux
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: true
|
||||
IncludeBlocks: Regroup
|
||||
SortIncludes: true
|
||||
IndentRequires: true
|
||||
NamespaceIndentation: Inner
|
||||
ReflowComments: true
|
||||
SpacesBeforeTrailingComments: 3
|
||||
TabWidth: 8
|
||||
UseTab: AlignWithSpaces
|
||||
PenaltyReturnTypeOnItsOwnLine: 1000000
|
||||
PenaltyExcessCharacter: 9999999
|
||||
PenaltyBreakOpenParenthesis: 5
|
||||
PenaltyBreakBeforeFirstCallParameter: 5
|
||||
PenaltyIndentedWhitespace: 0
|
||||
AttributeMacros:
|
||||
- FX_API
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
|
||||
+4
-4
@@ -756,18 +756,18 @@ static void get_error_id(
|
||||
fx_stringstream *id = fx_stringstream_create_with_buffer(out, max);
|
||||
|
||||
if (vendor_name) {
|
||||
fx_stream_write_string(id, vendor_name, NULL);
|
||||
fx_stream_write_cstr(id, vendor_name, NULL);
|
||||
}
|
||||
|
||||
if (error_name) {
|
||||
if (vendor_name) {
|
||||
fx_stream_write_string(id, ".", NULL);
|
||||
fx_stream_write_cstr(id, ".", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_string(id, error_name, NULL);
|
||||
fx_stream_write_cstr(id, error_name, NULL);
|
||||
} else {
|
||||
if (vendor_name) {
|
||||
fx_stream_write_string(id, "#", NULL);
|
||||
fx_stream_write_cstr(id, "#", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_fmt(id, NULL, "%ld", code);
|
||||
|
||||
@@ -84,7 +84,7 @@ FX_API fx_status fx_stream_read_all_bytes_s(
|
||||
fx_stream *src, fx_stream *dest, fx_stream_buffer *buffer, size_t *nr_read);
|
||||
|
||||
FX_API fx_status fx_stream_write_char(fx_stream *stream, fx_wchar c);
|
||||
FX_API fx_status fx_stream_write_string(
|
||||
FX_API fx_status fx_stream_write_cstr(
|
||||
fx_stream *stream, const char *s, size_t *nr_written);
|
||||
|
||||
FX_API fx_status fx_stream_write_bytes(
|
||||
|
||||
+1
-1
@@ -238,7 +238,7 @@ static void to_stream(const struct fx_rope *rope, void *arg)
|
||||
case FX_ROPE_F_CSTR:
|
||||
case FX_ROPE_F_CSTR_BORROWED:
|
||||
case FX_ROPE_F_CSTR_STATIC:
|
||||
fx_stream_write_string(out, rope->r_v.v_cstr.s, NULL);
|
||||
fx_stream_write_cstr(out, rope->r_v.v_cstr.s, NULL);
|
||||
break;
|
||||
case FX_ROPE_F_INT:
|
||||
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, rope->r_v.v_int);
|
||||
|
||||
+146
-48
@@ -6,16 +6,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define READ_MAGIC(p) (*(uint64_t *)p)
|
||||
#define IS_BSTR(p) (READ_MAGIC(p) == FX_BSTR_MAGIC)
|
||||
#define READ_MAGIC(p) (*(uint64_t *)p)
|
||||
#define IS_BSTR(p) (READ_MAGIC(p) == FX_BSTR_MAGIC)
|
||||
|
||||
#define FX_TYPE_STDIO_STREAM (fx_stdio_stream_get_type())
|
||||
|
||||
#define STREAM_DISPATCH_VIRTUAL(func, stream, ...) \
|
||||
do { \
|
||||
struct stream_data _stream; \
|
||||
enum fx_status status = stream_get_data(stream, &_stream); \
|
||||
if (!FX_OK(status)) { \
|
||||
enum fx_status status = stream_get_data(stream, &_stream); \
|
||||
if (!FX_OK(status)) { \
|
||||
return status; \
|
||||
} \
|
||||
return func(&_stream, __VA_ARGS__); \
|
||||
@@ -23,8 +23,8 @@
|
||||
#define STREAM_DISPATCH_VIRTUAL_0(func, stream) \
|
||||
do { \
|
||||
struct stream_data _stream; \
|
||||
enum fx_status status = stream_get_data(stream, &_stream); \
|
||||
if (!FX_OK(status)) { \
|
||||
enum fx_status status = stream_get_data(stream, &_stream); \
|
||||
if (!FX_OK(status)) { \
|
||||
return status; \
|
||||
} \
|
||||
return func(&_stream); \
|
||||
@@ -84,12 +84,17 @@ static enum fx_status stdio_write(fx_stream *, const void *, size_t, size_t *);
|
||||
static enum fx_status stdio_seek(fx_stream *, long long, fx_stream_seek_origin);
|
||||
static enum fx_status stdio_tell(const fx_stream *, size_t *);
|
||||
|
||||
static enum fx_status stream_get_data(const fx_stream *strp, struct stream_data *out)
|
||||
static enum fx_status stream_get_data(
|
||||
const fx_stream *strp,
|
||||
struct stream_data *out)
|
||||
{
|
||||
out->s_obj = (fx_stream *)strp;
|
||||
return fx_object_get_data(
|
||||
strp, FX_TYPE_STREAM, (void **)&out->s_private,
|
||||
(void **)&out->s_cfg, (void **)&out->s_ops);
|
||||
strp,
|
||||
FX_TYPE_STREAM,
|
||||
(void **)&out->s_private,
|
||||
(void **)&out->s_cfg,
|
||||
(void **)&out->s_ops);
|
||||
}
|
||||
|
||||
static int current_indent(struct stream_data *stream)
|
||||
@@ -117,7 +122,9 @@ static size_t stream_cursor(const struct stream_data *stream)
|
||||
}
|
||||
|
||||
static enum fx_status stream_seek(
|
||||
struct stream_data *stream, long long offset, fx_stream_seek_origin origin)
|
||||
struct stream_data *stream,
|
||||
long long offset,
|
||||
fx_stream_seek_origin origin)
|
||||
{
|
||||
if (!stream || !stream->s_ops || !stream->s_ops->s_seek) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -236,7 +243,8 @@ static enum fx_status __write_char(struct stream_data *stream, fx_wchar c)
|
||||
}
|
||||
}
|
||||
|
||||
status = stream->s_ops->s_write(stream->s_obj, (unsigned char *)s, len, &w);
|
||||
status = stream->s_ops
|
||||
->s_write(stream->s_obj, (unsigned char *)s, len, &w);
|
||||
|
||||
if (!FX_OK(status)) {
|
||||
return status;
|
||||
@@ -289,7 +297,10 @@ static enum fx_status stream_write_char(struct stream_data *stream, fx_wchar c)
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_bytes(
|
||||
struct stream_data *stream, void *buf, size_t count, size_t *nr_read)
|
||||
struct stream_data *stream,
|
||||
void *buf,
|
||||
size_t count,
|
||||
size_t *nr_read)
|
||||
{
|
||||
if (!(stream->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -304,7 +315,10 @@ static enum fx_status stream_read_bytes(
|
||||
return stream->s_ops->s_read(stream->s_obj, buf, count, nr_read);
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_line(struct stream_data *stream, char *s, size_t max)
|
||||
static enum fx_status stream_read_line(
|
||||
struct stream_data *stream,
|
||||
char *s,
|
||||
size_t max)
|
||||
{
|
||||
if (!(stream->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -337,7 +351,8 @@ static enum fx_status stream_read_line(struct stream_data *stream, char *s, size
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_line_s(
|
||||
struct stream_data *src, struct stream_data *dest)
|
||||
struct stream_data *src,
|
||||
struct stream_data *dest)
|
||||
{
|
||||
if (!(src->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -374,7 +389,8 @@ static enum fx_status stream_read_line_s(
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_line_to_bstr(
|
||||
struct stream_data *src, struct fx_bstr *dest)
|
||||
struct stream_data *src,
|
||||
struct fx_bstr *dest)
|
||||
{
|
||||
if (!(src->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -407,7 +423,10 @@ static enum fx_status stream_read_line_to_bstr(
|
||||
}
|
||||
|
||||
static enum fx_status stream_write_bytes(
|
||||
struct stream_data *stream, const void *buf, size_t count, size_t *nr_written)
|
||||
struct stream_data *stream,
|
||||
const void *buf,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
if (!(stream->s_cfg->s_mode & FX_STREAM_WRITE)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -423,7 +442,10 @@ static enum fx_status stream_write_bytes(
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_all_bytes(
|
||||
struct stream_data *stream, void *p, size_t max, size_t *out_nr_read)
|
||||
struct stream_data *stream,
|
||||
void *p,
|
||||
size_t max,
|
||||
size_t *out_nr_read)
|
||||
{
|
||||
if (!(stream->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -452,8 +474,10 @@ static enum fx_status stream_read_all_bytes(
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_all_bytes_s(
|
||||
struct stream_data *src, struct stream_data *dest,
|
||||
struct fx_stream_buffer_p *buffer, size_t *out_nr_read)
|
||||
struct stream_data *src,
|
||||
struct stream_data *dest,
|
||||
struct fx_stream_buffer_p *buffer,
|
||||
size_t *out_nr_read)
|
||||
{
|
||||
if (!(src->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -482,7 +506,10 @@ static enum fx_status stream_read_all_bytes_s(
|
||||
while (1) {
|
||||
size_t r = 0, w = 0;
|
||||
status = stream_read_bytes(
|
||||
src, buffer->p_buf, buffer->p_buf_len, &r);
|
||||
src,
|
||||
buffer->p_buf,
|
||||
buffer->p_buf_len,
|
||||
&r);
|
||||
if (status != FX_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
@@ -507,8 +534,10 @@ static enum fx_status stream_read_all_bytes_s(
|
||||
}
|
||||
|
||||
static enum fx_status stream_read_all_bytes_to_bstr_s(
|
||||
struct stream_data *src, struct fx_bstr *dest,
|
||||
struct fx_stream_buffer_p *buffer, size_t *out_nr_read)
|
||||
struct stream_data *src,
|
||||
struct fx_bstr *dest,
|
||||
struct fx_stream_buffer_p *buffer,
|
||||
size_t *out_nr_read)
|
||||
{
|
||||
if (!(src->s_cfg->s_mode & FX_STREAM_READ)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -533,7 +562,10 @@ static enum fx_status stream_read_all_bytes_to_bstr_s(
|
||||
while (1) {
|
||||
size_t r = 0, w = 0;
|
||||
status = stream_read_bytes(
|
||||
src, buffer->p_buf, buffer->p_buf_len, &r);
|
||||
src,
|
||||
buffer->p_buf,
|
||||
buffer->p_buf_len,
|
||||
&r);
|
||||
if (status != FX_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
@@ -557,8 +589,10 @@ static enum fx_status stream_read_all_bytes_to_bstr_s(
|
||||
return status;
|
||||
}
|
||||
|
||||
static enum fx_status stream_write_string(
|
||||
struct stream_data *stream, const char *s, size_t *nr_written)
|
||||
static enum fx_status stream_write_cstr(
|
||||
struct stream_data *stream,
|
||||
const char *s,
|
||||
size_t *nr_written)
|
||||
{
|
||||
size_t i;
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
@@ -610,7 +644,8 @@ static enum fx_status stream_push_indent(struct stream_data *stream, int indent)
|
||||
stream->s_private->s_istack_ptr = 0;
|
||||
}
|
||||
|
||||
if (stream->s_private->s_istack_ptr + 1 >= stream->s_private->s_istack_size) {
|
||||
if (stream->s_private->s_istack_ptr + 1
|
||||
>= stream->s_private->s_istack_size) {
|
||||
int *buf = realloc(
|
||||
stream->s_private->s_istack,
|
||||
(stream->s_private->s_istack_size + 4) * sizeof(int));
|
||||
@@ -735,20 +770,31 @@ enum fx_status fx_stream_reserve(fx_stream *stream, size_t len)
|
||||
}
|
||||
|
||||
FX_CLASS_DISPATCH_VIRTUAL(
|
||||
fx_stream, FX_TYPE_STREAM, FX_ERR_NOT_SUPPORTED, s_reserve, stream,
|
||||
fx_stream,
|
||||
FX_TYPE_STREAM,
|
||||
FX_ERR_NOT_SUPPORTED,
|
||||
s_reserve,
|
||||
stream,
|
||||
len);
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_seek(
|
||||
fx_stream *stream, long long offset, fx_stream_seek_origin origin)
|
||||
fx_stream *stream,
|
||||
long long offset,
|
||||
fx_stream_seek_origin origin)
|
||||
{
|
||||
if (IS_BSTR(stream)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
FX_CLASS_DISPATCH_VIRTUAL(
|
||||
fx_stream, FX_TYPE_STREAM, FX_ERR_NOT_SUPPORTED, s_seek, stream,
|
||||
offset, origin);
|
||||
fx_stream,
|
||||
FX_TYPE_STREAM,
|
||||
FX_ERR_NOT_SUPPORTED,
|
||||
s_seek,
|
||||
stream,
|
||||
offset,
|
||||
origin);
|
||||
}
|
||||
|
||||
size_t fx_stream_cursor(const fx_stream *stream)
|
||||
@@ -788,7 +834,10 @@ enum fx_status fx_stream_read_char(fx_stream *strp, int *c)
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_read_bytes(
|
||||
fx_stream *strp, void *buf, size_t count, size_t *nr_read)
|
||||
fx_stream *strp,
|
||||
void *buf,
|
||||
size_t count,
|
||||
size_t *nr_read)
|
||||
{
|
||||
if (IS_BSTR(strp)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -833,17 +882,28 @@ enum fx_status fx_stream_read_line_s(fx_stream *src, fx_stream *dest)
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_read_all_bytes(
|
||||
fx_stream *stream, void *p, size_t max, size_t *out_nr_read)
|
||||
fx_stream *stream,
|
||||
void *p,
|
||||
size_t max,
|
||||
size_t *out_nr_read)
|
||||
{
|
||||
if (IS_BSTR(stream)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
STREAM_DISPATCH_VIRTUAL(stream_read_all_bytes, stream, p, max, out_nr_read);
|
||||
STREAM_DISPATCH_VIRTUAL(
|
||||
stream_read_all_bytes,
|
||||
stream,
|
||||
p,
|
||||
max,
|
||||
out_nr_read);
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_read_all_bytes_s(
|
||||
fx_stream *src, fx_stream *dest, fx_stream_buffer *buffer, size_t *out_nr_read)
|
||||
fx_stream *src,
|
||||
fx_stream *dest,
|
||||
fx_stream_buffer *buffer,
|
||||
size_t *out_nr_read)
|
||||
{
|
||||
if (IS_BSTR(src)) {
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
@@ -865,7 +925,10 @@ enum fx_status fx_stream_read_all_bytes_s(
|
||||
|
||||
if (IS_BSTR(dest)) {
|
||||
return stream_read_all_bytes_to_bstr_s(
|
||||
&src_p, (fx_bstr *)dest, buffer_p, out_nr_read);
|
||||
&src_p,
|
||||
(fx_bstr *)dest,
|
||||
buffer_p,
|
||||
out_nr_read);
|
||||
}
|
||||
|
||||
status = stream_get_data(dest, &dest_p);
|
||||
@@ -885,34 +948,54 @@ enum fx_status fx_stream_write_char(fx_stream *stream, fx_wchar c)
|
||||
STREAM_DISPATCH_VIRTUAL(stream_write_char, stream, c);
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_write_string(
|
||||
fx_stream *stream, const char *s, size_t *nr_written)
|
||||
enum fx_status fx_stream_write_cstr(
|
||||
fx_stream *stream,
|
||||
const char *s,
|
||||
size_t *nr_written)
|
||||
{
|
||||
if (IS_BSTR(stream)) {
|
||||
return fx_bstr_write_cstr((fx_bstr *)stream, s, nr_written);
|
||||
}
|
||||
|
||||
STREAM_DISPATCH_VIRTUAL(stream_write_string, stream, s, nr_written);
|
||||
STREAM_DISPATCH_VIRTUAL(stream_write_cstr, stream, s, nr_written);
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_write_bytes(
|
||||
fx_stream *stream, const void *buf, size_t count, size_t *nr_written)
|
||||
fx_stream *stream,
|
||||
const void *buf,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
if (IS_BSTR(stream)) {
|
||||
return fx_bstr_write_chars((fx_bstr *)stream, buf, count, nr_written);
|
||||
return fx_bstr_write_chars(
|
||||
(fx_bstr *)stream,
|
||||
buf,
|
||||
count,
|
||||
nr_written);
|
||||
}
|
||||
|
||||
STREAM_DISPATCH_VIRTUAL(stream_write_bytes, stream, buf, count, nr_written);
|
||||
STREAM_DISPATCH_VIRTUAL(
|
||||
stream_write_bytes,
|
||||
stream,
|
||||
buf,
|
||||
count,
|
||||
nr_written);
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_write_fmt(
|
||||
fx_stream *stream, size_t *nr_written, const char *format, ...)
|
||||
fx_stream *stream,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
if (IS_BSTR(stream)) {
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
fx_status w = fx_bstr_write_vfmt(
|
||||
(fx_bstr *)stream, nr_written, format, arg);
|
||||
(fx_bstr *)stream,
|
||||
nr_written,
|
||||
format,
|
||||
arg);
|
||||
va_end(arg);
|
||||
|
||||
return w;
|
||||
@@ -934,10 +1017,17 @@ enum fx_status fx_stream_write_fmt(
|
||||
}
|
||||
|
||||
enum fx_status fx_stream_write_vfmt(
|
||||
fx_stream *stream, size_t *nr_written, const char *format, va_list arg)
|
||||
fx_stream *stream,
|
||||
size_t *nr_written,
|
||||
const char *format,
|
||||
va_list arg)
|
||||
{
|
||||
if (IS_BSTR(stream)) {
|
||||
return fx_bstr_write_vfmt((fx_bstr *)stream, nr_written, format, arg);
|
||||
return fx_bstr_write_vfmt(
|
||||
(fx_bstr *)stream,
|
||||
nr_written,
|
||||
format,
|
||||
arg);
|
||||
}
|
||||
|
||||
struct stream_data p;
|
||||
@@ -997,7 +1087,10 @@ static void stdio_stream_fini(fx_object *obj, void *priv)
|
||||
}
|
||||
|
||||
static enum fx_status stdio_read(
|
||||
fx_stream *stream, void *out, size_t max, size_t *nr_read)
|
||||
fx_stream *stream,
|
||||
void *out,
|
||||
size_t max,
|
||||
size_t *nr_read)
|
||||
{
|
||||
struct fx_stdio_stream_p *p
|
||||
= fx_object_get_private(stream, FX_TYPE_STDIO_STREAM);
|
||||
@@ -1015,7 +1108,10 @@ static enum fx_status stdio_read(
|
||||
}
|
||||
|
||||
static enum fx_status stdio_write(
|
||||
fx_stream *stream, const void *data, size_t count, size_t *nr_written)
|
||||
fx_stream *stream,
|
||||
const void *data,
|
||||
size_t count,
|
||||
size_t *nr_written)
|
||||
{
|
||||
struct fx_stdio_stream_p *p
|
||||
= fx_object_get_private(stream, FX_TYPE_STDIO_STREAM);
|
||||
@@ -1032,7 +1128,9 @@ static enum fx_status stdio_write(
|
||||
}
|
||||
|
||||
static enum fx_status stdio_seek(
|
||||
fx_stream *stream, long long offset, fx_stream_seek_origin origin)
|
||||
fx_stream *stream,
|
||||
long long offset,
|
||||
fx_stream_seek_origin origin)
|
||||
{
|
||||
struct fx_stdio_stream_p *p
|
||||
= fx_object_get_private(stream, FX_TYPE_STDIO_STREAM);
|
||||
|
||||
+14
-7
@@ -31,7 +31,8 @@ static fx_status resize_array(struct fx_array_p *array, size_t new_capacity)
|
||||
{
|
||||
if (array->ar_cap < new_capacity) {
|
||||
void *new_data = realloc(
|
||||
array->ar_data, new_capacity * sizeof(struct fx_dsref *));
|
||||
array->ar_data,
|
||||
new_capacity * sizeof(struct fx_dsref *));
|
||||
if (!new_data) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -43,7 +44,8 @@ static fx_status resize_array(struct fx_array_p *array, size_t new_capacity)
|
||||
}
|
||||
|
||||
void *new_data = realloc(
|
||||
array->ar_data, new_capacity * sizeof(struct fx_dsref *));
|
||||
array->ar_data,
|
||||
new_capacity * sizeof(struct fx_dsref *));
|
||||
if (!new_data) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -59,7 +61,10 @@ static fx_status resize_array(struct fx_array_p *array, size_t new_capacity)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_status array_insert(struct fx_array_p *array, fx_object *value, size_t at)
|
||||
static fx_status array_insert(
|
||||
struct fx_array_p *array,
|
||||
fx_object *value,
|
||||
size_t at)
|
||||
{
|
||||
if (at == FX_NPOS) {
|
||||
at = array->ar_len;
|
||||
@@ -193,7 +198,9 @@ static void array_clear(struct fx_array_p *array)
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_array *fx_array_create_with_values(fx_object *const *values, size_t nr_values)
|
||||
fx_array *fx_array_create_with_values(
|
||||
fx_object *const *values,
|
||||
size_t nr_values)
|
||||
{
|
||||
fx_array *array = fx_array_create();
|
||||
if (!array) {
|
||||
@@ -323,11 +330,11 @@ static void array_to_string(const fx_object *obj, fx_stream *out)
|
||||
struct fx_array_p *array = fx_object_get_private(obj, FX_TYPE_ARRAY);
|
||||
|
||||
if (!array->ar_len) {
|
||||
fx_stream_write_string(out, "[]", NULL);
|
||||
fx_stream_write_cstr(out, "[]", NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
fx_stream_write_string(out, "[\n", NULL);
|
||||
fx_stream_write_cstr(out, "[\n", NULL);
|
||||
|
||||
fx_stream_push_indent(out, 1);
|
||||
size_t len = array_size(array);
|
||||
@@ -347,7 +354,7 @@ static void array_to_string(const fx_object *obj, fx_stream *out)
|
||||
}
|
||||
|
||||
if (i < len - 1) {
|
||||
fx_stream_write_string(out, ",", NULL);
|
||||
fx_stream_write_cstr(out, ",", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_char(out, '\n');
|
||||
|
||||
@@ -36,9 +36,16 @@ struct fx_dict_iterator_p {
|
||||
/*** MISC FUNCTIONS ***********************************************************/
|
||||
|
||||
static FX_BST_DEFINE_SIMPLE_GET(
|
||||
struct fx_dict_bucket, uint64_t, bk_node, bk_hash, get_bucket);
|
||||
struct fx_dict_bucket,
|
||||
uint64_t,
|
||||
bk_node,
|
||||
bk_hash,
|
||||
get_bucket);
|
||||
static FX_BST_DEFINE_SIMPLE_INSERT(
|
||||
struct fx_dict_bucket, bk_node, bk_hash, put_bucket);
|
||||
struct fx_dict_bucket,
|
||||
bk_node,
|
||||
bk_hash,
|
||||
put_bucket);
|
||||
|
||||
uint64_t fx_cstr_hash(const char *s)
|
||||
{
|
||||
@@ -79,7 +86,10 @@ static struct fx_dict_bucket_item *create_bucket_item(void)
|
||||
return item;
|
||||
}
|
||||
|
||||
static fx_status dict_put(struct fx_dict_p *dict, const char *key, fx_object *value)
|
||||
static fx_status dict_put(
|
||||
struct fx_dict_p *dict,
|
||||
const char *key,
|
||||
fx_object *value)
|
||||
{
|
||||
uint64_t hash = fx_cstr_hash(key);
|
||||
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
|
||||
@@ -107,7 +117,9 @@ static fx_status dict_put(struct fx_dict_p *dict, const char *key, fx_object *va
|
||||
}
|
||||
|
||||
static fx_status dict_put_sk(
|
||||
struct fx_dict_p *dict, const fx_string *key, fx_object *value)
|
||||
struct fx_dict_p *dict,
|
||||
const fx_string *key,
|
||||
fx_object *value)
|
||||
{
|
||||
uint64_t hash = fx_string_hash(key);
|
||||
struct fx_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
|
||||
@@ -147,7 +159,7 @@ static fx_object *dict_at(const struct fx_dict_p *dict, const char *key)
|
||||
struct fx_dict_bucket_item *item
|
||||
= fx_unbox(struct fx_dict_bucket_item, entry, bi_entry);
|
||||
|
||||
if (!strcmp(fx_string_ptr(item->bi_str), key)) {
|
||||
if (!strcmp(fx_string_get_cstr(item->bi_str), key)) {
|
||||
return item->bi_value;
|
||||
}
|
||||
|
||||
@@ -250,8 +262,10 @@ static bool dict_is_empty(const struct fx_dict_p *dict)
|
||||
}
|
||||
|
||||
static bool get_next_node(
|
||||
struct fx_bst_node *cur_node, struct fx_queue_entry *cur_entry,
|
||||
struct fx_bst_node **out_next_node, struct fx_queue_entry **out_next_entry)
|
||||
struct fx_bst_node *cur_node,
|
||||
struct fx_queue_entry *cur_entry,
|
||||
struct fx_bst_node **out_next_node,
|
||||
struct fx_queue_entry **out_next_entry)
|
||||
{
|
||||
struct fx_dict_bucket *cur_bucket
|
||||
= fx_unbox(struct fx_dict_bucket, cur_node, bk_node);
|
||||
@@ -298,7 +312,8 @@ static bool get_next_node(
|
||||
}
|
||||
|
||||
static fx_status delete_item(
|
||||
struct fx_dict_p *dict, struct fx_dict_bucket *bucket,
|
||||
struct fx_dict_p *dict,
|
||||
struct fx_dict_bucket *bucket,
|
||||
struct fx_dict_bucket_item *item)
|
||||
{
|
||||
fx_queue_delete(&bucket->bk_items, &item->bi_entry);
|
||||
@@ -401,11 +416,15 @@ static void dict_fini(fx_object *obj, void *priv)
|
||||
struct fx_bst_node *next_node = fx_bst_next(node);
|
||||
fx_bst_delete(&dict->d_buckets, node);
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
struct fx_queue_entry *entry
|
||||
= fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_dict_bucket_item *item = fx_unbox(
|
||||
struct fx_dict_bucket_item, entry, bi_entry);
|
||||
struct fx_queue_entry *next_entry = fx_queue_next(entry);
|
||||
struct fx_dict_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
struct fx_queue_entry *next_entry
|
||||
= fx_queue_next(entry);
|
||||
fx_queue_delete(&bucket->bk_items, entry);
|
||||
|
||||
free(item->bi_str);
|
||||
@@ -425,11 +444,11 @@ static void dict_to_string(const fx_object *obj, fx_stream *out)
|
||||
struct fx_dict_p *dict = fx_object_get_private(obj, FX_TYPE_DICT);
|
||||
|
||||
if (dict_is_empty(dict)) {
|
||||
fx_stream_write_string(out, "{}", NULL);
|
||||
fx_stream_write_cstr(out, "{}", NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
fx_stream_write_string(out, "{\n", NULL);
|
||||
fx_stream_write_cstr(out, "{\n", NULL);
|
||||
|
||||
fx_stream_push_indent(out, 1);
|
||||
size_t len = dict_get_size(dict);
|
||||
@@ -440,16 +459,20 @@ static void dict_to_string(const fx_object *obj, fx_stream *out)
|
||||
struct fx_dict_bucket *bucket
|
||||
= fx_unbox(struct fx_dict_bucket, node, bk_node);
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
struct fx_queue_entry *entry
|
||||
= fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_dict_bucket_item *item = fx_unbox(
|
||||
struct fx_dict_bucket_item, entry, bi_entry);
|
||||
struct fx_dict_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
fx_object_to_string(item->bi_str, out);
|
||||
fx_stream_write_string(out, ": ", NULL);
|
||||
fx_stream_write_cstr(out, ": ", NULL);
|
||||
|
||||
bool is_string = fx_object_is_type(
|
||||
item->bi_value, FX_TYPE_STRING);
|
||||
item->bi_value,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
if (is_string) {
|
||||
fx_stream_write_char(out, '"');
|
||||
@@ -462,7 +485,7 @@ static void dict_to_string(const fx_object *obj, fx_stream *out)
|
||||
}
|
||||
|
||||
if (i < len - 1) {
|
||||
fx_stream_write_string(out, ",", NULL);
|
||||
fx_stream_write_cstr(out, ",", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_char(out, '\n');
|
||||
|
||||
+38
-23
@@ -1,12 +1,12 @@
|
||||
#ifndef FX_DS_STRING_H_
|
||||
#define FX_DS_STRING_H_
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fx/core/encoding.h>
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <ctype.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -52,18 +52,22 @@ FX_API fx_string *fx_string_duplicate(const fx_string *str);
|
||||
FX_API char *fx_string_steal(fx_string *str);
|
||||
FX_API fx_status fx_string_reserve(fx_string *str, size_t capacity);
|
||||
FX_API fx_status fx_string_replace(
|
||||
fx_string *str, size_t start, size_t length, const char *new_data);
|
||||
fx_string *str,
|
||||
size_t start,
|
||||
size_t length,
|
||||
const char *new_data);
|
||||
FX_API fx_status fx_string_replace_all(fx_string *str, const char *new_data);
|
||||
FX_API fx_status fx_string_replace_all_with_stringstream(
|
||||
fx_string *str, const fx_stringstream *new_data);
|
||||
fx_string *str,
|
||||
const fx_stringstream *new_data);
|
||||
FX_API fx_status fx_string_remove(fx_string *str, size_t start, size_t length);
|
||||
FX_API fx_status fx_string_transform(fx_string *str, int (*transformer)(int));
|
||||
FX_API fx_status fx_string_trim(fx_string *str);
|
||||
static inline fx_status fx_string_toupper(fx_string *str)
|
||||
static inline fx_status fx_string_transform_uppercase(fx_string *str)
|
||||
{
|
||||
return fx_string_transform(str, toupper);
|
||||
}
|
||||
static inline fx_status fx_string_tolower(fx_string *str)
|
||||
static inline fx_status fx_string_transform_lowercase(fx_string *str)
|
||||
{
|
||||
return fx_string_transform(str, tolower);
|
||||
}
|
||||
@@ -73,30 +77,36 @@ FX_API fx_status fx_string_append_wc(fx_string *dest, fx_wchar c);
|
||||
FX_API fx_status fx_string_append_s(fx_string *dest, const fx_string *src);
|
||||
FX_API fx_status fx_string_append_cstr(fx_string *dest, const char *src);
|
||||
FX_API fx_status fx_string_append_wstr(fx_string *dest, const fx_wchar *src);
|
||||
FX_API fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...);
|
||||
FX_API fx_status
|
||||
fx_string_append_cstrf(fx_string *dest, const char *format, ...);
|
||||
|
||||
FX_API fx_status fx_string_prepend_c(fx_string *dest, char c);
|
||||
FX_API fx_status fx_string_prepend_wc(fx_string *dest, fx_wchar c);
|
||||
FX_API fx_status fx_string_prepend_cstr(fx_string *dest, const char *src);
|
||||
FX_API fx_status fx_string_prepend_wstr(fx_string *dest, const fx_wchar *src);
|
||||
FX_API fx_status fx_string_prepend_cstrf(fx_string *dest, const char *format, ...);
|
||||
FX_API fx_status
|
||||
fx_string_prepend_cstrf(fx_string *dest, const char *format, ...);
|
||||
|
||||
FX_API fx_status fx_string_insert_c(fx_string *dest, char c, size_t at);
|
||||
FX_API fx_status fx_string_insert_wc(fx_string *dest, fx_wchar c, size_t at);
|
||||
FX_API fx_status fx_string_insert_s(fx_string *dest, const fx_string *src, size_t at);
|
||||
FX_API fx_status fx_string_insert_cstr(fx_string *dest, const char *src, size_t at);
|
||||
FX_API fx_status fx_string_insert_wstr(
|
||||
fx_string *dest, const fx_wchar *src, size_t at);
|
||||
FX_API fx_status fx_string_insert_cstrn(
|
||||
fx_string *dest, const char *src, size_t len, size_t at);
|
||||
FX_API fx_status fx_string_insert_wstrn(
|
||||
fx_string *dest, const char *src, size_t len, size_t at);
|
||||
FX_API fx_status fx_string_insert_cstrf(
|
||||
fx_string *dest, size_t at, const char *format, ...);
|
||||
FX_API fx_status
|
||||
fx_string_insert_s(fx_string *dest, const fx_string *src, size_t at);
|
||||
FX_API fx_status
|
||||
fx_string_insert_cstr(fx_string *dest, const char *src, size_t at);
|
||||
FX_API fx_status
|
||||
fx_string_insert_wstr(fx_string *dest, const fx_wchar *src, size_t at);
|
||||
FX_API fx_status
|
||||
fx_string_insert_cstrn(fx_string *dest, const char *src, size_t len, size_t at);
|
||||
FX_API fx_status
|
||||
fx_string_insert_wstrn(fx_string *dest, const char *src, size_t len, size_t at);
|
||||
FX_API fx_status
|
||||
fx_string_insert_cstrf(fx_string *dest, size_t at, const char *format, ...);
|
||||
FX_API void fx_string_clear(fx_string *str);
|
||||
|
||||
FX_API fx_iterator *fx_string_tokenise(
|
||||
fx_string *str, const char *delims[], size_t nr_delims,
|
||||
fx_string *str,
|
||||
const char *delims[],
|
||||
size_t nr_delims,
|
||||
fx_string_tokenise_flags flags);
|
||||
|
||||
FX_API size_t fx_string_get_size(const fx_string *str, fx_strlen_flags flags);
|
||||
@@ -104,15 +114,20 @@ FX_API size_t fx_string_get_capacity(const fx_string *str);
|
||||
|
||||
FX_API bool fx_string_compare(const fx_string *a, const fx_string *b);
|
||||
|
||||
FX_API char fx_string_front(const fx_string *str);
|
||||
FX_API char fx_string_back(const fx_string *str);
|
||||
FX_API char fx_string_get_first_char(const fx_string *str);
|
||||
FX_API char fx_string_get_last_char(const fx_string *str);
|
||||
|
||||
FX_API void fx_string_pop_back(fx_string *str);
|
||||
|
||||
FX_API const char *fx_string_ptr(const fx_string *str);
|
||||
FX_API fx_string *fx_string_substr(const fx_string *str, size_t start, size_t len);
|
||||
FX_API const char *fx_string_get_cstr(const fx_string *str);
|
||||
FX_API fx_string *fx_string_get_substr(
|
||||
const fx_string *str,
|
||||
size_t start,
|
||||
size_t len);
|
||||
|
||||
FX_API int fx_string_iterator_begin(const fx_string *string, fx_string_iterator *it);
|
||||
FX_API int fx_string_iterator_begin(
|
||||
const fx_string *string,
|
||||
fx_string_iterator *it);
|
||||
FX_API bool fx_string_iterator_next(fx_string_iterator *it);
|
||||
// FX_API fx_status fx_string_iterator_erase(fx_string_iterator *it);
|
||||
FX_API bool fx_string_iterator_is_valid(const fx_string_iterator *it);
|
||||
|
||||
+244
-71
@@ -34,7 +34,8 @@ struct fx_number_p {
|
||||
|
||||
typedef int (*number_converter_t)(const struct fx_number_p *, void *);
|
||||
|
||||
static number_converter_t converters[FX_NUMBER_TYPE_COUNT][FX_NUMBER_TYPE_COUNT];
|
||||
static number_converter_t converters[FX_NUMBER_TYPE_COUNT]
|
||||
[FX_NUMBER_TYPE_COUNT];
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
@@ -44,7 +45,9 @@ static fx_number_type number_get_number_type(const struct fx_number_p *number)
|
||||
}
|
||||
|
||||
static int number_get_value(
|
||||
const struct fx_number_p *number, fx_number_type type, void *value_ptr)
|
||||
const struct fx_number_p *number,
|
||||
fx_number_type type,
|
||||
void *value_ptr)
|
||||
{
|
||||
fx_number_type srb_type = number->n_type;
|
||||
fx_number_type dest_type = type;
|
||||
@@ -532,110 +535,188 @@ static void print_inf(const struct fx_number_p *n, fx_stream *out)
|
||||
{
|
||||
switch (n->n_type) {
|
||||
case FX_NUMBER_INT8:
|
||||
fx_stream_write_string(out, n->n_value.v_int8 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int8 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT16:
|
||||
fx_stream_write_string(out, n->n_value.v_int16 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int16 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT32:
|
||||
fx_stream_write_string(out, n->n_value.v_int32 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int32 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT64:
|
||||
fx_stream_write_string(out, n->n_value.v_int64 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int64 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT32:
|
||||
fx_stream_write_string(
|
||||
out, n->n_value.v_float32 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_float32 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT64:
|
||||
fx_stream_write_string(
|
||||
out, n->n_value.v_float64 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_float64 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_CHAR:
|
||||
fx_stream_write_string(out, n->n_value.v_char < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_char < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_SHORT:
|
||||
fx_stream_write_string(out, n->n_value.v_short < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_short < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT:
|
||||
fx_stream_write_string(out, n->n_value.v_int < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_LONG:
|
||||
fx_stream_write_string(out, n->n_value.v_long < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_long < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_LONGLONG:
|
||||
fx_stream_write_string(
|
||||
out, n->n_value.v_longlong < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_longlong < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT:
|
||||
fx_stream_write_string(out, n->n_value.v_float < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_float < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_DOUBLE:
|
||||
fx_stream_write_string(out, n->n_value.v_double < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_double < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_SIZE_T:
|
||||
fx_stream_write_string(out, n->n_value.v_size_t < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_size_t < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
fx_stream_write_string(out, "INF", NULL);
|
||||
fx_stream_write_cstr(out, "INF", NULL);
|
||||
}
|
||||
|
||||
static void print_nan(const struct fx_number_p *n, fx_stream *out)
|
||||
{
|
||||
switch (n->n_type) {
|
||||
case FX_NUMBER_INT8:
|
||||
fx_stream_write_string(out, n->n_value.v_int8 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int8 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT16:
|
||||
fx_stream_write_string(out, n->n_value.v_int16 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int16 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT32:
|
||||
fx_stream_write_string(out, n->n_value.v_int32 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int32 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT64:
|
||||
fx_stream_write_string(out, n->n_value.v_int64 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int64 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT32:
|
||||
fx_stream_write_string(
|
||||
out, n->n_value.v_float32 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_float32 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT64:
|
||||
fx_stream_write_string(
|
||||
out, n->n_value.v_float64 < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_float64 < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_CHAR:
|
||||
fx_stream_write_string(out, n->n_value.v_char < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_char < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_SHORT:
|
||||
fx_stream_write_string(out, n->n_value.v_short < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_short < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_INT:
|
||||
fx_stream_write_string(out, n->n_value.v_int < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_int < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_LONG:
|
||||
fx_stream_write_string(out, n->n_value.v_long < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_long < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_LONGLONG:
|
||||
fx_stream_write_string(
|
||||
out, n->n_value.v_longlong < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_longlong < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT:
|
||||
fx_stream_write_string(out, n->n_value.v_float < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_float < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_DOUBLE:
|
||||
fx_stream_write_string(out, n->n_value.v_double < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_double < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
case FX_NUMBER_SIZE_T:
|
||||
fx_stream_write_string(out, n->n_value.v_size_t < 0 ? "-" : "", NULL);
|
||||
fx_stream_write_cstr(
|
||||
out,
|
||||
n->n_value.v_size_t < 0 ? "-" : "",
|
||||
NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
fx_stream_write_string(out, "NaN", NULL);
|
||||
fx_stream_write_cstr(out, "NaN", NULL);
|
||||
}
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
@@ -660,27 +741,37 @@ fx_number *fx_number_create(fx_number_type type, void *value_ptr)
|
||||
memcpy(&p->n_value.v_int8, value_ptr, sizeof p->n_value.v_int8);
|
||||
break;
|
||||
case FX_NUMBER_INT16:
|
||||
memcpy(&p->n_value.v_int16, value_ptr, sizeof p->n_value.v_int16);
|
||||
memcpy(&p->n_value.v_int16,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_int16);
|
||||
break;
|
||||
case FX_NUMBER_INT32:
|
||||
memcpy(&p->n_value.v_int32, value_ptr, sizeof p->n_value.v_int32);
|
||||
memcpy(&p->n_value.v_int32,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_int32);
|
||||
break;
|
||||
case FX_NUMBER_INT64:
|
||||
memcpy(&p->n_value.v_int64, value_ptr, sizeof p->n_value.v_int64);
|
||||
memcpy(&p->n_value.v_int64,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_int64);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT32:
|
||||
memcpy(&p->n_value.v_float32, value_ptr,
|
||||
memcpy(&p->n_value.v_float32,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_float32);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT64:
|
||||
memcpy(&p->n_value.v_float64, value_ptr,
|
||||
memcpy(&p->n_value.v_float64,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_float64);
|
||||
break;
|
||||
case FX_NUMBER_CHAR:
|
||||
memcpy(&p->n_value.v_char, value_ptr, sizeof p->n_value.v_char);
|
||||
break;
|
||||
case FX_NUMBER_SHORT:
|
||||
memcpy(&p->n_value.v_short, value_ptr, sizeof p->n_value.v_short);
|
||||
memcpy(&p->n_value.v_short,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_short);
|
||||
break;
|
||||
case FX_NUMBER_INT:
|
||||
memcpy(&p->n_value.v_int, value_ptr, sizeof p->n_value.v_int);
|
||||
@@ -689,17 +780,24 @@ fx_number *fx_number_create(fx_number_type type, void *value_ptr)
|
||||
memcpy(&p->n_value.v_long, value_ptr, sizeof p->n_value.v_long);
|
||||
break;
|
||||
case FX_NUMBER_LONGLONG:
|
||||
memcpy(&p->n_value.v_longlong, value_ptr,
|
||||
memcpy(&p->n_value.v_longlong,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_longlong);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT:
|
||||
memcpy(&p->n_value.v_float, value_ptr, sizeof p->n_value.v_float);
|
||||
memcpy(&p->n_value.v_float,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_float);
|
||||
break;
|
||||
case FX_NUMBER_DOUBLE:
|
||||
memcpy(&p->n_value.v_double, value_ptr, sizeof p->n_value.v_double);
|
||||
memcpy(&p->n_value.v_double,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_double);
|
||||
break;
|
||||
case FX_NUMBER_SIZE_T:
|
||||
memcpy(&p->n_value.v_size_t, value_ptr, sizeof p->n_value.v_size_t);
|
||||
memcpy(&p->n_value.v_size_t,
|
||||
value_ptr,
|
||||
sizeof p->n_value.v_size_t);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -710,13 +808,23 @@ fx_number *fx_number_create(fx_number_type type, void *value_ptr)
|
||||
|
||||
fx_number_type fx_number_get_number_type(const fx_number *number)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_NUMBER, number_get_number_type, number);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_NUMBER,
|
||||
number_get_number_type,
|
||||
number);
|
||||
}
|
||||
|
||||
int fx_number_get_value(const fx_number *number, fx_number_type type, void *value_ptr)
|
||||
int fx_number_get_value(
|
||||
const fx_number *number,
|
||||
fx_number_type type,
|
||||
void *value_ptr)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_NUMBER, number_get_value, number, type, value_ptr);
|
||||
FX_TYPE_NUMBER,
|
||||
number_get_value,
|
||||
number,
|
||||
type,
|
||||
value_ptr);
|
||||
}
|
||||
|
||||
bool fx_number_is_integer(const fx_number *number)
|
||||
@@ -736,12 +844,18 @@ bool fx_number_is_inf(const fx_number *number)
|
||||
|
||||
bool fx_number_is_inf_positive(const fx_number *number)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_NUMBER, number_is_inf_positive, number);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_NUMBER,
|
||||
number_is_inf_positive,
|
||||
number);
|
||||
}
|
||||
|
||||
bool fx_number_is_inf_negative(const fx_number *number)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_NUMBER, number_is_inf_negative, number);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_NUMBER,
|
||||
number_is_inf_negative,
|
||||
number);
|
||||
}
|
||||
|
||||
bool fx_number_is_nan(const fx_number *number)
|
||||
@@ -751,32 +865,54 @@ bool fx_number_is_nan(const fx_number *number)
|
||||
|
||||
bool fx_number_is_nan_positive(const fx_number *number)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_NUMBER, number_is_nan_positive, number);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_NUMBER,
|
||||
number_is_nan_positive,
|
||||
number);
|
||||
}
|
||||
|
||||
bool fx_number_is_nan_negative(const fx_number *number)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_NUMBER, number_is_nan_negative, number);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_NUMBER,
|
||||
number_is_nan_negative,
|
||||
number);
|
||||
}
|
||||
|
||||
void fx_number_set_inf_positive(fx_number *number, bool v)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_NUMBER, number_set_inf_positive, number, v);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_NUMBER,
|
||||
number_set_inf_positive,
|
||||
number,
|
||||
v);
|
||||
}
|
||||
|
||||
void fx_number_set_inf_negative(fx_number *number, bool v)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_NUMBER, number_set_inf_negative, number, v);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_NUMBER,
|
||||
number_set_inf_negative,
|
||||
number,
|
||||
v);
|
||||
}
|
||||
|
||||
void fx_number_set_nan_positive(fx_number *number, bool v)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_NUMBER, number_set_nan_positive, number, v);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_NUMBER,
|
||||
number_set_nan_positive,
|
||||
number,
|
||||
v);
|
||||
}
|
||||
|
||||
void fx_number_set_nan_negative(fx_number *number, bool v)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_NUMBER, number_set_nan_negative, number, v);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_NUMBER,
|
||||
number_set_nan_negative,
|
||||
number,
|
||||
v);
|
||||
}
|
||||
|
||||
size_t fx_number_data_size(const fx_number *number)
|
||||
@@ -812,22 +948,42 @@ static void number_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
switch (number->n_type) {
|
||||
case FX_NUMBER_INT8:
|
||||
fx_stream_write_fmt(out, NULL, "%" PRIu8, number->n_value.v_int8);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"%" PRIu8,
|
||||
number->n_value.v_int8);
|
||||
break;
|
||||
case FX_NUMBER_INT16:
|
||||
fx_stream_write_fmt(out, NULL, "%" PRIu16, number->n_value.v_int16);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"%" PRIu16,
|
||||
number->n_value.v_int16);
|
||||
break;
|
||||
case FX_NUMBER_INT32:
|
||||
fx_stream_write_fmt(out, NULL, "%" PRIu32, number->n_value.v_int32);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"%" PRIu32,
|
||||
number->n_value.v_int32);
|
||||
break;
|
||||
case FX_NUMBER_INT64:
|
||||
fx_stream_write_fmt(out, NULL, "%" PRIu64, number->n_value.v_int64);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"%" PRIu64,
|
||||
number->n_value.v_int64);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT32:
|
||||
fx_stream_write_fmt(out, NULL, "%f", number->n_value.v_float32);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT64:
|
||||
fx_stream_write_fmt(out, NULL, "%lf", number->n_value.v_float64);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"%lf",
|
||||
number->n_value.v_float64);
|
||||
break;
|
||||
case FX_NUMBER_CHAR:
|
||||
fx_stream_write_fmt(out, NULL, "%d", number->n_value.v_char);
|
||||
@@ -842,7 +998,11 @@ static void number_to_string(const fx_object *obj, fx_stream *out)
|
||||
fx_stream_write_fmt(out, NULL, "%ld", number->n_value.v_long);
|
||||
break;
|
||||
case FX_NUMBER_LONGLONG:
|
||||
fx_stream_write_fmt(out, NULL, "%lld", number->n_value.v_longlong);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"%lld",
|
||||
number->n_value.v_longlong);
|
||||
break;
|
||||
case FX_NUMBER_FLOAT:
|
||||
fx_stream_write_fmt(out, NULL, "%f", number->n_value.v_float);
|
||||
@@ -855,7 +1015,10 @@ static void number_to_string(const fx_object *obj, fx_stream *out)
|
||||
break;
|
||||
case FX_NUMBER_HANDLE:
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%016" PRIx64, number->n_value.v_size_t);
|
||||
out,
|
||||
NULL,
|
||||
"%016" PRIx64,
|
||||
number->n_value.v_size_t);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1286,7 +1449,9 @@ static int float32_to_long(const struct fx_number_p *number, void *value_ptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int float32_to_longlong(const struct fx_number_p *number, void *value_ptr)
|
||||
static int float32_to_longlong(
|
||||
const struct fx_number_p *number,
|
||||
void *value_ptr)
|
||||
{
|
||||
*(long long *)value_ptr = number->n_value.v_float32;
|
||||
return 0;
|
||||
@@ -1372,7 +1537,9 @@ static int float64_to_long(const struct fx_number_p *number, void *value_ptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int float64_to_longlong(const struct fx_number_p *number, void *value_ptr)
|
||||
static int float64_to_longlong(
|
||||
const struct fx_number_p *number,
|
||||
void *value_ptr)
|
||||
{
|
||||
*(long long *)value_ptr = number->n_value.v_float64;
|
||||
return 0;
|
||||
@@ -1766,13 +1933,17 @@ static int longlong_to_int64(const struct fx_number_p *number, void *value_ptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int longlong_to_float32(const struct fx_number_p *number, void *value_ptr)
|
||||
static int longlong_to_float32(
|
||||
const struct fx_number_p *number,
|
||||
void *value_ptr)
|
||||
{
|
||||
*(float *)value_ptr = number->n_value.v_longlong;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int longlong_to_float64(const struct fx_number_p *number, void *value_ptr)
|
||||
static int longlong_to_float64(
|
||||
const struct fx_number_p *number,
|
||||
void *value_ptr)
|
||||
{
|
||||
*(double *)value_ptr = number->n_value.v_longlong;
|
||||
return 0;
|
||||
@@ -1802,7 +1973,9 @@ static int longlong_to_long(const struct fx_number_p *number, void *value_ptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int longlong_to_longlong(const struct fx_number_p *number, void *value_ptr)
|
||||
static int longlong_to_longlong(
|
||||
const struct fx_number_p *number,
|
||||
void *value_ptr)
|
||||
{
|
||||
*(long long *)value_ptr = number->n_value.v_longlong;
|
||||
return 0;
|
||||
|
||||
+214
-63
@@ -1,7 +1,7 @@
|
||||
#include <ctype.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -27,7 +27,8 @@ enum iterator_mode {
|
||||
|
||||
struct fx_string_p {
|
||||
/* length of string in bytes, not including null-terminator.
|
||||
* a multi-byte utf-8 codepoint will be counted as multiple bytes here */
|
||||
* a multi-byte utf-8 codepoint will be counted as multiple bytes here
|
||||
*/
|
||||
unsigned int s_len;
|
||||
/* length of string in codepoints, not including null-terminator.
|
||||
* a multi-byte utf-8 codepoint will be counted as one codepoint here */
|
||||
@@ -76,8 +77,11 @@ static char *string_ptr(const struct fx_string_p *str)
|
||||
}
|
||||
|
||||
static enum fx_status convert_codepoint_range_to_byte_range(
|
||||
const struct fx_string_p *str, size_t cp_start, size_t cp_length,
|
||||
size_t *out_byte_start, size_t *out_byte_length)
|
||||
const struct fx_string_p *str,
|
||||
size_t cp_start,
|
||||
size_t cp_length,
|
||||
size_t *out_byte_start,
|
||||
size_t *out_byte_length)
|
||||
{
|
||||
const char *s = string_ptr(str);
|
||||
size_t byte_offset = 0, byte_length = 0;
|
||||
@@ -146,7 +150,9 @@ static char *get_next_codepoint(struct fx_string_p *str, char *this_codepoint)
|
||||
return this_codepoint + len;
|
||||
}
|
||||
|
||||
static char *get_previous_codepoint(struct fx_string_p *str, char *this_codepoint)
|
||||
static char *get_previous_codepoint(
|
||||
struct fx_string_p *str,
|
||||
char *this_codepoint)
|
||||
{
|
||||
char *start = string_ptr(str);
|
||||
char *end = this_codepoint - 1;
|
||||
@@ -260,7 +266,8 @@ static int string_change_capacity(struct fx_string_p *str, size_t capacity)
|
||||
}
|
||||
|
||||
if (!is_now_inline) {
|
||||
/* string was inline, and now large enough to require a buffer. */
|
||||
/* string was inline, and now large enough to require a buffer.
|
||||
*/
|
||||
return string_make_large(str, capacity);
|
||||
}
|
||||
|
||||
@@ -322,7 +329,10 @@ static fx_status string_reserve(struct fx_string_p *str, size_t capacity)
|
||||
}
|
||||
|
||||
static enum fx_status replace_ansi(
|
||||
struct fx_string_p *str, size_t start, size_t length, const char *new_data)
|
||||
struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t length,
|
||||
const char *new_data)
|
||||
{
|
||||
fx_status status = FX_SUCCESS;
|
||||
size_t new_data_len = strlen(new_data);
|
||||
@@ -361,7 +371,10 @@ static enum fx_status replace_ansi(
|
||||
}
|
||||
|
||||
static enum fx_status replace_utf8(
|
||||
struct fx_string_p *str, size_t start, size_t length, const char *new_data)
|
||||
struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t length,
|
||||
const char *new_data)
|
||||
{
|
||||
if (start >= str->s_codepoints) {
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
@@ -382,12 +395,17 @@ static enum fx_status replace_utf8(
|
||||
size_t old_data_offset = 0, old_data_nr_bytes = 0;
|
||||
size_t old_data_nr_codepoints = length;
|
||||
enum fx_status status = convert_codepoint_range_to_byte_range(
|
||||
str, start, length, &old_data_offset, &old_data_nr_bytes);
|
||||
str,
|
||||
start,
|
||||
length,
|
||||
&old_data_offset,
|
||||
&old_data_nr_bytes);
|
||||
if (!FX_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t new_total_bytes = str->s_len - old_data_nr_bytes + new_data_nr_bytes;
|
||||
size_t new_total_bytes
|
||||
= str->s_len - old_data_nr_bytes + new_data_nr_bytes;
|
||||
if (new_total_bytes > str->s_max) {
|
||||
status = string_reserve(str, new_total_bytes);
|
||||
}
|
||||
@@ -415,7 +433,10 @@ static enum fx_status replace_utf8(
|
||||
}
|
||||
|
||||
static fx_status string_replace(
|
||||
struct fx_string_p *str, size_t start, size_t length, const char *new_data)
|
||||
struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t length,
|
||||
const char *new_data)
|
||||
{
|
||||
if (str->s_len == str->s_codepoints) {
|
||||
return replace_ansi(str, start, length, new_data);
|
||||
@@ -424,7 +445,9 @@ static fx_status string_replace(
|
||||
return replace_utf8(str, start, length, new_data);
|
||||
}
|
||||
|
||||
static fx_status string_replace_all(struct fx_string_p *str, const char *new_data)
|
||||
static fx_status string_replace_all(
|
||||
struct fx_string_p *str,
|
||||
const char *new_data)
|
||||
{
|
||||
size_t new_len = strlen(new_data);
|
||||
string_reserve(str, new_len);
|
||||
@@ -437,7 +460,8 @@ static fx_status string_replace_all(struct fx_string_p *str, const char *new_dat
|
||||
}
|
||||
|
||||
static fx_status string_replace_all_with_stringstream(
|
||||
struct fx_string_p *str, const fx_stringstream *new_data)
|
||||
struct fx_string_p *str,
|
||||
const fx_stringstream *new_data)
|
||||
{
|
||||
size_t new_len = fx_stringstream_get_length(new_data);
|
||||
string_reserve(str, new_len);
|
||||
@@ -451,7 +475,10 @@ static fx_status string_replace_all_with_stringstream(
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum fx_status remove_ansi(struct fx_string_p *str, size_t start, size_t length)
|
||||
static enum fx_status remove_ansi(
|
||||
struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t length)
|
||||
{
|
||||
fx_status status = FX_SUCCESS;
|
||||
|
||||
@@ -479,11 +506,18 @@ static enum fx_status remove_ansi(struct fx_string_p *str, size_t start, size_t
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum fx_status remove_utf8(struct fx_string_p *str, size_t start, size_t length)
|
||||
static enum fx_status remove_utf8(
|
||||
struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t length)
|
||||
{
|
||||
size_t remove_offset = 0, remove_nr_bytes = 0;
|
||||
enum fx_status status = convert_codepoint_range_to_byte_range(
|
||||
str, start, length, &remove_offset, &remove_nr_bytes);
|
||||
str,
|
||||
start,
|
||||
length,
|
||||
&remove_offset,
|
||||
&remove_nr_bytes);
|
||||
if (!FX_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
@@ -506,7 +540,9 @@ static enum fx_status remove_utf8(struct fx_string_p *str, size_t start, size_t
|
||||
}
|
||||
|
||||
static enum fx_status string_remove(
|
||||
struct fx_string_p *str, size_t start, size_t length)
|
||||
struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t length)
|
||||
{
|
||||
if (str->s_len == str->s_codepoints) {
|
||||
return remove_ansi(str, start, length);
|
||||
@@ -515,7 +551,9 @@ static enum fx_status string_remove(
|
||||
return remove_utf8(str, start, length);
|
||||
}
|
||||
|
||||
static fx_status string_transform(struct fx_string_p *str, int (*transformer)(int))
|
||||
static fx_status string_transform(
|
||||
struct fx_string_p *str,
|
||||
int (*transformer)(int))
|
||||
{
|
||||
char *s = string_ptr(str);
|
||||
for (size_t i = 0; i < str->s_len; i++) {
|
||||
@@ -612,7 +650,10 @@ static fx_status string_trim(struct fx_string_p *str)
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_cstr_ansi(
|
||||
struct fx_string_p *dest, const char *src, size_t nr_bytes, size_t at)
|
||||
struct fx_string_p *dest,
|
||||
const char *src,
|
||||
size_t nr_bytes,
|
||||
size_t at)
|
||||
{
|
||||
if (at >= dest->s_len) {
|
||||
at = dest->s_len;
|
||||
@@ -637,7 +678,9 @@ static enum fx_status string_insert_cstr_ansi(
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_cstr_utf8(
|
||||
struct fx_string_p *dest, const char *src, size_t nr_bytes,
|
||||
struct fx_string_p *dest,
|
||||
const char *src,
|
||||
size_t nr_bytes,
|
||||
size_t codepoint_offset)
|
||||
{
|
||||
if (codepoint_offset >= dest->s_codepoints) {
|
||||
@@ -651,7 +694,11 @@ static enum fx_status string_insert_cstr_utf8(
|
||||
byte_offset = dest->s_len;
|
||||
} else {
|
||||
status = convert_codepoint_range_to_byte_range(
|
||||
dest, 0, codepoint_offset, NULL, &byte_offset);
|
||||
dest,
|
||||
0,
|
||||
codepoint_offset,
|
||||
NULL,
|
||||
&byte_offset);
|
||||
}
|
||||
|
||||
if (!FX_OK(status)) {
|
||||
@@ -678,7 +725,10 @@ static enum fx_status string_insert_cstr_utf8(
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_wstr_ansi(
|
||||
struct fx_string_p *dest, const fx_wchar *src, size_t nr_codepoints, size_t at)
|
||||
struct fx_string_p *dest,
|
||||
const fx_wchar *src,
|
||||
size_t nr_codepoints,
|
||||
size_t at)
|
||||
{
|
||||
if (at >= dest->s_len) {
|
||||
at = dest->s_len;
|
||||
@@ -723,7 +773,9 @@ static enum fx_status string_insert_wstr_ansi(
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_wstr_utf8(
|
||||
struct fx_string_p *dest, const fx_wchar *src, size_t nr_codepoints,
|
||||
struct fx_string_p *dest,
|
||||
const fx_wchar *src,
|
||||
size_t nr_codepoints,
|
||||
size_t codepoint_offset)
|
||||
{
|
||||
if (codepoint_offset >= dest->s_codepoints) {
|
||||
@@ -748,7 +800,11 @@ static enum fx_status string_insert_wstr_utf8(
|
||||
move_offset = dest->s_len;
|
||||
} else {
|
||||
status = convert_codepoint_range_to_byte_range(
|
||||
dest, 0, codepoint_offset, NULL, &move_offset);
|
||||
dest,
|
||||
0,
|
||||
codepoint_offset,
|
||||
NULL,
|
||||
&move_offset);
|
||||
}
|
||||
|
||||
if (!FX_OK(status)) {
|
||||
@@ -783,7 +839,10 @@ static enum fx_status string_insert_wstr_utf8(
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_cstr(
|
||||
struct fx_string_p *dest, const char *src, size_t nr_bytes, size_t at)
|
||||
struct fx_string_p *dest,
|
||||
const char *src,
|
||||
size_t nr_bytes,
|
||||
size_t at)
|
||||
{
|
||||
if (dest->s_len == dest->s_codepoints) {
|
||||
return string_insert_cstr_ansi(dest, src, nr_bytes, at);
|
||||
@@ -793,7 +852,10 @@ static enum fx_status string_insert_cstr(
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_wstr(
|
||||
struct fx_string_p *dest, const fx_wchar *src, size_t nr_codepoints, size_t at)
|
||||
struct fx_string_p *dest,
|
||||
const fx_wchar *src,
|
||||
size_t nr_codepoints,
|
||||
size_t at)
|
||||
{
|
||||
if (dest->s_len == dest->s_codepoints) {
|
||||
return string_insert_wstr_ansi(dest, src, nr_codepoints, at);
|
||||
@@ -803,25 +865,36 @@ static enum fx_status string_insert_wstr(
|
||||
}
|
||||
|
||||
static enum fx_status string_insertf(
|
||||
struct fx_string_p *dest, size_t at, const char *format, va_list arg)
|
||||
struct fx_string_p *dest,
|
||||
size_t at,
|
||||
const char *format,
|
||||
va_list arg)
|
||||
{
|
||||
char buf[1024];
|
||||
size_t len = vsnprintf(buf, sizeof buf, format, arg);
|
||||
return string_insert_cstr(dest, buf, len, at);
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_c(struct fx_string_p *dest, char c, size_t at)
|
||||
static enum fx_status string_insert_c(
|
||||
struct fx_string_p *dest,
|
||||
char c,
|
||||
size_t at)
|
||||
{
|
||||
return string_insert_cstr(dest, &c, 1, at);
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_wc(struct fx_string_p *dest, fx_wchar c, size_t at)
|
||||
static enum fx_status string_insert_wc(
|
||||
struct fx_string_p *dest,
|
||||
fx_wchar c,
|
||||
size_t at)
|
||||
{
|
||||
return string_insert_wstr(dest, &c, 1, at);
|
||||
}
|
||||
|
||||
static enum fx_status string_insert_s(
|
||||
struct fx_string_p *dest, const struct fx_string_p *src, size_t at)
|
||||
struct fx_string_p *dest,
|
||||
const struct fx_string_p *src,
|
||||
size_t at)
|
||||
{
|
||||
return string_insert_cstr(dest, string_ptr(src), src->s_len, at);
|
||||
}
|
||||
@@ -858,7 +931,9 @@ static bool has_prefix(const char *s, const char *prefix, size_t *prefix_len)
|
||||
}
|
||||
|
||||
static bool has_prefixes(
|
||||
const char *s, const char **prefixes, size_t nr_prefixes,
|
||||
const char *s,
|
||||
const char **prefixes,
|
||||
size_t nr_prefixes,
|
||||
size_t *selected_prefix_len)
|
||||
{
|
||||
for (size_t i = 0; i < nr_prefixes; i++) {
|
||||
@@ -929,14 +1004,16 @@ static enum fx_status find_next_token(struct fx_string_iterator_p *it)
|
||||
}
|
||||
|
||||
it->_ds = offset + prefix_len;
|
||||
it->string_value = fx_string_ptr(it->_tmp);
|
||||
it->string_value = fx_string_get_cstr(it->_tmp);
|
||||
it->string_length = it->_tmp_p->s_len;
|
||||
it->string_codepoints = it->_tmp_p->s_codepoints;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_iterator *string_tokenise(
|
||||
struct fx_string_p *str, const char *delims[], size_t nr_delims,
|
||||
struct fx_string_p *str,
|
||||
const char *delims[],
|
||||
size_t nr_delims,
|
||||
fx_string_tokenise_flags flags)
|
||||
{
|
||||
if (!nr_delims) {
|
||||
@@ -970,7 +1047,9 @@ static fx_iterator *string_tokenise(
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
static size_t string_get_size(const struct fx_string_p *str, fx_strlen_flags flags)
|
||||
static size_t string_get_size(
|
||||
const struct fx_string_p *str,
|
||||
fx_strlen_flags flags)
|
||||
{
|
||||
switch (flags) {
|
||||
case FX_STRLEN_NORMAL:
|
||||
@@ -987,7 +1066,9 @@ static size_t string_get_capacity(const struct fx_string_p *str)
|
||||
return str->s_max;
|
||||
}
|
||||
|
||||
static bool string_compare(const struct fx_string_p *a, const struct fx_string_p *b)
|
||||
static bool string_compare(
|
||||
const struct fx_string_p *a,
|
||||
const struct fx_string_p *b)
|
||||
{
|
||||
if (a->s_len != b->s_len) {
|
||||
return false;
|
||||
@@ -1041,7 +1122,10 @@ static void string_pop_back(struct fx_string_p *str)
|
||||
str->s_len--;
|
||||
}
|
||||
|
||||
static fx_string *string_substr(const struct fx_string_p *str, size_t start, size_t len)
|
||||
static fx_string *string_substr(
|
||||
const struct fx_string_p *str,
|
||||
size_t start,
|
||||
size_t len)
|
||||
{
|
||||
if (start > string_get_size(str, FX_STRLEN_NORMAL)) {
|
||||
return NULL;
|
||||
@@ -1052,7 +1136,8 @@ static fx_string *string_substr(const struct fx_string_p *str, size_t start, siz
|
||||
}
|
||||
|
||||
fx_string *newstr = fx_string_create();
|
||||
struct fx_string_p *newstr_p = fx_object_get_private(newstr, FX_TYPE_STRING);
|
||||
struct fx_string_p *newstr_p
|
||||
= fx_object_get_private(newstr, FX_TYPE_STRING);
|
||||
string_reserve(newstr_p, len);
|
||||
|
||||
const char *src = string_ptr(str) + start;
|
||||
@@ -1146,32 +1231,57 @@ fx_status fx_string_reserve(fx_string *str, size_t capacity)
|
||||
}
|
||||
|
||||
fx_status fx_string_replace(
|
||||
fx_string *str, size_t start, size_t length, const char *new_data)
|
||||
fx_string *str,
|
||||
size_t start,
|
||||
size_t length,
|
||||
const char *new_data)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING, string_replace, str, start, length, new_data);
|
||||
FX_TYPE_STRING,
|
||||
string_replace,
|
||||
str,
|
||||
start,
|
||||
length,
|
||||
new_data);
|
||||
}
|
||||
|
||||
fx_status fx_string_replace_all(fx_string *str, const char *new_data)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_STRING, string_replace_all, str, new_data);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING,
|
||||
string_replace_all,
|
||||
str,
|
||||
new_data);
|
||||
}
|
||||
|
||||
fx_status fx_string_replace_all_with_stringstream(
|
||||
fx_string *str, const fx_stringstream *new_data)
|
||||
fx_string *str,
|
||||
const fx_stringstream *new_data)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING, string_replace_all_with_stringstream, str, new_data);
|
||||
FX_TYPE_STRING,
|
||||
string_replace_all_with_stringstream,
|
||||
str,
|
||||
new_data);
|
||||
}
|
||||
|
||||
enum fx_status fx_string_remove(fx_string *str, size_t start, size_t length)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_STRING, string_remove, str, start, length);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING,
|
||||
string_remove,
|
||||
str,
|
||||
start,
|
||||
length);
|
||||
}
|
||||
|
||||
fx_status fx_string_transform(fx_string *str, int (*transformer)(int))
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_STRING, string_transform, str, transformer);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING,
|
||||
string_transform,
|
||||
str,
|
||||
transformer);
|
||||
}
|
||||
|
||||
fx_status fx_string_trim(fx_string *str)
|
||||
@@ -1189,29 +1299,46 @@ enum fx_status fx_string_insert_wc(fx_string *dest, fx_wchar c, size_t at)
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_STRING, string_insert_wc, dest, c, at);
|
||||
}
|
||||
|
||||
enum fx_status fx_string_insert_s(fx_string *dest, const fx_string *src, size_t at)
|
||||
enum fx_status fx_string_insert_s(
|
||||
fx_string *dest,
|
||||
const fx_string *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p = fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
const struct fx_string_p *src_p = fx_object_get_private(src, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
const struct fx_string_p *src_p
|
||||
= fx_object_get_private(src, FX_TYPE_STRING);
|
||||
return string_insert_s(dest_p, src_p, at);
|
||||
}
|
||||
|
||||
enum fx_status fx_string_insert_cstr(fx_string *dest, const char *src, size_t at)
|
||||
enum fx_status fx_string_insert_cstr(
|
||||
fx_string *dest,
|
||||
const char *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p = fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
return string_insert_cstr(dest_p, src, strlen(src), at);
|
||||
}
|
||||
|
||||
enum fx_status fx_string_insert_wstr(fx_string *dest, const fx_wchar *src, size_t at)
|
||||
enum fx_status fx_string_insert_wstr(
|
||||
fx_string *dest,
|
||||
const fx_wchar *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p = fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
return string_insert_wstr(dest_p, src, fx_wstrlen(src), at);
|
||||
}
|
||||
|
||||
enum fx_status fx_string_insert_cstrf(
|
||||
fx_string *dest, size_t at, const char *format, ...)
|
||||
fx_string *dest,
|
||||
size_t at,
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
struct fx_string_p *dest_p = fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1222,15 +1349,24 @@ enum fx_status fx_string_insert_cstrf(
|
||||
}
|
||||
|
||||
enum fx_status fx_string_insert_cstrn(
|
||||
fx_string *dest, const char *src, size_t len, size_t at)
|
||||
fx_string *dest,
|
||||
const char *src,
|
||||
size_t len,
|
||||
size_t at)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING, string_insert_cstr, dest, src, len, at);
|
||||
FX_TYPE_STRING,
|
||||
string_insert_cstr,
|
||||
dest,
|
||||
src,
|
||||
len,
|
||||
at);
|
||||
}
|
||||
|
||||
enum fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...)
|
||||
{
|
||||
struct fx_string_p *dest_p = fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1242,7 +1378,8 @@ enum fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...)
|
||||
|
||||
enum fx_status fx_string_prepend_cstrf(fx_string *dest, const char *format, ...)
|
||||
{
|
||||
struct fx_string_p *dest_p = fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1258,11 +1395,18 @@ void fx_string_clear(fx_string *str)
|
||||
}
|
||||
|
||||
fx_iterator *fx_string_tokenise(
|
||||
fx_string *str, const char *delims[], size_t nr_delims,
|
||||
fx_string *str,
|
||||
const char *delims[],
|
||||
size_t nr_delims,
|
||||
fx_string_tokenise_flags flags)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING, string_tokenise, str, delims, nr_delims, flags);
|
||||
FX_TYPE_STRING,
|
||||
string_tokenise,
|
||||
str,
|
||||
delims,
|
||||
nr_delims,
|
||||
flags);
|
||||
}
|
||||
|
||||
size_t fx_string_get_size(const fx_string *str, fx_strlen_flags flags)
|
||||
@@ -1297,14 +1441,19 @@ void fx_string_pop_back(fx_string *str)
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRING, string_pop_back, str);
|
||||
}
|
||||
|
||||
const char *fx_string_ptr(const fx_string *str)
|
||||
const char *fx_string_get_cstr(const fx_string *str)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_STRING, string_ptr, str);
|
||||
}
|
||||
|
||||
fx_string *fx_string_substr(const fx_string *str, size_t start, size_t len)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_STRING, string_substr, str, start, len);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_STRING,
|
||||
string_substr,
|
||||
str,
|
||||
start,
|
||||
len);
|
||||
}
|
||||
|
||||
uint64_t fx_string_hash(const fx_string *str)
|
||||
@@ -1495,12 +1644,14 @@ static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
}
|
||||
}
|
||||
|
||||
static fx_iterator_value chars_iterator_get_value(struct fx_string_iterator_p *it)
|
||||
static fx_iterator_value chars_iterator_get_value(
|
||||
struct fx_string_iterator_p *it)
|
||||
{
|
||||
return FX_ITERATOR_VALUE_INT(it->char_value);
|
||||
}
|
||||
|
||||
static fx_iterator_value tokens_iterator_get_value(struct fx_string_iterator_p *it)
|
||||
static fx_iterator_value tokens_iterator_get_value(
|
||||
struct fx_string_iterator_p *it)
|
||||
{
|
||||
return FX_ITERATOR_VALUE_CPTR(it->string_value);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <ctype.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/ds/uuid.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -15,31 +15,43 @@ struct fx_uuid_p {
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
static fx_status uuid_to_cstr(
|
||||
const struct fx_uuid_p *uuid, char out[FX_UUID_STRING_MAX])
|
||||
const struct fx_uuid_p *uuid,
|
||||
char out[FX_UUID_STRING_MAX])
|
||||
{
|
||||
snprintf(
|
||||
out, FX_UUID_STRING_MAX,
|
||||
out,
|
||||
FX_UUID_STRING_MAX,
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%"
|
||||
"02x%02x",
|
||||
uuid->uuid_bytes.uuid_bytes[0], uuid->uuid_bytes.uuid_bytes[1],
|
||||
uuid->uuid_bytes.uuid_bytes[2], uuid->uuid_bytes.uuid_bytes[3],
|
||||
uuid->uuid_bytes.uuid_bytes[4], uuid->uuid_bytes.uuid_bytes[5],
|
||||
uuid->uuid_bytes.uuid_bytes[6], uuid->uuid_bytes.uuid_bytes[7],
|
||||
uuid->uuid_bytes.uuid_bytes[8], uuid->uuid_bytes.uuid_bytes[9],
|
||||
uuid->uuid_bytes.uuid_bytes[10], uuid->uuid_bytes.uuid_bytes[11],
|
||||
uuid->uuid_bytes.uuid_bytes[12], uuid->uuid_bytes.uuid_bytes[13],
|
||||
uuid->uuid_bytes.uuid_bytes[14], uuid->uuid_bytes.uuid_bytes[15]);
|
||||
uuid->uuid_bytes.uuid_bytes[0],
|
||||
uuid->uuid_bytes.uuid_bytes[1],
|
||||
uuid->uuid_bytes.uuid_bytes[2],
|
||||
uuid->uuid_bytes.uuid_bytes[3],
|
||||
uuid->uuid_bytes.uuid_bytes[4],
|
||||
uuid->uuid_bytes.uuid_bytes[5],
|
||||
uuid->uuid_bytes.uuid_bytes[6],
|
||||
uuid->uuid_bytes.uuid_bytes[7],
|
||||
uuid->uuid_bytes.uuid_bytes[8],
|
||||
uuid->uuid_bytes.uuid_bytes[9],
|
||||
uuid->uuid_bytes.uuid_bytes[10],
|
||||
uuid->uuid_bytes.uuid_bytes[11],
|
||||
uuid->uuid_bytes.uuid_bytes[12],
|
||||
uuid->uuid_bytes.uuid_bytes[13],
|
||||
uuid->uuid_bytes.uuid_bytes[14],
|
||||
uuid->uuid_bytes.uuid_bytes[15]);
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static void uuid_get_bytes(
|
||||
const struct fx_uuid_p *uuid, unsigned char bytes[FX_UUID_NBYTES])
|
||||
const struct fx_uuid_p *uuid,
|
||||
unsigned char bytes[FX_UUID_NBYTES])
|
||||
{
|
||||
memcpy(bytes, uuid->uuid_bytes.uuid_bytes, FX_UUID_NBYTES);
|
||||
}
|
||||
|
||||
static void uuid_get_uuid_bytes(
|
||||
const struct fx_uuid_p *uuid, union fx_uuid_bytes *bytes)
|
||||
const struct fx_uuid_p *uuid,
|
||||
union fx_uuid_bytes *bytes)
|
||||
{
|
||||
memcpy(bytes, &uuid->uuid_bytes, sizeof *bytes);
|
||||
}
|
||||
@@ -52,11 +64,22 @@ static union fx_uuid_bytes *uuid_ptr(struct fx_uuid_p *uuid)
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_uuid *fx_uuid_create_from_bytes(
|
||||
unsigned char u00, unsigned char u01, unsigned char u02,
|
||||
unsigned char u03, unsigned char u04, unsigned char u05,
|
||||
unsigned char u06, unsigned char u07, unsigned char u08,
|
||||
unsigned char u09, unsigned char u10, unsigned char u11,
|
||||
unsigned char u12, unsigned char u13, unsigned char u14, unsigned char u15)
|
||||
unsigned char u00,
|
||||
unsigned char u01,
|
||||
unsigned char u02,
|
||||
unsigned char u03,
|
||||
unsigned char u04,
|
||||
unsigned char u05,
|
||||
unsigned char u06,
|
||||
unsigned char u07,
|
||||
unsigned char u08,
|
||||
unsigned char u09,
|
||||
unsigned char u10,
|
||||
unsigned char u11,
|
||||
unsigned char u12,
|
||||
unsigned char u13,
|
||||
unsigned char u14,
|
||||
unsigned char u15)
|
||||
{
|
||||
fx_uuid *uuid = fx_uuid_create();
|
||||
if (!uuid) {
|
||||
@@ -171,7 +194,11 @@ void fx_uuid_get_bytes(const fx_uuid *uuid, unsigned char bytes[FX_UUID_NBYTES])
|
||||
|
||||
void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, union fx_uuid_bytes *bytes)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_UUID, uuid_get_uuid_bytes, uuid, bytes);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_UUID,
|
||||
uuid_get_uuid_bytes,
|
||||
uuid,
|
||||
bytes);
|
||||
}
|
||||
|
||||
union fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid)
|
||||
@@ -188,7 +215,7 @@ fx_uuid *fx_uuid_create_from_uuid_bytes(const union fx_uuid_bytes *bytes)
|
||||
|
||||
fx_uuid *fx_uuid_create_from_string(const fx_string *string)
|
||||
{
|
||||
return fx_uuid_create_from_cstr(fx_string_ptr(string));
|
||||
return fx_uuid_create_from_cstr(fx_string_get_cstr(string));
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
@@ -207,7 +234,7 @@ static void uuid_to_string(const fx_object *uuid, fx_stream *out)
|
||||
{
|
||||
char str[FX_UUID_STRING_MAX];
|
||||
fx_uuid_to_cstr(uuid, str);
|
||||
fx_stream_write_string(out, str, NULL);
|
||||
fx_stream_write_cstr(out, str, NULL);
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
@@ -379,7 +379,7 @@ void path_to_string(const fx_object *obj, fx_stream *out)
|
||||
{
|
||||
struct fx_path_p *path = fx_object_get_private(obj, FX_TYPE_PATH);
|
||||
|
||||
fx_stream_write_string(out, fx_string_ptr(path->p_pathstr), NULL);
|
||||
fx_stream_write_cstr(out, fx_string_ptr(path->p_pathstr), NULL);
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
+10
-6
@@ -3,18 +3,22 @@
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static enum fx_status bitcode_serialise(
|
||||
fx_serial_ctx *serial, fx_object *src, fx_stream *dest,
|
||||
static struct fx_error *bitcode_serialise(
|
||||
fx_serial_ctx *serial,
|
||||
fx_object *src,
|
||||
fx_stream *dest,
|
||||
enum fx_serial_flags flags)
|
||||
{
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
return FX_RESULT_ERR(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
static enum fx_status bitcode_deserialise(
|
||||
fx_serial_ctx *serial, fx_stream *src, fx_object **dest,
|
||||
static struct fx_error *bitcode_deserialise(
|
||||
fx_serial_ctx *serial,
|
||||
fx_stream *src,
|
||||
fx_object **dest,
|
||||
enum fx_serial_flags flags)
|
||||
{
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
return FX_RESULT_ERR(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
static void bitcode_serial_ctx_init(fx_object *obj, void *priv)
|
||||
|
||||
+30
-10
@@ -10,14 +10,16 @@
|
||||
|
||||
static void serial_ctx_init(fx_object *obj, void *priv)
|
||||
{
|
||||
fx_serial_ctx_data *data = fx_object_get_protected(obj, FX_TYPE_SERIAL_CTX);
|
||||
fx_serial_ctx_data *data
|
||||
= fx_object_get_protected(obj, FX_TYPE_SERIAL_CTX);
|
||||
|
||||
data->ctx_streambuf = fx_stream_buffer_create_dynamic(2048);
|
||||
}
|
||||
|
||||
static void serial_ctx_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
fx_serial_ctx_data *data = fx_object_get_protected(obj, FX_TYPE_SERIAL_CTX);
|
||||
fx_serial_ctx_data *data
|
||||
= fx_object_get_protected(obj, FX_TYPE_SERIAL_CTX);
|
||||
|
||||
fx_stream_buffer_unref(data->ctx_streambuf);
|
||||
}
|
||||
@@ -40,18 +42,36 @@ FX_TYPE_DEFINITION_END(fx_serial_ctx)
|
||||
|
||||
/*** ITERATOR FUNCTIONS *******************************************************/
|
||||
|
||||
enum fx_status fx_serial_ctx_serialise(
|
||||
fx_serial_ctx *ctx, fx_object *src, fx_stream *dest, enum fx_serial_flags flags)
|
||||
fx_result fx_serial_ctx_serialise(
|
||||
fx_serial_ctx *ctx,
|
||||
fx_object *src,
|
||||
fx_stream *dest,
|
||||
enum fx_serial_flags flags)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL(
|
||||
fx_serial_ctx, FX_TYPE_SERIAL_CTX, FX_ERR_NOT_SUPPORTED,
|
||||
s_serialise, ctx, src, dest, flags);
|
||||
fx_serial_ctx,
|
||||
FX_TYPE_SERIAL_CTX,
|
||||
FX_RESULT_ERR(NOT_SUPPORTED),
|
||||
s_serialise,
|
||||
ctx,
|
||||
src,
|
||||
dest,
|
||||
flags);
|
||||
}
|
||||
|
||||
enum fx_status fx_serial_ctx_deserialise(
|
||||
fx_serial_ctx *ctx, fx_stream *src, fx_object **dest, enum fx_serial_flags flags)
|
||||
fx_result fx_serial_ctx_deserialise(
|
||||
fx_serial_ctx *ctx,
|
||||
fx_stream *src,
|
||||
fx_object **dest,
|
||||
enum fx_serial_flags flags)
|
||||
{
|
||||
FX_CLASS_DISPATCH_VIRTUAL(
|
||||
fx_serial_ctx, FX_TYPE_SERIAL_CTX, FX_ERR_NOT_SUPPORTED,
|
||||
s_deserialise, ctx, src, dest, flags);
|
||||
fx_serial_ctx,
|
||||
FX_TYPE_SERIAL_CTX,
|
||||
FX_RESULT_ERR(NOT_SUPPORTED),
|
||||
s_deserialise,
|
||||
ctx,
|
||||
src,
|
||||
dest,
|
||||
flags);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,16 @@ typedef enum fx_serial_flags {
|
||||
FX_DECLARE_TYPE(fx_serial_ctx);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_serial_ctx)
|
||||
fx_status (*s_serialise)(
|
||||
fx_serial_ctx *, fx_object *, fx_stream *, fx_serial_flags);
|
||||
fx_status (*s_deserialise)(
|
||||
fx_serial_ctx *, fx_stream *, fx_object **, fx_serial_flags);
|
||||
fx_result (*s_serialise)(
|
||||
fx_serial_ctx *,
|
||||
fx_object *,
|
||||
fx_stream *,
|
||||
fx_serial_flags);
|
||||
fx_result (*s_deserialise)(
|
||||
fx_serial_ctx *,
|
||||
fx_stream *,
|
||||
fx_object **,
|
||||
fx_serial_flags);
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_serial_ctx)
|
||||
|
||||
typedef struct fx_serial_ctx_data {
|
||||
@@ -31,11 +37,17 @@ typedef struct fx_serial_ctx_data {
|
||||
|
||||
FX_API fx_type fx_serial_ctx_get_type(void);
|
||||
|
||||
FX_API fx_status fx_serial_ctx_serialise(
|
||||
fx_serial_ctx *ctx, fx_object *src, fx_stream *dest, fx_serial_flags flags);
|
||||
FX_API fx_result fx_serial_ctx_serialise(
|
||||
fx_serial_ctx *ctx,
|
||||
fx_object *src,
|
||||
fx_stream *dest,
|
||||
fx_serial_flags flags);
|
||||
|
||||
FX_API fx_status fx_serial_ctx_deserialise(
|
||||
fx_serial_ctx *ctx, fx_stream *src, fx_object **dest, fx_serial_flags flags);
|
||||
FX_API fx_result fx_serial_ctx_deserialise(
|
||||
fx_serial_ctx *ctx,
|
||||
fx_stream *src,
|
||||
fx_object **dest,
|
||||
fx_serial_flags flags);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
|
||||
+230
-189
File diff suppressed because it is too large
Load Diff
+8
-4
@@ -19,18 +19,18 @@ static void get_error_id(
|
||||
fx_stringstream *id = fx_stringstream_create_with_buffer(out, max);
|
||||
|
||||
if (vendor_name) {
|
||||
fx_stream_write_string(id, vendor_name, NULL);
|
||||
fx_stream_write_cstr(id, vendor_name, NULL);
|
||||
}
|
||||
|
||||
if (error_name) {
|
||||
if (vendor_name) {
|
||||
fx_stream_write_string(id, ".", NULL);
|
||||
fx_stream_write_cstr(id, ".", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_string(id, error_name, NULL);
|
||||
fx_stream_write_cstr(id, error_name, NULL);
|
||||
} else {
|
||||
if (vendor_name) {
|
||||
fx_stream_write_string(id, "#", NULL);
|
||||
fx_stream_write_cstr(id, "#", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_fmt(id, NULL, "%ld", code);
|
||||
@@ -125,6 +125,10 @@ static void print_content(
|
||||
const struct fx_error_template_parameter *params, size_t nr_params,
|
||||
const char *s)
|
||||
{
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
|
||||
char modifier = 0;
|
||||
char buf[128];
|
||||
size_t buf_len = 0;
|
||||
|
||||
@@ -158,7 +158,7 @@ void test_stringstream_1(CuTest *tc)
|
||||
char buf[1024];
|
||||
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
fx_stream_write_string(s, "hello", NULL);
|
||||
fx_stream_write_cstr(s, "hello", NULL);
|
||||
fx_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
|
||||
|
||||
char *end = fx_stringstream_steal(s);
|
||||
@@ -172,14 +172,14 @@ void test_stringstream_2(CuTest *tc)
|
||||
char buf[1024];
|
||||
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
fx_stream_write_string(s, "{\n", NULL);
|
||||
fx_stream_write_cstr(s, "{\n", NULL);
|
||||
fx_stream_push_indent(s, 1);
|
||||
|
||||
fx_stream_write_string(s, "a = 32,\n", NULL);
|
||||
fx_stream_write_string(s, "b = 64\n", NULL);
|
||||
fx_stream_write_cstr(s, "a = 32,\n", NULL);
|
||||
fx_stream_write_cstr(s, "b = 64\n", NULL);
|
||||
|
||||
fx_stream_pop_indent(s);
|
||||
fx_stream_write_string(s, "}", NULL);
|
||||
fx_stream_write_cstr(s, "}", NULL);
|
||||
|
||||
char *str = fx_stringstream_steal(s);
|
||||
fx_stringstream_unref(s);
|
||||
|
||||
+3
-3
@@ -29,9 +29,9 @@ int main(void)
|
||||
fx_string_unref(str);
|
||||
|
||||
fx_stringstream *strv = fx_stringstream_create();
|
||||
fx_stream_write_string(strv, "Hello", NULL);
|
||||
fx_stream_write_string(strv, ", world", NULL);
|
||||
fx_stream_write_string(strv, "!", NULL);
|
||||
fx_stream_write_cstr(strv, "Hello", NULL);
|
||||
fx_stream_write_cstr(strv, ", world", NULL);
|
||||
fx_stream_write_cstr(strv, "!", NULL);
|
||||
|
||||
char *s = fx_stringstream_steal(strv);
|
||||
fx_stringstream_unref(strv);
|
||||
|
||||
+30
-30
@@ -10,7 +10,7 @@ void write_tagged_value(fx_object *data);
|
||||
|
||||
void write_raw_string(const fx_string *data)
|
||||
{
|
||||
fx_stream_write_string(fx_stdout, "\"", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "\"", NULL);
|
||||
|
||||
const fx_iterator *it = fx_iterator_cbegin(data);
|
||||
fx_foreach_c(fx_wchar, c, it)
|
||||
@@ -30,52 +30,52 @@ void write_raw_string(const fx_string *data)
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
|
||||
fx_stream_write_string(fx_stdout, "\"", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "\"", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_string(fx_string *data)
|
||||
{
|
||||
fx_stream_write_string(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "{ \"type\": \"string\", \"value\": ", NULL);
|
||||
|
||||
write_raw_string(data);
|
||||
|
||||
fx_stream_write_string(fx_stdout, " }", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, " }", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_integer(fx_number *data)
|
||||
{
|
||||
fx_stream_write_string(
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout, "{ \"type\": \"integer\", \"value\": \"", NULL);
|
||||
|
||||
if (fx_number_is_inf_positive(data)) {
|
||||
fx_stream_write_string(fx_stdout, "inf", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "inf", NULL);
|
||||
} else if (fx_number_is_inf_negative(data)) {
|
||||
fx_stream_write_string(fx_stdout, "-inf", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "-inf", NULL);
|
||||
} else if (fx_number_is_nan_positive(data)) {
|
||||
fx_stream_write_string(fx_stdout, "nan", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "nan", NULL);
|
||||
} else if (fx_number_is_nan_negative(data)) {
|
||||
fx_stream_write_string(fx_stdout, "-nan", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "-nan", NULL);
|
||||
} else {
|
||||
fx_stream_write_fmt(
|
||||
fx_stdout, NULL, "%lld", fx_number_get_longlong(data), NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_string(fx_stdout, "\" }", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_float(fx_number *data)
|
||||
{
|
||||
fx_stream_write_string(
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout, "{ \"type\": \"float\", \"value\": \"", NULL);
|
||||
|
||||
if (fx_number_is_inf_positive(data)) {
|
||||
fx_stream_write_string(fx_stdout, "inf", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "inf", NULL);
|
||||
} else if (fx_number_is_inf_negative(data)) {
|
||||
fx_stream_write_string(fx_stdout, "-inf", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "-inf", NULL);
|
||||
} else if (fx_number_is_nan_positive(data)) {
|
||||
fx_stream_write_string(fx_stdout, "nan", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "nan", NULL);
|
||||
} else if (fx_number_is_nan_negative(data)) {
|
||||
fx_stream_write_string(fx_stdout, "-nan", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "-nan", NULL);
|
||||
} else {
|
||||
double v = fx_number_get_double(data);
|
||||
if ((v <= 0.00000001 && v > 0) || (v >= -0.00000001 && v < 0)
|
||||
@@ -86,7 +86,7 @@ void write_tagged_float(fx_number *data)
|
||||
}
|
||||
}
|
||||
|
||||
fx_stream_write_string(fx_stdout, "\" }", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_bool(fx_number *data)
|
||||
@@ -103,33 +103,33 @@ void write_tagged_datetime(fx_datetime *data)
|
||||
bool has_time = fx_datetime_has_time(data);
|
||||
bool localtime = fx_datetime_is_localtime(data);
|
||||
|
||||
fx_stream_write_string(fx_stdout, "{ \"type\": \"", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "{ \"type\": \"", NULL);
|
||||
|
||||
if (has_date && has_time) {
|
||||
fx_stream_write_string(
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout, localtime ? "datetime-local" : "datetime", NULL);
|
||||
} else if (has_date) {
|
||||
fx_stream_write_string(
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout, localtime ? "date-local" : "date", NULL);
|
||||
} else if (has_time) {
|
||||
fx_stream_write_string(
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout, localtime ? "time-local" : "time", NULL);
|
||||
}
|
||||
|
||||
fx_stream_write_string(fx_stdout, "\", \"value\": \"", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "\", \"value\": \"", NULL);
|
||||
|
||||
fx_string *new_data = fx_string_create();
|
||||
fx_datetime_to_string(data, FX_DATETIME_FORMAT_RFC3339, new_data);
|
||||
fx_stream_write_string(fx_stdout, fx_string_ptr(new_data), NULL);
|
||||
fx_stream_write_cstr(fx_stdout, fx_string_ptr(new_data), NULL);
|
||||
|
||||
fx_stream_write_string(fx_stdout, "\" }", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
|
||||
|
||||
fx_string_unref(new_data);
|
||||
}
|
||||
|
||||
void write_tagged_dict(fx_dict *data)
|
||||
{
|
||||
fx_stream_write_string(fx_stdout, "{ ", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "{ ", NULL);
|
||||
|
||||
int i = 0;
|
||||
|
||||
@@ -137,35 +137,35 @@ void write_tagged_dict(fx_dict *data)
|
||||
fx_foreach(fx_dict_item *, item, it)
|
||||
{
|
||||
if (i++ > 0) {
|
||||
fx_stream_write_string(fx_stdout, ", ", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, ", ", NULL);
|
||||
}
|
||||
|
||||
write_raw_string(item->key);
|
||||
fx_stream_write_string(fx_stdout, ": ", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, ": ", NULL);
|
||||
write_tagged_value(item->value);
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
|
||||
fx_stream_write_string(fx_stdout, " }", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, " }", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_array(fx_array *data)
|
||||
{
|
||||
fx_stream_write_string(fx_stdout, "[ ", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, "[ ", NULL);
|
||||
|
||||
int i = 0;
|
||||
fx_iterator *it = fx_iterator_begin(data);
|
||||
fx_foreach(fx_object *, obj, it)
|
||||
{
|
||||
if (i++ > 0) {
|
||||
fx_stream_write_string(fx_stdout, ", ", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, ", ", NULL);
|
||||
}
|
||||
|
||||
write_tagged_value(obj);
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
|
||||
fx_stream_write_string(fx_stdout, " ]", NULL);
|
||||
fx_stream_write_cstr(fx_stdout, " ]", NULL);
|
||||
}
|
||||
|
||||
void write_tagged_value(fx_object *data)
|
||||
|
||||
Reference in New Issue
Block a user