Skip to content
parse-pinyin.cpp 807 B
Newer Older
Yuanle Song's avatar
Yuanle Song committed
#include "parse-pinyin.hpp"
#include "../PinyinArray.h"
#include "../PinyinParser.h"

/**
 * parse preedit_str to array of Pinyin.
 * each Pinyin contains shengmu_i, yunmu_i, and pinyin's length.
 *
 * @preedit_str: the preedit string
 *
 * returns: a list of Pinyin
 */
std::vector<Pinyin*>*
parse_pinyin (const char* preedit_str, guint max_pinyin)
{
	std::vector<Pinyin*>* result = new std::vector<Pinyin*>();
	PyZy::PinyinArray pyar = {0};
	PyZy::PinyinParser::parse(preedit_str, strlen(preedit_str), 0, pyar, max_pinyin);
	Pinyin thispy = {0};
	for (guint i = 0; i < pyar.size(); ++i) {
		thispy.shengmu_i = (int) pyar[i].pinyin->pinyin_id[0].sheng;
		thispy.yunmu_i = (int) pyar[i].pinyin->pinyin_id[0].yun;
		thispy.length = pyar[i].len;
		result->push_back (new Pinyin(thispy));
	}
	return result;
}