blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005 Novell, Inc. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00025 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00027 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00028 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *******************************************************************************/ 00034 #ifndef BLOCXX_POSIX_REGEX_HPP_INCLUDE_GUARD_HPP_ 00035 #define BLOCXX_POSIX_REGEX_HPP_INCLUDE_GUARD_HPP_ 00036 #include "blocxx/BLOCXX_config.h" 00037 #include "blocxx/RegExException.hpp" 00038 00039 #ifdef BLOCXX_HAVE_REGEX 00040 #include "blocxx/String.hpp" 00041 #include "blocxx/Array.hpp" 00042 00043 #ifdef BLOCXX_HAVE_REGEX_H 00044 #include <regex.h> 00045 00046 namespace BLOCXX_NAMESPACE 00047 { 00048 00058 class BLOCXX_COMMON_API PosixRegEx 00059 { 00060 public: 00067 typedef regmatch_t match_t; 00068 00072 typedef blocxx::Array<match_t> MatchArray; 00073 00077 PosixRegEx(); 00078 00088 PosixRegEx(const String ®ex, int cflags = REG_EXTENDED); 00089 00098 PosixRegEx(const PosixRegEx &ref); 00099 00103 ~PosixRegEx(); 00104 00112 PosixRegEx& operator = (const PosixRegEx &ref); 00113 00114 00136 bool compile(const String ®ex, 00137 int cflags = REG_EXTENDED); 00138 00145 int errorCode(); 00146 00153 String errorString() const; 00154 00155 00159 String patternString() const; 00160 00164 int compileFlags() const; 00165 00169 bool isCompiled() const; 00170 00171 00237 bool execute(MatchArray &sub, 00238 const String &str, 00239 size_t index = 0, 00240 size_t count = 0, 00241 int eflags = 0); 00242 00269 StringArray capture(const String &str, 00270 size_t index = 0, 00271 size_t count = 0, 00272 int eflags = 0); 00273 00309 String replace(const String &str, 00310 const String &rep, 00311 bool global = false, 00312 int eflags = 0); 00313 00345 StringArray split (const String &str, 00346 bool empty = false, 00347 int eflags = 0); 00348 00375 StringArray grep (const StringArray &src, 00376 int eflags = 0); 00377 00403 bool match (const String &str, 00404 size_t index = 0, 00405 int eflags = 0) const; 00406 00407 private: 00408 bool compiled; 00409 int m_flags; 00410 mutable int m_ecode; 00411 mutable String m_error; 00412 String m_rxstr; 00413 regex_t m_regex; 00414 }; 00415 00416 } // End of BLOCXX_NAMESPACE 00417 00418 #endif // BLOCXX_HAVE_REGEX_H 00419 #endif // BLOCXX_HAVE_REGEX 00420 00421 #endif // BLOCXX_POSIX_REGEX_HPP_INCLUDE_GUARD_HPP_ 00422 /* vim: set ts=8 sts=8 sw=8 ai noet: */ 00423