Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
strings.h
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 */
18#pragma once
19
20#include <stddef.h>
21#include <stdint.h>
22
23// TODO(lxsameer): Implement the WTF8 support based on Rust's implementation
24
25typedef struct srn_context_t srn_context_t;
26typedef struct srn_error_t srn_error_t;
27typedef struct srn_value_t srn_value_t;
28typedef struct srn_metadata_t srn_metadata_t;
29
30/// On top of my head, no other reason.
31#define SRN_STRING_MAX_LEN (1U << 20U)
32
33typedef struct srn_string_t {
34 /// Size of the buffer
35 size_t size;
36 /// length of the WTF-8 sequence in bytes
37 size_t len;
38 /// The buffer that holds the WTF8 sequence.
39 uint8_t buffer[];
41
42/// Create a string from a null terminated C string. IT HAS TO BE NULL
43/// TERMINATED
44[[gnu::nonnull(1)]] srn_value_t *
45srn_string_make(srn_context_t *ctx, srn_metadata_t *metadata, const char *src);
46
47[[gnu::nonnull(1)]]
48size_t srn_string_size(const srn_string_t *s);
49[[gnu::nonnull(1)]]
50size_t srn_string_length(const srn_string_t *s);
51
52/// Copy the `src` string to `dst` string. It's important to note that dst has
53/// to be allocated already
54[[gnu::nonnull(1, 2)]]
56
58bool srn_string_eq(const srn_string_t *a, const srn_string_t *b);
size_t srn_string_length(const srn_string_t *s)
Definition strings.c:33
size_t srn_string_size(const srn_string_t *s)
Definition strings.c:28
srn_value_t * srn_string_make(srn_context_t *ctx, srn_metadata_t *metadata, const char *src)
Create a string from a null terminated C string.
Definition strings.c:50
bool srn_string_is_empty(const srn_string_t *s)
Definition strings.c:48
bool srn_string_eq(const srn_string_t *a, const srn_string_t *b)
Definition strings.c:76
srn_string_t * srn_string_copy(srn_context_t *ctx, const srn_string_t *src)
Copy the src string to dst string.
Definition strings.c:38
size_t size
Size of the buffer.
Definition strings.h:35
uint8_t buffer[]
The buffer that holds the WTF8 sequence.
Definition strings.h:39
size_t len
length of the WTF-8 sequence in bytes
Definition strings.h:37