aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/main.c4
-rw-r--r--go/typdown.go2
-rw-r--r--include/typdown.h4
-rw-r--r--src/root.zig21
4 files changed, 13 insertions, 18 deletions
diff --git a/examples/main.c b/examples/main.c
index 11534b3..5dd3a4b 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -5,11 +5,11 @@
void foo(char *v) {
uint8_t code;
- char *res = parse(v, &code);
+ char *res = typdown_parse(v, &code);
if (code == 0) {
printf("%s\n", res);
free(res);
- } else printf("cannot parse '%s', error: %s (%d)\n", v, getErrorString(code), code);
+ } else printf("cannot parse '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code);
}
int main() {
diff --git a/go/typdown.go b/go/typdown.go
index 1125ecb..386b779 100644
--- a/go/typdown.go
+++ b/go/typdown.go
@@ -31,7 +31,7 @@ var (
func Parse(content string) (template.HTML, error) {
code := C.uchar(0)
conv := C.CString(content)
- raw := C.parse(conv, &code)
+ raw := C.typdown_parse(conv, &code)
defer C.free(unsafe.Pointer(conv))
if code > 0 {
err := codeErrors[uint8(code)]
diff --git a/include/typdown.h b/include/typdown.h
index 4b08aaa..51821a0 100644
--- a/include/typdown.h
+++ b/include/typdown.h
@@ -1,5 +1,5 @@
#pragma once
#include <stdint.h>
-char * getErrorString(uint8_t);
-char * parse(char *, uint8_t *);
+char * typdown_getErrorString(uint8_t);
+char * typdown_parse(char *, uint8_t *);
diff --git a/src/root.zig b/src/root.zig
index 956f584..f0e3f98 100644
--- a/src/root.zig
+++ b/src/root.zig
@@ -15,7 +15,7 @@ inline fn getErrorCode(err: Error) u8 {
}
/// Returns the static string linked with the error code.
-export fn getErrorString(code: u8) [*:0]const u8 {
+export fn typdown_getErrorString(code: u8) [*:0]const u8 {
return switch (code) {
1 => "out of memory",
2 => "invalid UTF-8",
@@ -33,11 +33,11 @@ export fn getErrorString(code: u8) [*:0]const u8 {
///
/// Returns a not null strings and set the code to 0 if everything is fine.
/// Else, it returns null and set an error code above 0.
-/// Use getErrorString to retrieve the string linked with the error code.
-/// Use zigParse if you are in Zig.
-export fn parse(content: [*:0]const u8, code: *u8) ?[*:0]const u8 {
+/// Use typdown_getErrorString to retrieve the string linked with the error code.
+/// Use parse if you are in Zig.
+export fn typdown_parse(content: [*:0]const u8, code: *u8) ?[*:0]const u8 {
const alloc = std.heap.c_allocator;
- const res = zigParse(alloc, std.mem.span(content)) catch |err| {
+ const res = parse(alloc, std.mem.span(content)) catch |err| {
code.* = getErrorCode(err);
return null;
};
@@ -52,19 +52,14 @@ export fn parse(content: [*:0]const u8, code: *u8) ?[*:0]const u8 {
/// Parse the content.
///
/// Use parse if you are not in Zig.
-pub fn zigParse(alloc: std.mem.Allocator, content: []const u8) Error![]const u8 {
+pub fn parse(alloc: std.mem.Allocator, content: []const u8) Error![]const u8 {
return parser.parse(alloc, content);
}
-pub fn zigParseReader(alloc: std.mem.Allocator, r: *std.io.Reader) ![]const u8 {
+pub fn zigParse(alloc: std.mem.Allocator, r: *std.io.Reader) ![]const u8 {
return parser.parseReader(alloc, r);
}
-pub fn zigParseFile(alloc: std.mem.Allocator, path: []const u8) ![]const u8 {
- const file = try std.fs.cwd().readFileAlloc(alloc, path, std.math.maxInt(usize));
- return zigParse(alloc, file);
-}
-
test {
std.testing.refAllDeclsRecursive(@This());
}
@@ -73,7 +68,7 @@ fn doTest(content: [*:0]const u8, exp: []const u8, comptime exp_code: u8) !void
const expect = std.testing.expect;
var code: u8 = undefined;
- const raw = parse(content, &code) orelse {
+ const raw = typdown_parse(content, &code) orelse {
expect(code == exp_code) catch |err| {
std.debug.print("{}\n", .{code});
return err;