luat_pinyin.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef LUAT_PINYIN_H
  2. #define LUAT_PINYIN_H
  3. #include "luat_base.h"
  4. #include <stdint.h>
  5. /**
  6. * @brief 将Unicode码点转换为UTF-8字符串
  7. * @param codepoint Unicode码点
  8. * @param utf8_buf 输出缓冲区(至少5字节)
  9. * @return UTF-8字节数,失败返回0
  10. */
  11. int luat_pinyin_codepoint_to_utf8(uint32_t codepoint, char *utf8_buf);
  12. /**
  13. * @brief 初始化pinyin库(预留接口,当前无需初始化)
  14. * @return 0表示成功
  15. */
  16. int luat_pinyin_init(void);
  17. /**
  18. * @brief 查询拼音对应的候选字Unicode码点数组
  19. * @param pinyin 拼音字符串(小写,无声调)
  20. * @param codepoints 输出参数:码点数组指针
  21. * @param count 输出参数:候选字数量
  22. * @return 0表示找到,-1表示未找到
  23. */
  24. int luat_pinyin_query(const char *pinyin, const uint32_t **codepoints, uint16_t *count);
  25. /**
  26. * @brief 查询拼音对应的候选字UTF-8字符串数组
  27. * @param pinyin 拼音字符串(小写,无声调)
  28. * @param utf8_strings 输出参数:UTF-8字符串数组,每个字符串最多5字节(4字节UTF-8 + '\0')
  29. * @param max_count 最大字符串数量(数组大小)
  30. * @param count 输出参数:实际返回的字符串数量
  31. * @return 0表示成功,-1表示失败
  32. */
  33. int luat_pinyin_query_utf8(const char *pinyin, char (*utf8_strings)[5], uint16_t max_count, uint16_t *count);
  34. /**
  35. * @brief 根据按键序列查询可能的音节列表(9键输入法)
  36. * @param key_sequence 按键序列数组,每个元素为按键ID(1-8对应ABC-WXYZ)
  37. * @param key_count 按键序列长度(最多5个)
  38. * @param syllables 输出参数:音节字符串数组(调用者需要分配内存)
  39. * @param max_syllable_count 最大音节数量(数组大小)
  40. * @param actual_count 输出参数:实际返回的音节数量
  41. * @return 0表示成功,-1表示失败
  42. *
  43. * 按键ID映射:
  44. * 1 → ABC (a, b, c)
  45. * 2 → DEF (d, e, f)
  46. * 3 → GHI (g, h, i)
  47. * 4 → JKL (j, k, l)
  48. * 5 → MNO (m, n, o)
  49. * 6 → PQRS (p, q, r, s)
  50. * 7 → TUV (t, u, v)
  51. * 8 → WXYZ (w, x, y, z)
  52. *
  53. * 示例:
  54. * 输入:key_sequence = [8, 3, 5, 5, 3] (对应 WXYZ, GHI, MNO, MNO, GHI)
  55. * 输出:可能的音节:["zhong", "zong", ...](按常用度排序)
  56. */
  57. int luat_pinyin_query_syllables_by_keys(
  58. const uint8_t *key_sequence,
  59. uint8_t key_count,
  60. char (*syllables)[8], // 每个音节最多7个字母+'\0'
  61. uint16_t max_syllable_count,
  62. uint16_t *actual_count
  63. );
  64. #endif /* LUAT_PINYIN_H */