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 
00273    bool            execute(MatchVector   &sub,
00274                            const String  &str,
00275                            size_t index = 0,
00276                            size_t count = 0,
00277                            int   eflags = 0);
00278    bool            execute(MatchArray    &sub,
00279                            const String  &str,
00280                            size_t index = 0,
00281                            size_t count = 0,
00282                            int   eflags = 0);
00283    /* @} */
00284 
00310    StringArray     capture(const String &str,
00311                            size_t index = 0,
00312                            size_t count = 0,
00313                            int   eflags = 0);
00314 
00349    String          replace(const String &str,
00350                            const String &rep,
00351                            bool  global = false,
00352                            int   eflags = 0);
00353 
00384    StringArray     split  (const String &str,
00385                            bool  empty  = false,
00386                            int   eflags = 0);
00387 
00413    StringArray     grep   (const StringArray &src,
00414                            int   eflags = 0);
00415 
00441    bool            match  (const String  &str,
00442                            size_t index = 0,
00443                            int   eflags = 0) const;
00444 
00445 private:
00446    pcre           *m_pcre;
00447    int             m_flags;
00448    mutable int     m_ecode;
00449    mutable String  m_error;
00450    String          m_rxstr;
00451 };
00452 
00453 } // End of BLOCXX_NAMESPACE
00454 
00455 #endif // BLOCXX_HAVE_PCRE_H
00456 #endif // BLOCXX_HAVE_PCRE
00457 
00458 #endif // BLOCXX_PERL_REGEX_HPP_INCLUDE_GUARD_HPP_
00459 /* vim: set ts=8 sts=8 sw=8 ai noet: */
00460 

Generated on Fri Jun 16 15:39:08 2006 for blocxx by  doxygen 1.4.6