Skip to content

Commit

Permalink
Fix for ticket #425: Pipe delimiter
Browse files Browse the repository at this point in the history
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 committed Dec 6, 2006
1 parent ba35e60 commit 622d34a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/plugins/delimited_text/qgsdelimitedtextplugingui.cpp
Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
{
Expand Down

0 comments on commit 622d34a

Please sign in to comment.