void LTransTextProcessor::on_submit_process(EventData * p_edata, EventEngine * p_caller) { cout << "test2 in on_submit_process..." << endl; assert(p_edata && p_caller); //转换请求 TextProcReq * p_req = dynamic_cast<TextProcReq*>(p_edata); if(!p_req) { lerr << "Convert to TextProcReq Failed." << endl; return; } if(p_req->GetTransType() != TRANS_TYPE_RTT) { lerr << "Local process can't accept a un rtt trans type." << endl; return; } TransText * p_text = p_req->GetTransText(); assert(p_text); int result = SUCCESS; try { //Step 1 语种识别 //DO NOTHING //Step 2 txt文本格式解析 TxtParser txt; vector<string> para_vec; vector<pair<size_t,size_t> > pos_vec; if(false == txt.Parse(p_text->GetSrcData(), para_vec, pos_vec) ) { lerr << "Txt Format parse Failed." << endl; result = ERR_PROC_TXT_FROMAT; throw -1; } p_text->SetFormatSrc(para_vec, pos_vec); }catch(...) { } //返回结果事件 TextProcRes *p_proc_res = new TextProcRes(p_req->GetCallID(), p_text, result); Event re(p_proc_res, this); p_caller->PostEvent(re); return; }
// on_load_text_3 int TextHandler::build_base_source(const string & text, TransText & trans_text) { string source_text = text; //1 编码识别和转换 charset_handle(source_text); //2 文本格式解析,存入TransText trans_text.ResetSrcData(source_text); TxtParser txt; vector<string> para_vec; vector<pair<size_t,size_t> > pos_vec; if(false == txt.Parse(trans_text.GetSrcData(), para_vec, pos_vec) ) { lerr << "Txt Format parse Failed." << endl; return ERR_PROC_TXT_FROMAT; } trans_text.SetFormatSrc(para_vec, pos_vec); //3 保存Base pos & Base source文件 string pos_content; trans_text.GetFromat().Serialization(pos_content); string pos_file_path = m_default_file_path + trans_text.GetID() + BASE_TEXT_POS_POSTFIX; if(false == write_file(pos_file_path, pos_content.c_str(), pos_content.size())) { return ERR_SAVE_BASE_POS_FILE_FAIELD; } string source_file_path = m_default_file_path + trans_text.GetID() + BASE_TEXT_SOURCE_POSTFIX; if(false == write_file(source_file_path, source_text.c_str(), source_text.size()) ) { return ERR_SAVE_BASE_SOURCE_FILE_FAILED; } return SUCCESS; }