Skip to content
Permalink
Browse files

After astyle

  • Loading branch information
ccrook committed Apr 9, 2013
1 parent 5bd27b0 commit c6f678fa45f3c58e026a0e1b067da4351c290a08

Large diffs are not rendered by default.

@@ -21,7 +21,7 @@ class QgsDelimitedTextProvider;

class QgsDelimitedTextFeatureIterator : public QgsAbstractFeatureIterator
{
public:
public:
QgsDelimitedTextFeatureIterator( QgsDelimitedTextProvider* p, const QgsFeatureRequest& request );

~QgsDelimitedTextFeatureIterator();
@@ -35,7 +35,7 @@ class QgsDelimitedTextFeatureIterator : public QgsAbstractFeatureIterator
//! end of iterating: free the resources / lock
virtual bool close();

protected:
protected:
QgsDelimitedTextProvider* P;

//! Feature id
@@ -50,8 +50,14 @@ QgsDelimitedTextFile::~QgsDelimitedTextFile()

void QgsDelimitedTextFile::close()
{
if( mStream ) { delete mStream; mStream=0; }
if( mFile ) { delete mFile; mFile=0; }
if( mStream ) {
delete mStream;
mStream=0;
}
if( mFile ) {
delete mFile;
mFile=0;
}
}

bool QgsDelimitedTextFile::open()
@@ -95,7 +101,7 @@ bool QgsDelimitedTextFile::setFromUrl( QUrl &url )
// Extract the file name
setFileName( url.toLocalFile());

// The default type is csv, to be consistent with the
// The default type is csv, to be consistent with the
// previous implementation (except that quoting should be handled properly)

QString type("csv");
@@ -326,7 +332,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::nextLine( QString &buffer, bo

QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseRegexp( QStringList &fields )
{
QString buffer;
QString buffer;
Status status = nextLine(buffer,true);
if( status != RecordOk ) return status;
mRecordLineNumber = mLineNumber;
@@ -345,7 +351,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
fields.clear();

// Find the first non-blank line to read
QString buffer;
QString buffer;
Status status = nextLine(buffer,true);
if( status != RecordOk ) return status;
mRecordLineNumber = mLineNumber;
@@ -357,8 +363,8 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
bool started = false; // Non-blank chars in field or quotes started
bool ended = false; // Quoted field ended
int cp = 0; // Pointer to the next character in the buffer
int cpmax = buffer.size(); // End of string
int cpmax = buffer.size(); // End of string

while( true )
{
QChar c = buffer[cp];
@@ -391,7 +397,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
// Determine if this is a special character - test each class in turn
// Note that delimiters are not valid as quotes or escape character
//
// Somewhat convoluted logic around quote and escape chars is
// Somewhat convoluted logic around quote and escape chars is
// to enforce logic for escape characters that are also quote characters.
// These escapes can only escape themselves and only in quotes using them
// as delimiters!
@@ -413,7 +419,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
// quote char in quoted field
if( quoted )
{
// if is also escape and next character is quote, then
// if is also escape and next character is quote, then
// escape the quote..
if( isEscape && buffer[cp]==quoteChar )
{
@@ -436,7 +442,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
}
// Cannot have a quote embedded in a field
else
{
{
fields.clear();
return RecordInvalid;
}
@@ -465,7 +471,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
started = false;
ended = false;
}
// Whitespace is permitted before the start of a field, or
// Whitespace is permitted before the start of a field, or
// after the end..
else if( c.isSpace() )
{
@@ -475,7 +481,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
else
{
if( ended )
{
{
fields.clear();
return RecordInvalid;
}
@@ -484,7 +490,7 @@ QgsDelimitedTextFile::Status QgsDelimitedTextFile::parseQuoted( QStringList &fie
}
}
// If reached the end of the record, then add the last field...
if( started && (mMaxFields <=0 || fields.size() < mMaxFields) )
if( started && (mMaxFields <=0 || fields.size() < mMaxFields) )
{
if( ! ended ) field = field.trimmed();
fields.append(field);
@@ -35,29 +35,29 @@ class QTextStream;
* for parsing each record. The following options are supported:
* - Basic whitespace parsing. Each line in the file is treated as a record.
* Extracts all contiguous sequences of non-whitespace
* characters. Leading and trailing whitespace are ignored.
* - Regular expression parsing. Each line in the file is treated as a record.
* The string is split into fields based on a regular expression.
* - Character delimited, based on a delimiter character set, a quote character, and
* characters. Leading and trailing whitespace are ignored.
* - Regular expression parsing. Each line in the file is treated as a record.
* The string is split into fields based on a regular expression.
* - Character delimited, based on a delimiter character set, a quote character, and
* an escape character. The escape treats the next character as a part of a field.
* Fields may start and end with quote characters, in which case any non-escaped
* Fields may start and end with quote characters, in which case any non-escaped
* character within the field is treated literally, including end of line characters.
* The escape character within a string causes the next character to be read literally
* (this includes new line characters). If the escape and quote characters are the
* same, then only quote characters will be escaped (ie to include a quote in a
* (this includes new line characters). If the escape and quote characters are the
* same, then only quote characters will be escaped (ie to include a quote in a
* quoted field it is entered as two quotes. All other characters in quoted fields
* are treated literally, including newlines.
* - CSV format files - these are a special case of character delimited, in which the
* delimiter is a comma, and the quote and escape characters are double quotes (")
*
* The delimiters can be encode in and decoded from a QUrl as query items. The
* The delimiters can be encode in and decoded from a QUrl as query items. The
* items used are:
* - delimiterType, one of plain (delimiter is any of a set of characters),
* - delimiterType, one of plain (delimiter is any of a set of characters),
* regexp, csv, whitespace
* - delimiter, interpreted according to the type. For plain characters this is
* a sequence of characters. The string \t in the sequence is replaced by a tab.
* For regexp type delimiters this specifies the reqular expression.
* The field is ignored for csv and whitespace
* For regexp type delimiters this specifies the reqular expression.
* The field is ignored for csv and whitespace
* - quoteChar, optional, a single character used for quoting plain fields
* - escapeChar, optional, a single characer used for escaping (may be the same as quoteChar)
*/
@@ -66,10 +66,10 @@ class QTextStream;
// on an abstract base class in order to facilitate changing the type of the parser easily
// eg in the provider dialog

class QgsDelimitedTextFile
class QgsDelimitedTextFile
{

public:
public:

enum Status
{
@@ -91,14 +91,16 @@ class QgsDelimitedTextFile

virtual ~QgsDelimitedTextFile();

/** Set the filename
/** Set the filename
* @param filename the name of the file
*/
void setFileName( QString filename );
/** Return the filename
/** Return the filename
* @return filename the name of the file
*/
QString fileName(){ return mFileName; }
QString fileName() {
return mFileName;
}

/** Decode the parser settings from a url as a string
* @param url The url from which the delimiter and delimiterType items are read
@@ -125,7 +127,7 @@ class QgsDelimitedTextFile
/** Set the parser to use a character type delimiter.
* @param delim The field delimiter character set
* @param quote The quote character, used to define quoted fields
* @param escape The escape character used to escape quote or delim
* @param escape The escape character used to escape quote or delim
* characters.
*/
void setTypeCSV( QString delim=QString(","), QString quote=QString("\""), QString escape=QString("\"") );
@@ -136,11 +138,15 @@ class QgsDelimitedTextFile
* return an unlimited number of fields
* @param maxFields The maximum number of fields into which a record will be split
*/
void setMaxFields( int maxFields ){ mMaxFields = maxFields; }
void setMaxFields( int maxFields ) {
mMaxFields = maxFields;
}
/* Return the maximum number of fields to return
* @return maxFields The maximum number of fields to return
* @return maxFields The maximum number of fields to return
*/
int maxFields(){ return mMaxFields; }
int maxFields() {
return mMaxFields;
}

/* Set the number of header lines to skip
* @param skiplines The maximum lines to skip
@@ -149,7 +155,9 @@ class QgsDelimitedTextFile
/* Return the number of header lines to skip
* @return skiplines The maximum lines to skip
*/
int skipLines(){ return mSkipLines; }
int skipLines() {
return mSkipLines;
}

/* Set reading column names from the first record
* @param useheaders Column names will be read if true
@@ -158,15 +166,17 @@ class QgsDelimitedTextFile
/* Return the option for reading column names from the first record
* @return useheaders Column names will be read if true
*/
bool useHeader(){ return mUseHeader; }
bool useHeader() {
return mUseHeader;
}

/** Return the column names read from the header, or default names
* Col## if none defined. Will open and read the head of the file
* if required, then reset..
*/
QStringList &columnNames();

/** Reads the next record from the stream splits into string fields.
/** Reads the next record from the stream splits into string fields.
* @param fields The string list to populate with the fields
* @return status The result of trying to parse a record. RecordOk
* if read successfully, RecordEOF if reached the end of the
@@ -178,7 +188,9 @@ class QgsDelimitedTextFile
/** Return the line number of the start of the last record read
* @return linenumber The line number of the start of the record
*/
int recordLineNumber(){ return mRecordLineNumber; }
int recordLineNumber() {
return mRecordLineNumber;
}

/** Reset the file to reread from the beginning
*/
@@ -192,15 +204,21 @@ class QgsDelimitedTextFile
* or a string)
* @return def The delimiter definition string
*/
QString delimiterDefinitionString(){ return mDelimDefinition; }
QString delimiterDefinitionString() {
return mDelimDefinition;
}
/** Return the quote character
* @return quote The quoet character
*/
QString quoteChar(){ return mQuoteChar; }
QString quoteChar() {
return mQuoteChar;
}
/** Return the escape character
* @return escape The escape character
*/
QString escapeChar(){ return mEscapeChar; }
QString escapeChar() {
return mEscapeChar;
}

/** Check that provider is valid (filename and definition valid)
*
@@ -209,7 +227,7 @@ class QgsDelimitedTextFile
bool isValid();


private:
private:

/** Open the file
*
@@ -243,7 +261,7 @@ class QgsDelimitedTextFile
QString mFileName;
QFile *mFile;
QTextStream *mStream;

// Parameters common to parsers
bool mDefinitionValid;
DelimiterType mType;
@@ -260,6 +278,6 @@ class QgsDelimitedTextFile

// Information extracted from file
QStringList mColumnNames;
int mRecordLineNumber;
int mLineNumber;
int mRecordLineNumber;
};

0 comments on commit c6f678f

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