メインページ   モジュール   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TRegularExpression.hh

解説を見る。
00001 // ============================================================================
00019 // ============================================================================
00020 #ifndef __TREGULAREXPRESSION_HH
00021 #define __TREGULAREXPRESSION_HH
00022 
00023 #include "Tglobals.h"
00024 
00025 
00045 class TRegularExpression
00046 {
00047 
00048   public:
00049     // REG_EXTENDED
00050     // 拡張正規表現を使う
00051     // REG_ICASE
00052     // 英字の大文字,小文字の区別を無視する
00053     // REG_NOSUB
00054     // regexec()でパターンマッチの成功,失敗のみを返す
00055     // REG_NEWLINE
00056     // 改行文字の扱いを切り替える
00057     enum { DEFAULT = REG_EXTENDED|REG_NEWLINE, IOPTION = DEFAULT|REG_ICASE };
00058 
00059   private:
00060     Tstring thePattern;
00061     Tint theOption;
00062     Tint theNumberOfSubMatches;
00063     Tregex_t* theCompiledPattern;
00064     Tregmatch_t* theMatch;
00065     Tregmatch_t* theSubMatch;
00066 
00067   public:
00068     TRegularExpression( const Tstring& pattern, Tint option = DEFAULT );
00069     TRegularExpression( Tint option = DEFAULT, const Tstring& pattern = "" );
00070     TRegularExpression( const TRegularExpression& right );
00071     ~TRegularExpression();
00072 
00073   public:
00074     const TRegularExpression& operator=( const TRegularExpression& right );
00075     const TRegularExpression& operator=( const Tstring& right );
00076     Tbool operator==( const Tstring& right );
00077     Tbool operator!=( const Tstring& right );
00078 
00079   public:
00080     Tvoid Compile();
00081     Tint Index( const Tstring& source, Tint pos = 0 );
00082     TintList Indexes( const Tstring& source, Tint pos = 0 );
00083     Tint Size( const Tstring& source, Tint pos = 0 );
00084     TintList Sizes( const Tstring& source, Tint pos = 0 );
00085     Tstring MatchString( const Tstring& source, Tint pos = 0 );
00086     TstringList MatchStrings( const Tstring& source, Tint pos = 0 );
00087     Tbool IsMatch( const Tstring& source, Tint pos = 0 );
00088     Tint GetNumberOfMatches( const Tstring& source, Tint pos = 0 );
00089     Tstring Substitute( const Tstring& source, const Tstring& substr = "", Tint pos = 0 );
00090     Tstring SubstituteAll( const Tstring& source, const Tstring& substr = "", Tint pos = 0 );
00091     TstringList Split( const Tstring& source, Tint pos = 0 );
00092     TstringList Split( const Tstring& pattern, const Tstring& source, Tint pos = 0 );
00093     TstringList Split( const TRegularExpression& regex, const Tstring& source, Tint pos = 0 );
00094     Tstring GetSubMatch( const Tstring& source, Tint index = 0, Tint pos = 0 );
00095     TstringList GetSubMatches( const Tstring& source, Tint pos = 0 );
00096 
00097   public:
00098     const Tstring& GetPattern() const;
00099     Tint GetOption() const;
00100     Tint GetNumberOfSubMatches() const;
00101     const Tregex_t* GetCompiledPattern() const;
00102     const Tregmatch_t* GetMatch() const;
00103     const Tregmatch_t* GetSubMatch() const;
00104     Tvoid SetPattern( const Tstring& pattern );
00105     Tvoid SetOption( Tint option = DEFAULT );
00106     Tvoid IgnoreCase( Tbool stat = Ttrue );
00107 
00108   private:
00109     Tvoid free();
00110     Tint execute( const Tstring& source, Tint pos );
00111 
00112 };
00113 
00114 inline const Tstring& TRegularExpression::GetPattern() const
00115 {
00116   return thePattern;
00117 }
00118 
00119 inline Tint TRegularExpression::GetOption() const
00120 {
00121   return theOption;
00122 }
00123 
00124 inline Tint TRegularExpression::GetNumberOfSubMatches() const
00125 {
00126   return theNumberOfSubMatches;
00127 }
00128 
00129 inline const Tregex_t* TRegularExpression::GetCompiledPattern() const
00130 {
00131   return theCompiledPattern;
00132 }
00133 
00134 inline const Tregmatch_t* TRegularExpression::GetMatch() const
00135 {
00136   return theMatch;
00137 }
00138 
00139 inline const Tregmatch_t* TRegularExpression::GetSubMatch() const
00140 {
00141   return theSubMatch;
00142 }
00143 
00144 inline Tvoid TRegularExpression::SetPattern( const Tstring& pattern )
00145 {
00146   thePattern = pattern;
00147   Compile();
00148   return;
00149 }
00150 
00151 inline Tvoid TRegularExpression::SetOption( Tint option )
00152 {
00153   theOption = option;
00154   Compile();
00155   return;
00156 }
00157 
00158 inline Tvoid TRegularExpression::IgnoreCase( Tbool stat )
00159 {
00160   Tint option = theOption;
00161   if ( stat == Ttrue ) {
00162     option |= REG_ICASE;
00163   } else {
00164     option &= ~REG_ICASE;
00165   }
00166   SetOption( option );
00167   return;
00168 }
00169 
00170 #endif

CLDAQ - a Class Library for Data AcQuisition (Version 1.11.0)
Go IWAI <goiwai@users.sourceforge.jp>