コード例 #1
0
/// @brief Process a dialogue line 
/// @param node 
/// @return 
///
bool TTXTSubtitleFormat::ProcessLine(wxXmlNode *node) {
	// Get time
	wxString sampleTime = node->GetAttribute(_T("sampleTime"),_T("00:00:00.000"));
	AssTime time;
	time.ParseASS(sampleTime);

	// Set end time of last line
	if (diag) diag->End = time;
	diag = NULL;

	// Get text
	wxString text;
	if (version == 0) text = node->GetAttribute(_T("text"),_T(""));
	else text = node->GetNodeContent();

	// Create line
	if (!text.IsEmpty()) {
		// Create dialogue
		diag = new AssDialogue();
		diag->Start.SetMS(time.GetMS());
		diag->End.SetMS(36000000-10);
		diag->group = _T("[Events]");
		diag->Style = _T("Default");
		diag->Comment = false;

		// Process text for 1.0
		if (version == 0) {
			wxString finalText;
			finalText.Alloc(text.Length());
			bool in = false;
			bool first = true;
			for (size_t i=0;i<text.Length();i++) {
				if (text[i] == _T('\'')) {
					if (!in && !first) finalText += _T("\\N");
					first = false;
					in = !in;
				}
				else if (in) finalText += text[i];
			}
			diag->Text = finalText;
		}

		// Process text for 1.1
		else {
			text.Replace(_T("\r"),_T(""));
			text.Replace(_T("\n"),_T("\\N"));
			diag->Text = text;
		}

		// Insert dialogue
		Line->push_back(diag);
		return true;
	}

	else return false;
}