Skip to content
Permalink
Browse files

Fix for ticket #425: Pipe delimiter

Don't evaluate delimiters as a regexp, just use them as regular strings
because this is what users expect. Tab delimiter can be still used
as \t because of explicit convert to tab character.


git-svn-id: http://svn.osgeo.org/qgis/trunk@6196 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 6, 2006
1 parent ba35e60 commit 622d34a7d826a4440d4e7aff6a8d25773b88ed78
@@ -110,8 +110,12 @@ void QgsDelimitedTextPluginGui::updateFieldLists()
std::cerr << "Attempting to split the input line: " << line.toLocal8Bit().data() <<
" using delimiter " << txtDelimiter->text().toLocal8Bit().data() << std::endl;
#endif

QStringList fieldList = QStringList::split(QRegExp(txtDelimiter->text()), line);
QString delimiter = txtDelimiter->text();

// convert \t to tabulator
delimiter.replace("\\t", "\t");

QStringList fieldList = QStringList::split(delimiter, line);

#ifdef QGISDEBUG
std::cerr << "Split line into " << fieldList.size() << " parts" << std::endl;
@@ -84,6 +84,11 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString const &uri)
std::cerr << "xField is: " << (const char *)mXField.toLocal8Bit().data() << std::endl;
std::cerr << "yField is: " << (const char *)mYField.toLocal8Bit().data() << std::endl;
#endif

// if delimiter contains some special characters, convert them
// (we no longer use delimiter as regexp as it introduces problems with special characters)
mDelimiter.replace("\\t", "\t"); // replace "\t" with a real tabulator

// Set the selection rectangle to null
mSelectionRectangle = 0;
// assume the layer is invalid until proven otherwise
@@ -123,8 +128,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString const &uri)
cerr << "Attempting to split the input line: " << (const char *)line.toLocal8Bit().data() <<
" using delimiter " << (const char *)mDelimiter.toLocal8Bit().data() << std::endl;
#endif
QStringList fieldList =
QStringList::split(QRegExp(mDelimiter), line, true);
QStringList fieldList = QStringList::split(mDelimiter, line, true);
#ifdef QGISDEBUG
std::cerr << "Split line into "
<< fieldList.size() << " parts" << std::endl;
@@ -173,7 +177,7 @@ QgsDelimitedTextProvider::QgsDelimitedTextProvider(QString const &uri)
// std::cout << line << std::endl;
// split the line on the delimiter
QStringList parts =
QStringList::split(QRegExp(mDelimiter), line, true);
QStringList::split(mDelimiter, line, true);
//if(parts.size() == attributeFields.size())
//{
// // we can populate attributes if required
@@ -354,7 +358,7 @@ QgsDelimitedTextProvider::getNextFeature_( QgsFeature & feature,
{
QString line = mStream->readLine(); // Default local 8 bit encoding
// lex the tokens from the current data line
QStringList tokens = QStringList::split(QRegExp(mDelimiter), line, true);
QStringList tokens = QStringList::split(mDelimiter, line, true);

bool xOk = false;
bool yOk = false;
@@ -835,7 +839,7 @@ bool QgsDelimitedTextProvider::saveAsShapefile()
line = mStream->readLine(); // line of text excluding '\n'
// split the line
QStringList parts =
QStringList::split(QRegExp(mDelimiter), line, true);
QStringList::split(mDelimiter, line, true);

// create the feature
OGRFeature *poFeature;
@@ -949,7 +953,7 @@ int *QgsDelimitedTextProvider::getFieldLengths()
{
line = mStream->readLine(); // line of text excluding '\n'
// split the line
QStringList parts = QStringList::split(QRegExp(mDelimiter), line, true);
QStringList parts = QStringList::split(mDelimiter, line, true);
// iterate over the parts and update the max value
for (int i = 0; i < parts.size(); i++)
{

0 comments on commit 622d34a

Please sign in to comment.
You can’t perform that action at this time.