summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-07-17 13:59:39 +0800
committerPeng Wu <alexepico@gmail.com>2014-07-17 14:27:08 +0800
commit92f2f6fc842698af0c56d069a7944cbad3267c24 (patch)
tree341151f3ea21a677c55b8bc7509a6b7f41ad2d8a
parent3310166780a55b13123388f6632b40bce5464c1c (diff)
downloadibus-libzhuyin-92f2f6fc842698af0c56d069a7944cbad3267c24.tar.gz
ibus-libzhuyin-92f2f6fc842698af0c56d069a7944cbad3267c24.tar.xz
ibus-libzhuyin-92f2f6fc842698af0c56d069a7944cbad3267c24.zip
write function probe_section_start
-rw-r--r--src/ZYEnhancedText.cc44
-rw-r--r--src/ZYEnhancedText.h5
2 files changed, 49 insertions, 0 deletions
diff --git a/src/ZYEnhancedText.cc b/src/ZYEnhancedText.cc
index 0231705..ca71ef9 100644
--- a/src/ZYEnhancedText.cc
+++ b/src/ZYEnhancedText.cc
@@ -240,6 +240,50 @@ get_symbol_section (const String & enhanced_text,
}
bool
+probe_section_start(const String & enhanced_text,
+ guint offset, guint & inner_offset,
+ size_t & index, size_t & start_pos)
+{
+ /* decrement the cursor variable to calculate the zhuyin cursor. */
+ guint cursor = offset;
+ inner_offset = 0;
+
+ index = 0;
+ start_pos = 0; size_t end_pos = 0;
+
+ while (end_pos != enhanced_text.size ()) {
+ if (0 == cursor)
+ break;
+
+ start_pos = end_pos;
+ section_t type = probe_section_quick (enhanced_text, start_pos);
+
+ if (PHONETIC_SECTION == type) {
+ String section;
+ get_phonetic_section (enhanced_text, start_pos, end_pos, section);
+
+ size_t section_len = end_pos - start_pos;
+
+ if (cursor < section_len)
+ break;
+
+ cursor -= section_len;
+ ++index;
+ }
+
+ if (SYMBOL_SECTION == type) {
+ String type, lookup, choice;
+ get_symbol_section (enhanced_text, start_pos, end_pos,
+ type, lookup, choice);
+ --cursor;
+ }
+ }
+
+ inner_offset = cursor;
+ return true;
+}
+
+bool
insert_section (String & enhanced_text, size_t offset, const String & section)
{
size_t pos = 0;
diff --git a/src/ZYEnhancedText.h b/src/ZYEnhancedText.h
index c1ff10a..3c83e2c 100644
--- a/src/ZYEnhancedText.h
+++ b/src/ZYEnhancedText.h
@@ -54,6 +54,11 @@ get_symbol_section (const String & enhanced_text,
String & type, String & lookup, String & choice);
bool
+probe_section_start(const String & enhanced_text,
+ guint offset, guint & inner_offset,
+ size_t & index, size_t & start_pos);
+
+bool
insert_phonetic(String & enhanced_text, size_t offset, const char key);
bool