Example #1
0
ucs4string Regexp::replace(ucs4string& text, ucs4string& subst, bool& matched)
{
    OnigRegion* const region = matchInternal(text);
    if (NULL == region) {
        matched = false;
        return text;
    }
    const ucs4string beg = text.substr(0, region->beg[0] / sizeof(ucs4char));
    const ucs4string end = text.substr(region->end[0] / sizeof(ucs4char), text.size() - region->end[0] / sizeof(ucs4char));
    matched = true;
    return (beg + subst + end).data();
}
Example #2
0
void Segmentation::DoSegment(ucs4string base, double base_rr, ucs4string to_seg, SegmentData& data)
{
	for (size_t i=1; i<to_seg.size(); ++i)
	{
		ucs4string us = to_seg.substr(0, i);
		DoSegment(base + ucs4_t(' ') + us, base_rr*GetRateReciprocal(us), to_seg.substr(i), data);
	}

	double rr = base_rr*GetRateReciprocal(to_seg);
	if (rr > data.m_rr)
		return;

	data.m_rr = rr;
	data.m_res = base + ucs4_t(' ') + to_seg;
}