edelib  2.0.0
edelib/Regex.h
00001 /*
00002  * $Id: Regex.h 2839 2009-09-28 11:36:20Z karijes $
00003  *
00004  * Regex class
00005  * Copyright (c) 2007-2009 edelib authors
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef __EDELIB_REGEX_H__
00022 #define __EDELIB_REGEX_H__
00023 
00024 #include "List.h"
00025 #include "String.h"
00026 
00027 EDELIB_NS_BEGIN
00028 
00034 enum RegexMode {
00035         RX_EXTENDED       = (1 << 1), 
00036         RX_CASELESS       = (1 << 2), 
00037         RX_DOLLAR_ENDONLY = (1 << 3), 
00038         RX_DOTALL         = (1 << 4), 
00039         RX_MULTILINE      = (1 << 5), 
00040         RX_UNGREEDY       = (1 << 6)  
00041 };
00042 
00048 enum RegexMatchMode {
00049         RX_MATCH_ANCHORED = (1 << 1), 
00050         RX_MATCH_NOTBOL   = (1 << 2), 
00051         RX_MATCH_NOTEOL   = (1 << 3), 
00052         RX_MATCH_NOTEMPTY = (1 << 4)  
00053 };
00054 
00055 #ifndef SKIP_DOCS
00056 struct RegexData;
00057 #endif
00058 
00065 struct RegexMatch {
00067         int offset;
00069         int length;
00070 };
00071 
00098 class EDELIB_API Regex {
00099 private:
00100         RegexData* data;
00101 
00102         void clear(void);
00103         E_DISABLE_CLASS_COPY(Regex)
00104 public:
00106         typedef list<RegexMatch> MatchVec;
00107 
00111         Regex();
00112 
00116         ~Regex();
00117 
00125         bool compile(const char* pattern, int m = 0);
00126 
00136         operator bool(void) const;
00137 
00150         int match(const char* str, int match_mode, int start, int len, MatchVec* matches);
00151 
00156         int match(const char* str, int match_mode = 0, MatchVec* matches = 0) 
00157         { return match(str, match_mode, 0, -1, matches); }
00158 
00167         int split(const char* str, list<String>& ls, int match_mode = 0);
00168 
00172         const char* strerror(void) const;
00173 };
00174 
00175 EDELIB_NS_END
00176 #endif