cstring概述
cstring是一個小型且簡單的C庫,用於定義和操作可擴展C樣式的字符串。字符串表示為cstring_t結構的實例, 並由庫的函數進行操作。它提供了一個簡單的API,由以下函數組成:
- cstring_error()
- cstring_init()
- cstring_create()
- cstring_createLen()
- cstring_createEx()
- cstring_createLenEx()
- cstring_destroy()
- cstring_yield2()
- cstring_setCapacity()
- cstring_assign()
- cstring_assignLen()
- cstring_copy()
- cstring_append()
- cstring_appendLen()
- cstring_truncate()
- cstring_swap()
- cstring_readline() (v3.5 +)
- cstring_writeline() (v3.5 +)
- cstring_insert() (v3.5 +)
- cstring_insertLen() (v3.5 +)
- cstring_replace() (v3.5 +)
- cstring_replaceLen() (v3.5 +)
- cstring_replaceAll() (v3.5 +)
下面的示例創建一個cstring實例,然後將另外兩個c樣式字符串附加到該實例,將其打印到stdout,將其截斷,再次打印,然後將其銷燬。
cstring_t str; // create a string from the C-style string "Hello," cstring_create(&str, "Hello,"); // append a space cstring_appendLen(&str, " ", 1); // append "World!" cstring_append(&str, "World!"); // print it out, passing length+ptr to printf printf("cstring contents: %.*s\n", str.len, str.ptr); // truncate it to length 5 cstring_truncate(&str, 5); // print it again, passing the ptr member to puts() puts(str.ptr); // destroy it cstring_destroy(&str);
cstring最新版本 為3.6.2 ,下載地址為http://synesis.com.au/software/cstring。