blocxx

PerlRegEx.hpp

Go to the documentation of this file.
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_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00035 #define   BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00036 #include "blocxx/BLOCXX_config.h"
00037 #include "blocxx/RegExException.hpp"
00038 
00039 #ifdef   BLOCXX_HAVE_PCRE
00040 #include "blocxx/String.hpp"
00041 #include "blocxx/Array.hpp"
00042 
00043 #ifdef   BLOCXX_HAVE_PCRE_H
00044 #include <pcre.h>
00045 
00046 namespace BLOCXX_NAMESPACE
00047 {
00048 
00059 class BLOCXX_COMMON_API PerlRegEx
00060 {
00061 public:
00067    typedef blocxx::Array<int>              MatchVector;
00068 
00070    struct match_t {
00071       int rm_so; 
00072       int rm_eo; 
00073    };
00074 
00076    typedef blocxx::Array<match_t>          MatchArray;
00077 
00081    PerlRegEx();
00082 
00090    PerlRegEx(const String &regex, int cflags = 0);
00091 
00100    PerlRegEx(const PerlRegEx &ref);
00101 
00105    ~PerlRegEx();
00106 
00114    PerlRegEx&          operator = (const PerlRegEx &ref);
00115 
00145    bool            compile(const String &regex,
00146                            int          cflags = 0);
00147 
00161    int             errorCode();
00162 
00169    String          errorString() const;
00170 
00174    String          patternString() const;
00175 
00179    int             compileFlags() const;
00180 
00184    bool            isCompiled() const;
00185 
00272    bool            execute(MatchVector   &sub,
00273                            const String  &str,
00274                            size_t index = 0,
00275                            size_t count = 0,
00276                            int   eflags = 0);
00277    bool            execute(MatchArray    &sub,
00278                            const String  &str,
00279                            size_t index = 0,
00280                            size_t count = 0,
00281                            int   eflags = 0);
00282    /* @} */
00283 
00309    StringArray     capture(const String &str,
00310                            size_t index = 0,
00311                            size_t count = 0,
00312                            int   eflags = 0);
00313 
00348    String          replace(const String &str,
00349                            const String &rep,
00350                            bool  global = false,
00351                            int   eflags = 0);
00352 
00383    StringArray     split  (const String &str,
00384                            bool  empty  = false,
00385                            int   eflags = 0);
00386 
00412    StringArray     grep   (const StringArray &src,
00413                            int   eflags = 0);
00414 
00440    bool            match  (const String  &str,
00441                            size_t index = 0,
00442                            int   eflags = 0) const;
00443 
00444 private:
00445    pcre           *m_pcre;
00446    int             m_flags;
00447    mutable int     m_ecode;
00448    mutable String  m_error;
00449    String          m_rxstr;
00450 };
00451 
00452 } // End of BLOCXX_NAMESPACE
00453 
00454 #endif // BLOCXX_HAVE_PCRE_H
00455 #endif // BLOCXX_HAVE_PCRE
00456 
00457 #endif // BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00458 /* vim: set ts=8 sts=8 sw=8 ai noet: */
00459