ERROR_NO_ITEM, /* item has a null slot */
ERROR_OUT_OF_RANGE, /* beyond the end of the sub phrase index */
ERROR_FILE_CORRUPTION, /* file is corrupted */
- ERROR_INTEGER_OVERFLOW /* integer is overflowed */
+ ERROR_INTEGER_OVERFLOW, /* integer is overflowed */
+ ERROR_ALREADY_EXISTS /* the sub phrase already exists. */
};
/* For N-gram */
chunkfilename = g_build_filename(context->m_user_dir,
phrasefilename, NULL);
- /* TODO: check bin file exists. if not, create a new one. */
- chunk->load(chunkfilename);
- g_free(chunkfilename);
+ /* check bin file exists. if not, create a new one. */
+ if (chunk->load(chunkfilename)) {
+ context->m_phrase_index->load(index, chunk);
+ } else {
+ delete chunk;
+ context->m_phrase_index->create_sub_phrase(index);
+ }
- context->m_phrase_index->load(index, chunk);
+ g_free(chunkfilename);
return true;
}
}
/**
- * TODO: to be implemented.
- * Note: prefix is the text before the pre-edit string.
- * bool pinyin_get_guessed_sentence_with_prefix(...);
- * bool pinyin_get_candidates_with_prefix(...);
- * For context-dependent order of the candidates list.
+ * Note: prefix is the text before the pre-edit string.
*/
}
return true;
}
+
+ int create_sub_phrase(guint8 index) {
+ SubPhraseIndex * & sub_phrase = m_sub_phrase_indices[index];
+ if (sub_phrase) {
+ return ERROR_ALREADY_EXISTS;
+ }
+
+ sub_phrase = new SubPhraseIndex;
+
+ return ERROR_OK;
+ }
};
};