Backend/Database/GTable.cpp
/*!
 * @brief GTable String import
 * @details imports data from a raw string
 * @param content the GTable data as a string
 */
@brief GTable String import
@details imports data from a raw string
@param content the GTable data as a string
@brief GTable String import @details imports data from a raw string @param content the GTable data as a string
void GTable::importFromString(const GString& newContent)
{
	if (!(newContent.length() > 0))
	{
		printf("[CSV] Load from string error.\n");
		return;
	}
	GString content = newContent;
	int rowCounter = 0;
	do
	{
		shmea::GList newRow;
		int breakPoint = content.cfind('\n');
		if (breakPoint == -1)
			break;
		GString line = content.substr(0, breakPoint);
		content = content.substr(breakPoint + 1);
		int colCounter = 0;
		bool lastCol = false;
		int breakPoint2 = line.cfind(delimiter);
		do
		{
			if ((breakPoint2 == -1) && (line.length() > 0) && (!lastCol))
			{
				breakPoint2 = line.length();
				lastCol = true;
			}
			GString word = line.substr(0, breakPoint2);
			if (!lastCol)
			{
				line = line.substr(breakPoint2 + 1);
				breakPoint2 = line.cfind(delimiter);
			}
			if (rowCounter == 0)
				header.push_back(word);
			else
				newRow.addString(word);
			++colCounter;
		} while (!lastCol);
		if (rowCounter > 0)
			addRow(newRow);
		++rowCounter;
	} while (content.length() > 0);
}
void GTable :: importFromString ( const GString & newContent ) { if ( ! ( newContent . length ( ) > 0 ) ) { printf ( " \n " ) ; return ; } GString content = newContent ; int rowCounter = 0 ; do { shmea :: GList newRow ; int breakPoint = content . cfind ( ' \n ' ) ; if ( breakPoint == -1 ) break ; GString line = content . substr ( 0 , breakPoint ) ; content = content . substr ( breakPoint + 1 ) ; int colCounter = 0 ; bool lastCol = false ; int breakPoint2 = line . cfind ( delimiter ) ; do { if ( ( breakPoint2 == -1 ) && ( line . length ( ) > 0 ) && ( ! lastCol ) ) { breakPoint2 = line . length ( ) ; lastCol = true ; } GString word = line . substr ( 0 , breakPoint2 ) ; if ( ! lastCol ) { line = line . substr ( breakPoint2 + 1 ) ; breakPoint2 = line . cfind ( delimiter ) ; } if ( rowCounter == 0 ) header . push_back ( word ) ; else newRow . addString ( word ) ; ++ colCounter ; } while ( ! lastCol ) ; if ( rowCounter > 0 ) addRow ( newRow ) ; ++ rowCounter ; } while ( content . length ( ) > 0 ) ; }
@brief GTable String import
 @details imports data from a raw string
 @param content the GTable data as a string
@brief GTable String import @details imports data from a raw string @param content the GTable data as a string
// Allocate a buffer // get the current line // Read each column // last column? // get the cell // add the col to the row // for the next column // add the row to the object