クラス テンプレート langedge::XSVParser< SEPARATOR, InputIteratorT >

CSV/TSV データの解析クラス. [詳細]

#include <xsvparser.hpp>

langedge::XSVParser< SEPARATOR, InputIteratorT >のコラボレーション図

Collaboration graph
[凡例]
すべてのメンバ一覧

Public 型

typedef IteratorCharTypeExtractor<
InputIteratorT >::CharType 
CharT
typedef std::basic_string<
CharT
StringT

Public メソッド

 XSVParser ()
 コンストラクタ
bool parse (InputIteratorT begin, InputIteratorT end)
 CSV/TSV データを解析し、値を取得する.
const std::vector< StringT > & getValues () const
 解析結果の値を格納した文字列ベクタを得る.
bool full () const
 parse() の結果、1列分の値をすべて取得できたか.
bool stopped () const
 parse() の結果、1列分の値をすべて取得できたか.
bool succeeded () const
 parse() は成功したか.
bool failed () const
 parse() は失敗したか.
size_t getLength () const
 直前の parse() の呼び出しで処理された文字数を返す.
size_t getLines () const
 これまで処理された行数を返す.
InputIteratorT getNextIterator () const
 直前の parse() の呼び出しで処理を終了した位置を示す入力反復子を返す.
void clearError ()
 エラー状態をクリアする.

説明

template<int SEPARATOR, class InputIteratorT>
class langedge::XSVParser< SEPARATOR, InputIteratorT >

CSV/TSV データの解析クラス.

入力反復子 (InputIteratorT) で指定された範囲のCSV (Comma Separated Values) または TSV (Tab Separated Values) データを解析し、 カンマまたはタブで区切られた各値を内部の文字列ベクタに格納するメソッド parse() を提供する。

テンプレートパラメータの SEPARATOR の値が ',' か '\t' かによって、 CSV/TSV のどちらを対象にするかが決定される。

例:

xsvparser_sample.cpp.


型定義

template<int SEPARATOR, class InputIteratorT>
typedef IteratorCharTypeExtractor<InputIteratorT>::CharType langedge::XSVParser< SEPARATOR, InputIteratorT >::CharT
 

template<int SEPARATOR, class InputIteratorT>
typedef std::basic_string<CharT> langedge::XSVParser< SEPARATOR, InputIteratorT >::StringT
 


コンストラクタとデストラクタ

template<int SEPARATOR, class InputIteratorT>
langedge::XSVParser< SEPARATOR, InputIteratorT >::XSVParser  )  [inline]
 

コンストラクタ


関数

template<int SEPARATOR, class InputIteratorT>
bool langedge::XSVParser< SEPARATOR, InputIteratorT >::parse InputIteratorT  begin,
InputIteratorT  end
[inline]
 

CSV/TSV データを解析し、値を取得する.

CSV (Comma Separated Value) または TSV (Tab Separated Value) データを解析し、 カンマで区切られた値を内部の文字列ベクタに格納する。 文字列ベクタは、getValues() によって取得できる。

解析対象となる CSV/TSVデータは、2つの入力反復子によって指定される。 CSV/TSVファイルを直接解析するのであれば、istreambuf_iterator を入力反復子として 使用することができる。あるいは、getline() で1行ずつバッファに読み出して、 parse( buffer, buffer+strlen(buffer) ); のような呼び出しもできる。

parse() は、入力反復子が改行コード位置または end 位置に到達した時に、 そこで解析を終了する。 ただし、改行コード位置がダブルクォートで囲まれた値の処理中であった場合は、 そのまま処理が続行される。
end 位置がダブルクォートで囲まれた値の処理中であった場合、 そこで処理を終了するが full() あるいは stopped() は false を返す。 それ以外の場合は、full() あるいは stopped() は true を返す。

処理の終了位置 (すなわち次回解析の開始位置) は、getNextIterator() によって取得することができる。

引数:
begin CSV/TSVデータの開始位置を示す入力反復子
end CSV/TSVデータの終了位置を示す入力反復子
戻り値:
入力データにエラーがなかったか (succeeded() の返す値と同じ)

template<int SEPARATOR, class InputIteratorT>
const std::vector<StringT>& langedge::XSVParser< SEPARATOR, InputIteratorT >::getValues  )  const [inline]
 

解析結果の値を格納した文字列ベクタを得る.

戻り値:
文字列ベクタ

template<int SEPARATOR, class InputIteratorT>
bool langedge::XSVParser< SEPARATOR, InputIteratorT >::full  )  const [inline]
 

parse() の結果、1列分の値をすべて取得できたか.

戻り値:
true 1列分の値をすべて取得できた
false parse() に渡された反復子で指定された範囲のデータは、 途中で終わっている。たとえば、ダブルクォートが閉じていない。
覚え書き:
stopped() と同じ。
full() == true であっても、反復子で指定された範囲のデータを すべて処理したとは限らないことに注意。getLength() を見よ。

template<int SEPARATOR, class InputIteratorT>
bool langedge::XSVParser< SEPARATOR, InputIteratorT >::stopped  )  const [inline]
 

parse() の結果、1列分の値をすべて取得できたか.

戻り値:
true 1列分の値をすべて取得できた
false parse() に渡された反復子で指定された範囲のデータは、 途中で終わっている。たとえば、ダブルクォートが閉じていない。
覚え書き:
full() と同じ。
stopped() == true であっても、反復子で指定された範囲のデータを すべて処理したとは限らないことに注意。getLength() を見よ。

template<int SEPARATOR, class InputIteratorT>
bool langedge::XSVParser< SEPARATOR, InputIteratorT >::succeeded  )  const [inline]
 

parse() は成功したか.

戻り値:
true 入力の CSV/TSVデータにエラーがなかった
false 入力の CSV/TSVデータにエラーがあった
覚え書き:
!failed() に同じ。
succeeded() == true であっても full() == true とは限らないことに注意。

template<int SEPARATOR, class InputIteratorT>
bool langedge::XSVParser< SEPARATOR, InputIteratorT >::failed  )  const [inline]
 

parse() は失敗したか.

戻り値:
true 入力の CSV/TSVデータにエラーがあった
false 入力の CSV/TSVデータにエラーがなかった
覚え書き:
!succeeded() に同じ。

template<int SEPARATOR, class InputIteratorT>
size_t langedge::XSVParser< SEPARATOR, InputIteratorT >::getLength  )  const [inline]
 

直前の parse() の呼び出しで処理された文字数を返す.

template<int SEPARATOR, class InputIteratorT>
size_t langedge::XSVParser< SEPARATOR, InputIteratorT >::getLines  )  const [inline]
 

これまで処理された行数を返す.

エラーが生じた行番号は、getLines() + 1 となる。

template<int SEPARATOR, class InputIteratorT>
InputIteratorT langedge::XSVParser< SEPARATOR, InputIteratorT >::getNextIterator  )  const [inline]
 

直前の parse() の呼び出しで処理を終了した位置を示す入力反復子を返す.

たとえば、入力反復子として istreambuf_iterator などを使用している場合は、 次の parse() の呼び出しには、getNextIterator() の返す反復子を用いるとよい。

戻り値:
次の入力位置を示す入力反復子

template<int SEPARATOR, class InputIteratorT>
void langedge::XSVParser< SEPARATOR, InputIteratorT >::clearError  )  [inline]
 

エラー状態をクリアする.

入力のCSV/TSVデータに誤りがあって、エラーが返った場合、解析処理を続行するには、 本メソッドを呼んでそのエラー状態をクリアする必要がある。
本メソッドが呼ばれると、次の改行コードまで入力が読み飛ばされる。


このクラスの説明は次のファイルから生成されました:
LangEdge ライブラリに対してFri May 6 22:43:04 2005に生成されました。  doxygen 1.4.2