Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ To use it you only need:

and link `-lstringx` — one header, one library.

**Documentation:** the full manual lives in [`docs/`](docs/README.md) —
[Getting started](docs/en_us/getting-started.md), [User guide](docs/en_us/guide.md),
[API reference](docs/en_us/api-buffer.md), [Regex](docs/en_us/regex.md),
[Design](docs/en_us/design.md), [Build & test](docs/en_us/build-and-test.md).
The Chinese edition is under [`docs/zh_cn/`](docs/zh_cn/README.md).

## Design

- **Buffer model.** Every `sx_t` owns a single NUL-terminated buffer:
Expand All @@ -23,18 +29,18 @@ and link `-lstringx` — one header, one library.
- **Views.** `sx_view_t {ref, offset, len}` aliases a slice of a buffer with
**no copy and no modification** of the original. Many APIs return views
(the `ref == NULL` sentinel marks "none").
- **Layers.** `sx_core.h` provides the core buffer, view, search, compare
and split operations (reached through `sx.h`); the advanced layer adds
regex through **PCRE2** (`\d \w \b …` are ASCII in 8-bit non-UTF mode).
- **Layers.** `sx_core.h` provides the core buffer, view, search and
compare operations (reached through `sx.h`); the advanced layer adds
splitting (`sx_split`) and regex through **PCRE2** (`\d \w \b …` are
ASCII in 8-bit non-UTF mode).
- **Deterministic contracts.** Every function documents its exact behavior
boundaries in `sx.h`; invalid inputs never crash — they return a
documented not-found/error value.
boundaries in `sx.h`: documented miss/error cases return sentinel values,
and anything outside those boundaries is out of contract.

## Requirements

- A C23 compiler (GCC and Clang), Linux
- The `forge` build tool to build from source (https://github.com/minelogy-dev/forge —
a custom build system; the tool compiles `build.c` into a local `./make` entry)
- [Forge](https://github.com/minelogy-dev/forge) to build from source
- `libpcre2-dev` (PCRE2 8-bit) — the regex layer's dependency; the shared
library links `pcre2-8` itself, so consumers only need `-lstringx`
- `pkg-config` (or `pkgconf`) recommended for consumers — the installed
Expand All @@ -43,29 +49,38 @@ and link `-lstringx` — one header, one library.
## Build

```sh
forge . # compile build.c into ./make (re-run whenever build.c changes)
forge . # generate ./make
./make # build -> build/output/libstringx.so (+ headers at build/output/include)
./make test # build and run every test under tests/ (ASan + UBSan)
```

See [Build, test & package](docs/en_us/build-and-test.md) for installation,
packaging and the test harness.

## Quick start

Edits return the handle they were given, so the whole chain is one
expression: `sx_append` consumes its `sx_t *` argument, and one `sx_free`
releases everything.

```c
#include <sx.h>
#include <stdio.h>

int main(void) {
sx_t *msg = sx_new_from_cstr("hello, world");
size_t at = sx_find_cstr(msg, ", ");
sx_t *hi = sx_substr(msg, 0, at);
fwrite(sx_buf_mut(hi), 1, (size_t)sx_len(hi), stdout);
putchar('\n'); /* hello */
sx_free(hi);
sx_free(msg);
/* One expression: every call returns the same handle, and the temporary
buffer is consumed by sx_append, so there is nothing else to free. */
sx_t *msg = sx_append(sx_append_cstr(sx_new(), "Hello, "),
sx_new_from_cstr("String X!"));

printf("%s (%d bytes)\n", sx_buf_mut(msg), sx_len(msg));
sx_free(msg); /* one buffer, one free */
return 0;
}
```

It prints `Hello, String X! (16 bytes)`.

Compile with (manually, or via pkg-config):

```sh
Expand Down Expand Up @@ -116,10 +131,14 @@ Contract highlights (full detail in `sx.h`):
| Split | `sx_split(sep)` |
| Regex | `sx_reg_compile`, `sx_reg_free`, `sx_reg_is_match`, `sx_reg_match`, `sx_reg_match_all`, `sx_reg_replace`, `sx_reg_replace_first`, `sx_reg_split` |

This table is an index only: [API reference: buffers & views](docs/en_us/api-buffer.md)
and [API reference: search, compare & split](docs/en_us/api-search.md) document
every function's exact contract.

## Tests

Pull requests run compiler, sanitizer, static-analysis and secret checks.
See [Continuous integration](docs/CI.md) for coverage and merge-protection setup.
See [Continuous integration](docs/en_us/ci.md) for coverage and merge-protection setup.

```sh
./make test
Expand Down
48 changes: 32 additions & 16 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

并链接 `-lstringx` —— 一个头文件,一个库。

**文档:** 完整手册位于 [`docs/`](docs/README.md) ——
[快速上手](docs/zh_cn/getting-started.md)、[用户指南](docs/zh_cn/guide.md)、
[API 参考](docs/zh_cn/api-buffer.md)、[正则](docs/zh_cn/regex.md)、
[设计](docs/zh_cn/design.md)、[构建与测试](docs/zh_cn/build-and-test.md)。
英文版见 [`docs/en_us/`](docs/en_us/README.md)。

## 设计

- **缓冲区模型。** 每个 `sx_t` 拥有一个单 NUL 结尾的缓冲区:
Expand All @@ -20,47 +26,53 @@
内嵌 NUL 是普通数据(二进制安全)。
- **视图。** `sx_view_t {ref, offset, len}` 是缓冲区某一段的别名:
**不拷贝、不修改**原串。多数 API 返回视图(`ref == NULL` 哨兵表示"无")。
- **分层。** core 层(经 `sx.h` 可达)提供缓冲区、视图、查找、比较、
split 等核心操作;adv 层基于 **PCRE2** 提供正则(8 位非 UTF 模式,
`\d \w \b …` 仅匹配 ASCII)。
- **确定性契约。** 每个函数在 `sx.h` 里写明精确的行为边界;非法输入不会
崩溃——返回文档化的"未找到/出错"值。
- **分层。** core 层(经 `sx.h` 可达)提供缓冲区、视图、查找、比较等
核心操作;adv 层提供分割(`sx_split`)与基于 **PCRE2** 的正则
(8 位非 UTF 模式,`\d \w \b …` 仅匹配 ASCII)。
- **确定性契约。** 每个函数在 `sx.h` 里写明精确的行为边界:文档化的
"未找到/出错"情形返回哨兵值,超出文档边界的输入属于契约之外。

## 依赖

- C23 编译器(GCC / Clang),Linux
- 构建需要 `forge` 构建工具(https://github.com/minelogy-dev/forge —— 自定义
构建系统:它会将 `build.c` 编译成本地 `./make` 入口)
- 从源码构建需要 [Forge](https://github.com/minelogy-dev/forge)
- `libpcre2-dev`(PCRE2 8 位)——正则层的依赖;共享库自身已链接
`pcre2-8`,使用者只需 `-lstringx`
- 推荐使用者安装 `pkg-config`(或 pkgconf)—— 安装包自带 `libstringx.pc`

## 构建

```sh
forge . # 把 build.c 编译成 ./make(改动 build.c 后需重跑)
forge . # 生成 ./make
./make # 构建 -> build/output/libstringx.so(头文件随附于 build/output/include)
./make test # 编译并运行 tests/ 下每个测试(ASan + UBSan)
```

安装、打包与测试框架的完整说明见[构建、测试与打包](docs/zh_cn/build-and-test.md)。

## 快速上手

每次修改都返回传入的句柄,因此整条链是一个表达式:`sx_append` 消费传入的
`sx_t *`,最后只需一次 `sx_free`。

```c
#include <sx.h>
#include <stdio.h>

int main(void) {
sx_t *msg = sx_new_from_cstr("hello, world");
size_t at = sx_find_cstr(msg, ", ");
sx_t *hi = sx_substr(msg, 0, at);
fwrite(sx_buf_mut(hi), 1, (size_t)sx_len(hi), stdout);
putchar('\n'); /* hello */
sx_free(hi);
sx_free(msg);
/* One expression: every call returns the same handle, and the temporary
buffer is consumed by sx_append, so there is nothing else to free. */
sx_t *msg = sx_append(sx_append_cstr(sx_new(), "Hello, "),
sx_new_from_cstr("String X!"));

printf("%s (%d bytes)\n", sx_buf_mut(msg), sx_len(msg));
sx_free(msg); /* one buffer, one free */
return 0;
}
```

输出为 `Hello, String X! (16 bytes)`。

编译(手动,或经 pkg-config):

```sh
Expand Down Expand Up @@ -110,10 +122,14 @@ sx_reg_free(re);
| 分隔 | `sx_split(sep)` |
| 正则 | `sx_reg_compile`, `sx_reg_free`, `sx_reg_is_match`, `sx_reg_match`, `sx_reg_match_all`, `sx_reg_replace`, `sx_reg_replace_first`, `sx_reg_split` |

上表只是索引:[API 参考:缓冲区与视图](docs/zh_cn/api-buffer.md) 与
[API 参考:查找、比较与分割](docs/zh_cn/api-search.md) 记录了每个函数
精确的契约。

## 测试

PR 会自动执行编译、内存检查、静态分析和密钥扫描。
检查范围与分支保护设置见[持续集成说明](docs/CI.md)。
检查范围与分支保护设置见[持续集成说明](docs/zh_cn/ci.md)。

```sh
./make test
Expand Down
101 changes: 0 additions & 101 deletions docs/CI.md

This file was deleted.

27 changes: 27 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# String X documentation

String X is a small C string library with a single-header API (`<sx.h>`) and a
byte-exact, zero-copy view model. This directory holds the complete
documentation for **v0.5**, in English and Simplified Chinese.

Choose a language / 选择语言:

- **[English documentation](en_us/README.md)**
- **[简体中文文档](zh_cn/README.md)**

Both languages cover the same material with the same structure:

| Topic | English | 中文 |
| --- | --- | --- |
| Getting started | [getting-started.md](en_us/getting-started.md) | [getting-started.md](zh_cn/getting-started.md) |
| User guide | [guide.md](en_us/guide.md) | [guide.md](zh_cn/guide.md) |
| API reference — buffers & views | [api-buffer.md](en_us/api-buffer.md) | [api-buffer.md](zh_cn/api-buffer.md) |
| API reference — search, compare, split | [api-search.md](en_us/api-search.md) | [api-search.md](zh_cn/api-search.md) |
| Regular expressions | [regex.md](en_us/regex.md) | [regex.md](zh_cn/regex.md) |
| Design & internals | [design.md](en_us/design.md) | [design.md](zh_cn/design.md) |
| Build, test & package | [build-and-test.md](en_us/build-and-test.md) | [build-and-test.md](zh_cn/build-and-test.md) |
| Contributing | [contributing.md](en_us/contributing.md) | [contributing.md](zh_cn/contributing.md) |
| Continuous integration | [ci.md](en_us/ci.md) | [ci.md](zh_cn/ci.md) |

The project is MIT licensed; the regex layer uses PCRE2 (BSD-3-Clause). See
[LICENSE](../LICENSE) and [THIRD_PARTY_NOTICES.md](../THIRD_PARTY_NOTICES.md).
42 changes: 0 additions & 42 deletions docs/WRITE_SAFETY.md

This file was deleted.

Loading
Loading