Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

P:/Dev2/freelibs/b64/1.4/src/shwild/matches.hpp

00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:    src/matches.hpp
00003  *
00004  * Purpose: Definition of Match interface class and concrete match classes
00005  *
00006  * Created: 17th June 2005
00007  * Updated: 20th December 2011
00008  *
00009  * Home:    http://shwild.org/
00010  *
00011  * Copyright (c) 2005-2011, Matthew Wilson and Sean Kelly
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without 
00015  * modification, are permitted provided that the following conditions are
00016  * met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice,
00019  *   this list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright
00021  *   notice, this list of conditions and the following disclaimer in the
00022  *   documentation and/or other materials provided with the distribution.
00023  * - Neither the names of Matthew Wilson and Sean Kelly nor the names of
00024  *   any contributors may be used to endorse or promote products derived
00025  *   from this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00028  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00029  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00031  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////// */
00040 
00041 
00042 #ifndef SHWILD_INCL_SRC_HPP_MATCHES
00043 #define SHWILD_INCL_SRC_HPP_MATCHES
00044 
00045 /* /////////////////////////////////////////////////////////////////////////
00046  * Includes
00047  */
00048 
00049 #include <shwild/shwild.h>
00050 #include "shwild_stlsoft.h"
00051 #include "shwild_string.hpp"    // for shwild_string_t
00052 
00053 /* /////////////////////////////////////////////////////////////////////////
00054  * Namespace
00055  */
00056 
00057 #if !defined(SHWILD_NO_NAMESPACE)
00058 namespace shwild
00059 {
00060 namespace impl
00061 {
00062 #endif /* !SHWILD_NO_NAMESPACE */
00063 
00064 /* /////////////////////////////////////////////////////////////////////////
00065  * Functions
00066  */
00067 
00068 char *STLSOFT_CDECL shwild_strchr(const char *, int);
00069 char *STLSOFT_CDECL shwild_strichr(const char *, int);
00070 char *STLSOFT_CDECL shwild_strstr(const char *, const char *);
00071 char *STLSOFT_CDECL shwild_stristr(const char *, const char *);
00072 int STLSOFT_CDECL   shwild_strncmp(const char *, const char *, size_t);
00073 int STLSOFT_CDECL   shwild_strnicmp(const char *, const char *, size_t);
00074 
00075 /* /////////////////////////////////////////////////////////////////////////
00076  * Classes
00077  */
00078 
00080 class Match
00081 {
00082 public:
00083     virtual ~Match() = 0;
00084 
00086     virtual void setNext(Match *next) = 0;
00087 
00088 public:
00093     virtual bool match(char const *first, char const *last) const = 0;
00099     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const = 0;
00100 };
00101 
00103 class MatchWild
00104     : public Match
00105 {
00106 public:
00107     typedef MatchWild   class_type;
00108 
00109 public:
00110     explicit MatchWild(unsigned flags);
00111     virtual ~MatchWild();
00112 
00113     virtual void setNext(Match *next);
00114 public:
00115     virtual bool match(char const *first, char const *last) const;
00116     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00117 private:
00118     Match   *m_next;
00119 private:
00120     class_type &operator =(class_type const &);
00121 };
00122 
00124 class MatchWild1
00125     : public Match
00126 {
00127 public:
00128     typedef MatchWild1  class_type;
00129 
00130 public:
00131     explicit MatchWild1(unsigned flags);
00132     virtual ~MatchWild1();
00133 
00134     virtual void setNext(Match *next);
00135 public:
00136     virtual bool match(char const *first, char const *last) const;
00137     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00138 private:
00139     Match   *m_next;
00140 private:
00141     class_type &operator =(class_type const &);
00142 };
00143 
00145 class MatchRange
00146     : public Match
00147 {
00148 public:
00149     typedef MatchRange  class_type;
00150 
00151 public:
00152     MatchRange(size_t len, char const *chars, unsigned flags);
00153     virtual ~MatchRange();
00154 
00155     virtual void setNext(Match *next);
00156 public:
00157     virtual bool match(char const *first, char const *last) const;
00158     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00159 protected:
00160     bool matchContents(char ch) const;
00161 protected:
00162     Match                   *m_next;
00163     const shwild_string_t   m_chars;
00164     const unsigned          m_flags;
00165 private:
00166     class_type &operator =(class_type const &);
00167 };
00168 
00170 class MatchNotRange
00171     : public MatchRange
00172 {
00173 public:
00174     typedef MatchRange      parent_class_type;
00175     typedef MatchNotRange   class_type;
00176 
00177 public:
00178     MatchNotRange(size_t len, char const *chars, unsigned flags);
00179     virtual ~MatchNotRange();
00180 
00181 public:
00182     virtual bool match(char const *first, char const *last) const;
00183 
00184 private:
00185     class_type &operator =(class_type const &);
00186 };
00187 
00189 class MatchEnd
00190     : public Match
00191 {
00192 public:
00193     typedef MatchEnd    class_type;
00194 
00195 public:
00196     explicit MatchEnd(unsigned flags);
00197     virtual ~MatchEnd();
00198 
00199     virtual void setNext(Match *next);
00200 public:
00201     virtual bool match(char const *first, char const *last) const;
00202     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00203 private:
00204     Match   *m_next;
00205 private:
00206     class_type &operator =(class_type const &);
00207 };
00208 
00210 class MatchLiteral
00211     : public Match
00212 {
00213 public:
00214     typedef MatchLiteral    class_type;
00215 
00216 public:
00217     MatchLiteral(size_t cchContents, char const *contents, unsigned flags);
00218     virtual ~MatchLiteral();
00219 
00220     virtual void setNext(Match *next);
00221 public:
00222     virtual bool match(char const *first, char const *last) const;
00223     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00224 private:
00225     Match                   *m_next;
00226     const shwild_string_t   m_contents;
00227     const unsigned          m_flags;
00228 private:
00229     class_type &operator =(class_type const &);
00230 };
00231 
00232 /* /////////////////////////////////////////////////////////////////////////
00233  * Namespace
00234  */
00235 
00236 #if !defined(SHWILD_NO_NAMESPACE)
00237 } // namespace impl
00238 
00239 } // namespace shwild
00240 #endif /* !SHWILD_NO_NAMESPACE */
00241 
00242 /* ////////////////////////////////////////////////////////////////////// */
00243 
00244 #endif /* !SHWILD_INCL_SRC_HPP_MATCHES */
00245 
00246 /* ////////////////////////////////////////////////////////////////////// */

b64 Library documentation © Synesis Software Pty Ltd, 2004-2012