Skip to content

Commit

Permalink
[add] append_printf() and modify some APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
neverxie committed Jul 25, 2018
1 parent 9b98a12 commit 6f0b33d
Showing 4 changed files with 267 additions and 136 deletions.
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dstr

## 1、介绍
这是一个在 RT-Thread 上,基于ANSI/ISO C(C89)实现的动态字符串软件包。
这是一个在 RT-Thread 上,基于 ANSI/ISO C89 实现的动态字符串软件包。

### 1.1 目录结构

@@ -17,31 +17,37 @@ dstr package 遵循 LGPLv2.1 许可,详见 `LICENSE` 文件。

### 1.3 依赖

对 RT-Thread 无依赖,也可用于裸机。
- 对 RT-Thread 无依赖,也可用于裸机。



## 2、如何打开 dstr

使用 dstr package 需要在 RT-Thread 的包管理器中选择它,具体路径如下
使用 dstr package 需要在 RT-Thread 的包管理器中选择它,详情如下

```
RT-Thread online packages
RT-Thread online packages --->
miscellaneous packages --->
[*] dstr: a dynamic string package
Version (latest) --->
dstr Options --->
[*] dstr test example
```

然后让 RT-Thread 的包管理器自动更新,或者使用 `pkgs --update` 命令更新包到 BSP 中。
保存 menuconfig 配置后使用 `pkgs --update` 命令下载软件包

## 3、使用 dstr

使用dstr可参考例子工程,该工程位于[/examples/examples_dstr.c](examples/examples_dstr.c)
使用 dstr 可参考例子代码,该代码位于[/dstr/examples/examples_dstr.c](dstr/examples/examples_dstr.c)

### 3.1 创建动态字符串对象
`rt_dstr_t *rt_dstr_new(const char *str);`

| 参数 | 描述 |
| ---- | ---- |
| name | 源字符串 |
| return | 创建成功,将返回dstr对象指针;创建失败则返回NULL |
| return | 创建成功,将返回 dstr 对象指针;创建失败则返回 NULL |


### 3.2 删除动态字符串对象
@@ -54,24 +60,24 @@ RT-Thread online packages


### 3.3 动态字符串连接
`rt_dstr_t *rt_dstr_cat(rt_dstr_t *const thiz, const char *src);`
`rt_dstr_t *rt_dstr_cat(rt_dstr_t *thiz, const char *src);`

| 参数 | 描述 |
| ---- | ---- |
| thiz | 动态字符串对象 |
| src | 源字符串 |
| return | cat成功,将返回dstr对象指针;cat失败,则返回NULL,但不会更改thiz,交由用户处理 |
| return | cat 成功,将返回 dstr 对象指针;cat 失败,则返回 NULL,但不会更改 thiz,交由用户处理 |


### 3.4 动态字符串连接(连接几个字符)
`rt_dstr_t *rt_dstr_ncat(rt_dstr_t *const thiz, const char *src, size_t n);`
`rt_dstr_t *rt_dstr_ncat(rt_dstr_t *thiz, const char *src, size_t n);`

| 参数 | 描述 |
| ---- | ---- |
| thiz | 动态字符串对象 |
| src | 源字符串 |
| n | 需要连接几个字符 |
| return | cat成功,将返回dstr对象指针;cat失败,则返回NULL,但不会更改thiz,交由用户处理 |
| return | cat 成功,将返回 dstr 对象指针;cat 失败,则返回 NULL,但不会更改 thiz,交由用户处理 |

### 3.5 动态字符串比较
`int rt_dstr_cmp(rt_dstr_t *const dstr1, rt_dstr_t *const dstr2);`
@@ -115,25 +121,36 @@ RT-Thread online packages
| 参数 | 描述 |
| ---- | ---- |
| thiz | 动态字符串对象 |
| return | 参数非NULL,将返回动态字符串长度;参数为NULL则返回-1 |
| return | 参数非 NULL,将返回动态字符串长度;参数为 NULL 则返回-1 |


### 3.9 字符串格式化输出
`int rt_dstr_sprintf(rt_dstr_t *const thiz, const char *fmt, ...);`
`rt_dstr_t *rt_dstr_sprintf(rt_dstr_t *thiz, const char *fmt, ...);`

| 参数 | 描述 |
| ---- | ---- |
| thiz | 动态字符串对象 |
| fmt | 格式化字符串 |
| argument... | 可选参数,任何类型的数据 |
| return | 返回动态字符串长度 |
| return | 返回 dstr 对象指针 |

### 3.10 字符串格式化输出(以追加的方式实现)

`rt_dstr_t *rt_dstr_append_printf(rt_dstr_t *thiz, const char *format, ...);`

| 参数 | 描述 |
| ---- | -------------- |
| thiz | 动态字符串对象 |
|fmt|格式化字符串|
| argument... | 可选参数,任何类型的数据 |
| return | 返回 dstr 对象指针 |


## 4、注意事项

暂无

## 5、联系方式 & 感谢
## 5、联系方式

* 维护:[never](https://github.com/neverxie)
* 主页:https://github.com/RT-Thread-packages/dstr
Loading

0 comments on commit 6f0b33d

Please sign in to comment.