00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 rexp.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: rexp.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00031 00032 #ifndef __REXP_H__ 00033 #define __REXP_H__ 00034 00035 #include "common.h" 00036 #include <sys/types.h> 00037 #include <regex.h> 00038 00039 #define DEFAULT_NMATCH 10 00040 00041 class Matcher; 00042 00043 class RExp : public zmm::Object 00044 { 00045 public: 00046 RExp(); 00047 virtual ~RExp(); 00048 void compile(zmm::String pattern, int flags = 0); 00049 void compile(zmm::String pattern, const char *flags); 00050 zmm::Ref<Matcher> matcher(zmm::String text, int nmatch = DEFAULT_NMATCH); 00051 zmm::Ref<Matcher> match(zmm::String text, int nmatch = DEFAULT_NMATCH); 00052 bool matches(zmm::String text); 00053 zmm::String getPattern(); 00054 protected: 00055 bool isCompiled; 00056 zmm::String pattern; 00057 regex_t regex; 00058 00059 friend class Matcher; 00060 }; 00061 00062 00063 class Matcher : public zmm::Object 00064 { 00065 public: 00066 virtual ~Matcher(); 00067 zmm::String group(int i); 00068 bool next(); 00069 bool matches(); 00070 protected: 00071 Matcher(zmm::Ref<RExp> rexp, zmm::String text, int nmatch); 00072 protected: 00073 zmm::Ref<RExp> rexp; 00074 zmm::String text; 00075 char *ptr; 00076 int nmatch; 00077 regmatch_t *pmatch; 00078 00079 friend class RExp; 00080 }; 00081 00082 00083 #endif // __REXP_H__
1.6.1