1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

janet_formatb -> janet_formatbv, new janet_formatb

The old function was not very useable. In the likely
case that there is no external code using this
(not well documented/janet_formatc is more convenient), we
can change this.
This commit is contained in:
Calvin Rose 2020-04-14 07:33:33 -05:00
parent a09112404d
commit 71882475d6
6 changed files with 13 additions and 11 deletions

View File

@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased - ??? ## Unreleased - ???
- Change C api's `janet_formatb` -> `janet_formatbv`.
- Add C `janet_formatb` to C api.
- Add `edefer` macro to core. - Add `edefer` macro to core.
- A struct/table literal/constructor with duplicate keys will use the last value given. - A struct/table literal/constructor with duplicate keys will use the last value given.
Previously, this was inconsistent between tables and structs, literals and constructor functions. Previously, this was inconsistent between tables and structs, literals and constructor functions.

View File

@ -54,7 +54,7 @@ void janet_panicf(const char *format, ...) {
while (format[len]) len++; while (format[len]) len++;
janet_buffer_init(&buffer, len); janet_buffer_init(&buffer, len);
va_start(args, format); va_start(args, format);
janet_formatb(&buffer, format, args); janet_formatbv(&buffer, format, args);
va_end(args); va_end(args);
ret = janet_string(buffer.data, buffer.count); ret = janet_string(buffer.data, buffer.count);
janet_buffer_deinit(&buffer); janet_buffer_deinit(&buffer);

View File

@ -502,7 +502,7 @@ void janet_dynprintf(const char *name, FILE *dflt_file, const char *format, ...)
int32_t len = 0; int32_t len = 0;
while (format[len]) len++; while (format[len]) len++;
janet_buffer_init(&buffer, len); janet_buffer_init(&buffer, len);
janet_formatb(&buffer, format, args); janet_formatbv(&buffer, format, args);
if (xtype == JANET_ABSTRACT) { if (xtype == JANET_ABSTRACT) {
void *abstract = janet_unwrap_abstract(x); void *abstract = janet_unwrap_abstract(x);
if (janet_abstract_type(abstract) != &janet_file_type) if (janet_abstract_type(abstract) != &janet_file_type)
@ -515,7 +515,7 @@ void janet_dynprintf(const char *name, FILE *dflt_file, const char *format, ...)
break; break;
} }
case JANET_BUFFER: case JANET_BUFFER:
janet_formatb(janet_unwrap_buffer(x), format, args); janet_formatbv(janet_unwrap_buffer(x), format, args);
break; break;
} }
va_end(args); va_end(args);

View File

@ -642,7 +642,7 @@ void janet_parser_eof(JanetParser *parser) {
if (parser->statecount > 1) { if (parser->statecount > 1) {
JanetParseState *s = parser->states + (parser->statecount - 1); JanetParseState *s = parser->states + (parser->statecount - 1);
JanetBuffer *buffer = janet_buffer(40); JanetBuffer *buffer = janet_buffer(40);
janet_buffer_push_cstring(buffer, "unexpected end of source: "); janet_buffer_push_cstring(buffer, "unexpected end of source, ");
if (s->flags & PFLAG_PARENS) { if (s->flags & PFLAG_PARENS) {
janet_buffer_push_u8(buffer, '('); janet_buffer_push_u8(buffer, '(');
} else if (s->flags & PFLAG_SQRBRACKETS) { } else if (s->flags & PFLAG_SQRBRACKETS) {
@ -657,7 +657,7 @@ void janet_parser_eof(JanetParser *parser) {
janet_buffer_push_u8(buffer, '`'); janet_buffer_push_u8(buffer, '`');
} }
} }
janet_formatbb(buffer, " opened at line %d, column %d", s->line, s->column); janet_formatb(buffer, " opened at line %d, column %d", s->line, s->column);
parser->error = (const char *) janet_string(buffer->data, buffer->count); parser->error = (const char *) janet_string(buffer->data, buffer->count);
parser->flag |= JANET_PARSER_GENERATED_ERROR; parser->flag |= JANET_PARSER_GENERATED_ERROR;
} }

View File

@ -728,7 +728,7 @@ static const char *scanformat(
return p; return p;
} }
void janet_formatb(JanetBuffer *b, const char *format, va_list args) { void janet_formatbv(JanetBuffer *b, const char *format, va_list args) {
const char *format_end = format + strlen(format); const char *format_end = format + strlen(format);
const char *c = format; const char *c = format;
int32_t startlen = b->count; int32_t startlen = b->count;
@ -853,7 +853,7 @@ const uint8_t *janet_formatc(const char *format, ...) {
va_start(args, format); va_start(args, format);
/* Run format */ /* Run format */
janet_formatb(&buffer, format, args); janet_formatbv(&buffer, format, args);
/* Iterate length */ /* Iterate length */
va_end(args); va_end(args);
@ -863,10 +863,10 @@ const uint8_t *janet_formatc(const char *format, ...) {
return ret; return ret;
} }
JanetBuffer *janet_formatbb(JanetBuffer *buffer, const char *format, ...) { JanetBuffer *janet_formatb(JanetBuffer *buffer, const char *format, ...) {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
janet_formatb(buffer, format, args); janet_formatbv(buffer, format, args);
va_end(args); va_end(args);
return buffer; return buffer;
} }

View File

@ -1238,8 +1238,8 @@ JANET_API void janet_description_b(JanetBuffer *buffer, Janet x);
#define janet_cstringv(cstr) janet_wrap_string(janet_cstring(cstr)) #define janet_cstringv(cstr) janet_wrap_string(janet_cstring(cstr))
#define janet_stringv(str, len) janet_wrap_string(janet_string((str), (len))) #define janet_stringv(str, len) janet_wrap_string(janet_string((str), (len)))
JANET_API JanetString janet_formatc(const char *format, ...); JANET_API JanetString janet_formatc(const char *format, ...);
JANET_API void janet_formatb(JanetBuffer *bufp, const char *format, va_list args); JANET_API JanetBuffer *janet_formatb(JanetBuffer *bufp, const char *format, ...);
JANET_API JanetBuffer *janet_formatbb(JanetBuffer *bufp, const char *format, ...); JANET_API void janet_formatbv(JanetBuffer *bufp, const char *format, va_list args);
/* Symbol functions */ /* Symbol functions */
JANET_API JanetSymbol janet_symbol(const uint8_t *str, int32_t len); JANET_API JanetSymbol janet_symbol(const uint8_t *str, int32_t len);