diff --git a/capi/src/io.rs b/capi/src/io.rs index ecf1b705..e2421f90 100644 --- a/capi/src/io.rs +++ b/capi/src/io.rs @@ -1709,6 +1709,24 @@ pub unsafe extern "C" fn chewing_bopomofo_String_static( copy_cstr(&mut ctx.bopomofo_buf, &ctx.editor.syllable_buffer_display()) } +/// # Safety +/// +/// This function should be called with valid pointers. +#[no_mangle] +pub unsafe extern "C" fn chewing_bopomofo_String(ctx: *const ChewingContext) -> *mut c_char { + let ctx = as_ref_or_return!( + ctx, + owned_into_raw(Owned::CString, CString::default().into_raw()) + ); + + let buffer = ctx.editor.syllable_buffer_display(); + let cstr = match CString::new(buffer) { + Ok(cstr) => cstr, + Err(_) => return null_mut(), + }; + owned_into_raw(Owned::CString, cstr.into_raw()) +} + /// # Safety /// /// This function should be called with valid pointers. diff --git a/capi/src/lib.rs b/capi/src/lib.rs index c22c22ed..642a311a 100644 --- a/capi/src/lib.rs +++ b/capi/src/lib.rs @@ -705,6 +705,17 @@ pub mod output { ///

pub use super::io::chewing_zuin_Check; + /// Returns the phonetic characters in the pre-edit buffer. + /// + /// The returned value is a pointer to a character string. The memory must + /// be freed by the caller using function + /// [chewing_free][super::setup::chewing_free]. + /// + /// # Failures + /// + /// This function returns NULL when memory allocation fails. + pub use super::io::chewing_bopomofo_String; + /// Returns the phonetic characters in the pre-edit buffer. /// /// The return value is a const pointer to a character string. The pointer diff --git a/capi/src/symbols-elf.map b/capi/src/symbols-elf.map index 41bec920..f34df457 100644 --- a/capi/src/symbols-elf.map +++ b/capi/src/symbols-elf.map @@ -134,4 +134,9 @@ CHEWING_0.9 { chewing_version_minor; chewing_version_patch; chewing_version_extra; -} CHEWING_0.5; \ No newline at end of file +} CHEWING_0.5; + +CHEWING_0.10 { + global: + chewing_bopomofo_String; +} CHEWING_0.9; \ No newline at end of file diff --git a/capi/src/symbols-mach_o.map b/capi/src/symbols-mach_o.map index 374e149a..fe05dfc0 100644 --- a/capi/src/symbols-mach_o.map +++ b/capi/src/symbols-mach_o.map @@ -3,6 +3,7 @@ _chewing_aux_Length _chewing_aux_String _chewing_aux_String_static _chewing_bopomofo_Check +_chewing_bopomofo_String _chewing_bopomofo_String_static _chewing_buffer_Check _chewing_buffer_Len diff --git a/capi/src/symbols-msvc.def b/capi/src/symbols-msvc.def index 3e75d062..ea91b96c 100644 --- a/capi/src/symbols-msvc.def +++ b/capi/src/symbols-msvc.def @@ -4,6 +4,7 @@ EXPORTS chewing_aux_String; chewing_aux_String_static; chewing_bopomofo_Check; + chewing_bopomofo_String; chewing_bopomofo_String_static; chewing_buffer_Check; chewing_buffer_Len; diff --git a/include/chewing.h b/include/chewing.h index 8f04bb04..ca374e1f 100644 --- a/include/chewing.h +++ b/include/chewing.h @@ -152,7 +152,7 @@ typedef struct ChewingContext ChewingContext; #define CHEWING_VERSION_MINOR 9 -#define CHEWING_VERSION_PATCH 0 +#define CHEWING_VERSION_PATCH 1 /** * Keyboard layout index. @@ -850,6 +850,13 @@ int chewing_buffer_Len(const struct ChewingContext *ctx); */ const char *chewing_bopomofo_String_static(const struct ChewingContext *ctx); +/** + * # Safety + * + * This function should be called with valid pointers. + */ +char *chewing_bopomofo_String(const struct ChewingContext *ctx); + /** * # Safety * diff --git a/tests/test-error-handling.c b/tests/test-error-handling.c index e9d5a48e..d125306d 100644 --- a/tests/test-error-handling.c +++ b/tests/test-error-handling.c @@ -244,6 +244,10 @@ void test_null() const_buf = chewing_buffer_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_buffer_String_static() returns `%s' shall be `%s'", const_buf, ""); + buf = chewing_bopomofo_String(NULL); + ok(strcmp(buf, "") == 0, "chewing_bopomofo_String() returns `%s' shall be `%s'", buf, ""); + chewing_free(buf); + const_buf = chewing_bopomofo_String_static(NULL); ok(strcmp(const_buf, "") == 0, "chewing_bopomofo_String_static() returns `%s' shall be `%s'", const_buf, ""); diff --git a/tests/testhelper.c b/tests/testhelper.c index 53319fd6..1cf86cc3 100644 --- a/tests/testhelper.c +++ b/tests/testhelper.c @@ -99,7 +99,7 @@ BufferType BOPOMOFO_BUFFER = { chewing_bopomofo_Check, chewing_zuin_Check, 0, - 0, + chewing_bopomofo_String, chewing_zuin_String, chewing_bopomofo_String_static };