|
sficl
Current version
|
A record consisting of string fields separated by a delimiter. More...
#include <SfiDelimitedRecordSTD.h>

Public Member Functions | |
| SfiDelimitedRecordSTD (const char *str=0, char delimiter= ',') | |
| SfiDelimitedRecordSTD (const SfiDelimitedRecordSTD &rec) | |
| ~SfiDelimitedRecordSTD () | |
| SfiDelimitedRecordSTD & | operator= (const SfiDelimitedRecordSTD &rec) |
| Copies all data from rec. More... | |
| SfiDelimitedRecordSTD & | operator= (const char *str) |
| Sets the record to a new string (makes a copy). More... | |
| int | size () const |
| Returns the number of fields in the record. More... | |
| const char * | operator[] (int i) const |
| Returns a pointer to the i-th field or an empty string if there are fewer than i fields. More... | |
| int | length (int n) const |
| Returns the length of the n-th field (zero-based) or -1 if there is no such field. More... | |
| void | setDelimiter (char delim) |
| Sets the delimiter character and re-splits the string. More... | |
| int | offset (int n) const |
| Returns the offset of the n-th field (zero-based) in the original string or -1 if there is no such field. More... | |
| int | split (char *buf, int n) |
Splits the buf in-place, overwriting delimiters with null characters. More... | |
| const char * | get (int i) const |
| Returns a pointer to the i-th field of a split string - for use with split(char*, int) only!!! If the index i is outside the range of valid fields, a pointer to an empty string is returned. More... | |
Protected Member Functions | |
| int | split () |
| Returns the number of fields in the record. Delimiters inside double quotes are ignored. More... | |
| void | clear () |
| Clears the record. More... | |
Protected Attributes | |
| string | m_buffer |
| Buffer with a modified string for fast retrieval. More... | |
| char | m_delimiter |
| SfiVectorLite< int > | m_offsets |
| SfiVectorLite< int > | m_lengths |
| char * | m_sptr |
| const char | m_nullChar |
A record consisting of string fields separated by a delimiter.
The functionality is similar to the split() function in Perl or the way awk treats lines. There are two ways of using this class. The first makes a copy of the string. In this case, the class should be initialized with a string and the resulting fields should be accessed by the operator[]. The second way is to pass the line to the class as a writable buffer in the split function and access the resulting fields via the get() method. In this case, the split occurs in-place, i.e., without a copy or memory allocation, but the delimiters in the buffer are overwritten with null characters. The get() method should not be called after the buffer was subsequently changed by the caller.
Definition at line 52 of file SfiDelimitedRecordSTD.h.
|
inlineexplicit |
Definition at line 64 of file SfiDelimitedRecordSTD.h.
References m_lengths, m_offsets, and SfiVectorLite< T >::reserve().
|
inline |
Definition at line 70 of file SfiDelimitedRecordSTD.h.
|
inline |
Definition at line 74 of file SfiDelimitedRecordSTD.h.
|
inlineprotected |
Clears the record.
Definition at line 218 of file SfiDelimitedRecordSTD.h.
References SfiVectorLite< T >::clear(), m_buffer, m_lengths, m_offsets, and m_sptr.
Referenced by operator=(), and split().
|
inline |
Returns a pointer to the i-th field of a split string - for use with split(char*, int) only!!! If the index i is outside the range of valid fields, a pointer to an empty string is returned.
Definition at line 178 of file SfiDelimitedRecordSTD.h.
References m_nullChar, m_offsets, m_sptr, SfiVectorLite< T >::size(), and size().
|
inline |
Returns the length of the n-th field (zero-based) or -1 if there is no such field.
Definition at line 121 of file SfiDelimitedRecordSTD.h.
References m_lengths, m_offsets, and SfiVectorLite< T >::size().
|
inline |
Returns the offset of the n-th field (zero-based) in the original string or -1 if there is no such field.
Definition at line 133 of file SfiDelimitedRecordSTD.h.
References m_offsets, and SfiVectorLite< T >::size().
|
inline |
Copies all data from rec.
Definition at line 77 of file SfiDelimitedRecordSTD.h.
References m_buffer, m_delimiter, m_lengths, m_offsets, and m_sptr.
|
inline |
Sets the record to a new string (makes a copy).
Access to the resulting split string is via the operator[].
Definition at line 89 of file SfiDelimitedRecordSTD.h.
|
inline |
Returns a pointer to the i-th field or an empty string if there are fewer than i fields.
Definition at line 110 of file SfiDelimitedRecordSTD.h.
References m_buffer, m_nullChar, m_offsets, SfiVectorLite< T >::size(), and size().
|
inline |
Sets the delimiter character and re-splits the string.
Definition at line 127 of file SfiDelimitedRecordSTD.h.
References m_delimiter.
|
inline |
Returns the number of fields in the record.
Definition at line 104 of file SfiDelimitedRecordSTD.h.
References m_offsets, and SfiVectorLite< T >::size().
Referenced by get(), and operator[]().
|
inline |
Splits the buf in-place, overwriting delimiters with null characters.
Returns the number of fields in the buf. Delimiters inside double quotes are ignored. n is the size of string in buf, excluding the terminating null. Access to fields is provided by get(int).
Definition at line 142 of file SfiDelimitedRecordSTD.h.
References SfiVectorLite< T >::clear(), clear(), m_delimiter, m_lengths, m_offsets, m_sptr, SfiVectorLite< T >::push_back(), and SfiVectorLite< T >::size().
|
inlineprotected |
Returns the number of fields in the record. Delimiters inside double quotes are ignored.
Definition at line 191 of file SfiDelimitedRecordSTD.h.
References SfiVectorLite< T >::clear(), m_buffer, m_delimiter, m_lengths, m_offsets, SfiVectorLite< T >::push_back(), and SfiVectorLite< T >::size().
Referenced by operator=().
|
protected |
Buffer with a modified string for fast retrieval.
Definition at line 56 of file SfiDelimitedRecordSTD.h.
Referenced by clear(), operator=(), operator[](), and split().
|
protected |
Definition at line 57 of file SfiDelimitedRecordSTD.h.
Referenced by operator=(), setDelimiter(), and split().
|
protected |
Definition at line 59 of file SfiDelimitedRecordSTD.h.
Referenced by clear(), length(), operator=(), SfiDelimitedRecordSTD(), and split().
|
protected |
Definition at line 61 of file SfiDelimitedRecordSTD.h.
Referenced by get(), and operator[]().
|
protected |
Definition at line 58 of file SfiDelimitedRecordSTD.h.
Referenced by clear(), get(), length(), offset(), operator=(), operator[](), SfiDelimitedRecordSTD(), size(), and split().
|
protected |
Definition at line 60 of file SfiDelimitedRecordSTD.h.
Referenced by clear(), get(), operator=(), and split().
1.8.5