std::string CStringToStdString1(CString theCStr)
{
	//CT2CA pszConvertedAnsiString(inCString);
	//std::string szResult(pszConvertedAnsiString);
	//return szResult;
  
	// Convert the CString to a regular char array
	const int theCStrLen = theCStr.GetLength();
	char *buffer = (char*)malloc(sizeof(char)*(theCStrLen+1));
	memset((void*)buffer, 0, sizeof(buffer));
	WideCharToMultiByte(CP_UTF8, 0, static_cast<CString>(theCStr).GetBuffer(), theCStrLen, buffer, sizeof(char)*(theCStrLen+1), NULL, NULL);
	// Construct a std::string with the char array, free the memory used by the char array, and
	// return the std::string object.
	std::string STDStr(buffer);
	free((void*)buffer);
	return STDStr;


	//std::string STDStr( CW2A( inCString.GetString(), CP_UTF8 ) );
	//CT2CA pszName(inCString); 
	//return (pszName);
}
Esempio n. 2
0
void CWordDocumentProcessing::GetText(int nSourceText,int nBook,int nChapter,int nVerse,int nSentence,CString* strEnglish,CString* strTarget)  //get the English sentence and target translation from the Word doc
{
	int i,j,k;
	CString T,strFileName,strReference,strCurrentReference,strEnglishSentence,strTargetSentence;
	wchar_t c[5];
	BOOL b;
	CReferenceUtils ru;
	TbtaFileProcessing::TbtaTable tbtaTable;
	TbtaFileProcessing::TbtaTableRow tbtaTableRow;

	*strEnglish=L"";
	*strTarget=L"";
	if (nSourceText==4 || nSourceText==3)          //if in the Bible or missions docs
	{
		if (nBook==1) strFileName=m_pDoc->GetPropertyString(11);     //get the Word doc for Genesis
		if (nBook==8) strFileName=m_pDoc->GetPropertyString(7);     //get the Word doc for Ruth
		if (nBook==27) strFileName=m_pDoc->GetPropertyString(12);     //get the Word doc for Daniel
		if (nBook==42) strFileName=m_pDoc->GetPropertyString(10);     //get the Word doc for Luke
	}
	else if (nSourceText==7)    //else in a community development text
	{
		strFileName=m_pDoc->GetPropertyString(nBook+3);   //get the name of the Word doc where user has his Community Development sentences
	}
	else
	{
		return;
	}
	if (strFileName==L"") 
	{
		*strEnglish=L"(no document has been selected)";
		return;
	}
	b=DoesFileExist(strFileName);
	if (!b) 
	{
		*strEnglish=L"(the specified document does not exist)";
		return;
	}
	strCurrentReference=ru.FormatReference(nBook,nChapter,nVerse,nSourceText,m_pDoc);
	if (nSentence>0)         //if in single sentence mode
	{
		_itow(nSentence,c,10);
		T=c;
		strCurrentReference+=L":"+T;
	}
	std::string STDStr(CW2A(strFileName.GetString()));
	TbtaFileProcessing::TbtaFileProcessor::Initialize(); //the initialize and terminate functions can just be called from the main method, they don't have to be called for every function.  But Initialize does need to be called before creating any TbtaFileProcessor instances.
	try
	{
		std::vector<TbtaFileProcessing::TbtaTable> tables = TbtaFileProcessing::TbtaFileProcessor::GetAllTables(STDStr);
		if (tables.size()>0)    //if there are some tables in the doc
		{
			for (i=0; i<tables.size(); i++)          //for each table
			{
				tbtaTable=tables[i];
				for (j=0; j<tbtaTable.size(); j++)   //for each row
				{
					tbtaTableRow=tbtaTable[j];
					strReference=tbtaTableRow[0];
					k=strReference.Find(L":");
					if (k>-1)
					{
						k=strReference.Find(L" ",k);  //find the first space after the colon
						if (k>0) strReference=strReference.Left(k);  //remove the comments after the reference
						if (strReference==strCurrentReference)   //if this row in the table corresponds to this verse in the Grammar Intro
						{
							strEnglishSentence=tbtaTableRow[1];    //get the English sentence
							strEnglishSentence=strCurrentReference+L" "+strEnglishSentence;       //put the reference at the beginning
							strTargetSentence=tbtaTableRow[2];
							if (nSentence>0) strTargetSentence=FindEndOfExample(strTargetSentence);   //trim the example so that it doesn't include the user's notes
						}
					}
				}
			}
		}
	}
	catch (const TbtaFileProcessing::FileProcessingException& e)
	{
			//error handling code here
	}
	TbtaFileProcessing::TbtaFileProcessor::Terminate();
	*strEnglish=strEnglishSentence;
	*strTarget=strTargetSentence;
}
Esempio n. 3
0
void CWordDocumentProcessing::GetGrammarIntroTexts(int nBook,int nChapter,int nVerse,CString* strEnglish,CString* strTarget)
{
	int i,j,k;
	CString strFileName,strReference,strCurrentReference,strEnglishSentence,strTargetSentence;
	BOOL b;
	CReferenceUtils ru;
	TbtaFileProcessing::TbtaTable tbtaTable;
	TbtaFileProcessing::TbtaTableRow tbtaTableRow;

	*strEnglish=L"";
	*strTarget=L"";
	strFileName=m_pDoc->GetPropertyString(2);   //get the name of the Word doc where user has his Grammar Intro sentences
	if (strFileName==L"") 
	{
		*strEnglish=L"(no document has been selected)";
		return;
	}
	b=DoesFileExist(strFileName);
	if (!b) 
	{
		*strEnglish=L"(the specified document does not exist)";
		return;
	}
	strCurrentReference=ru.FormatReference(nBook,nChapter,nVerse,6,m_pDoc);
	std::string STDStr(CW2A(strFileName.GetString()));
	TbtaFileProcessing::TbtaFileProcessor::Initialize(); //the initialize and terminate functions can just be called from the main method, they don't have to be called for every function.  But Initialize does need to be called before creating any TbtaFileProcessor instances.
	try
	{
		std::vector<TbtaFileProcessing::TbtaTable> tables = TbtaFileProcessing::TbtaFileProcessor::GetAllTables(STDStr);
		if (tables.size()>0)    //if there are some tables in the doc
		{
			for (i=0; i<tables.size(); i++)          //for each table
			{
				tbtaTable=tables[i];
				for (j=1; j<tbtaTable.size(); j++)   //for each row
				{
					tbtaTableRow=tbtaTable[j];
					strReference=tbtaTableRow[0];
					k=strReference.Find(L":");
					if (k>-1)
					{
						k=strReference.Find(L" ",k);  //find the first space after the colon
						if (k>0) strReference=strReference.Left(k);  //remove the comments after the reference
						if (strReference==strCurrentReference)   //if this row in the table corresponds to this verse in the Grammar Intro
						{
							strEnglishSentence=tbtaTableRow[1];    //get the English sentence
							strEnglishSentence=strCurrentReference+L" "+strEnglishSentence;       //put the reference at the beginning
							strTargetSentence=tbtaTableRow[3];
							strTargetSentence=FindEndOfExample(strTargetSentence);   //trim the example so that it doesn't include the user's notes
						}
					}
				}
			}
		}
	}
	catch (const TbtaFileProcessing::FileProcessingException& e)
	{
			//error handling code here
	}
	TbtaFileProcessing::TbtaFileProcessor::Terminate();
	*strEnglish=strEnglishSentence;
	*strTarget=strTargetSentence;
}