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: 6th April 2008
00008  *
00009  * Home:    http://shwild.org/
00010  *
00011  * Copyright (c) 2005-2008, 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 met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the names of Matthew Wilson and Sean Kelly nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * ////////////////////////////////////////////////////////////////////////// */
00039 
00040 
00041 #ifndef SHWILD_INCL_SRC_HPP_MATCHES
00042 #define SHWILD_INCL_SRC_HPP_MATCHES
00043 
00044 /* /////////////////////////////////////////////////////////////////////////////
00045  * Version information
00046  */
00047 
00048 #ifndef SHWILD_DOCUMENTATION_SKIP_SECTION
00049 # define SHWILD_VER_HPP_MATCHES_MAJOR       1
00050 # define SHWILD_VER_HPP_MATCHES_MINOR       1
00051 # define SHWILD_VER_HPP_MATCHES_REVISION    5
00052 # define SHWILD_VER_HPP_MATCHES_EDIT        10
00053 #endif /* !SHWILD_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* /////////////////////////////////////////////////////////////////////////////
00056  * Includes
00057  */
00058 
00059 #include <shwild/shwild.h>
00060 #include "shwild_string.hpp"    // for shwild_string_t
00061 
00062 #include <stlsoft/stlsoft.h>    /* If the compiler cannot find this, you are not using STLSoft 1.9 or later, as required. */
00063 #if !defined(_STLSOFT_VER) || \
00064    _STLSOFT_VER < 0x01091eff
00065 # error Requires STLSoft 1.9.30, or later. (www.stlsoft.org/downloads.html)
00066 #endif /* STLSoft version */
00067 
00068 /* /////////////////////////////////////////////////////////////////////////////
00069  * Namespace
00070  */
00071 
00072 #if !defined(SHWILD_NO_NAMESPACE)
00073 namespace shwild
00074 {
00075 namespace impl
00076 {
00077 #endif /* !SHWILD_NO_NAMESPACE */
00078 
00079 /* /////////////////////////////////////////////////////////////////////////////
00080  * Functions
00081  */
00082 
00083 char *STLSOFT_CDECL shwild_strchr(const char *, int);
00084 char *STLSOFT_CDECL shwild_strichr(const char *, int);
00085 char *STLSOFT_CDECL shwild_strstr(const char *, const char *);
00086 char *STLSOFT_CDECL shwild_stristr(const char *, const char *);
00087 int STLSOFT_CDECL   shwild_strncmp(const char *, const char *, size_t);
00088 int STLSOFT_CDECL   shwild_strnicmp(const char *, const char *, size_t);
00089 
00090 /* /////////////////////////////////////////////////////////////////////////////
00091  * Classes
00092  */
00093 
00095 class Match
00096 {
00097 public:
00098     virtual ~Match() = 0;
00099 
00101     virtual void setNext(Match *next) = 0;
00102 
00103 public:
00108     virtual bool match(char const *first, char const *last) const = 0;
00114     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const = 0;
00115 };
00116 
00118 class MatchWild
00119     : public Match
00120 {
00121 public:
00122     typedef MatchWild   class_type;
00123 
00124 public:
00125     explicit MatchWild(unsigned flags);
00126     virtual ~MatchWild();
00127 
00128     virtual void setNext(Match *next);
00129 public:
00130     virtual bool match(char const *first, char const *last) const;
00131     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00132 private:
00133     Match   *m_next;
00134 private:
00135     class_type &operator =(class_type const &);
00136 };
00137 
00139 class MatchWild1
00140     : public Match
00141 {
00142 public:
00143     typedef MatchWild1  class_type;
00144 
00145 public:
00146     explicit MatchWild1(unsigned flags);
00147     virtual ~MatchWild1();
00148 
00149     virtual void setNext(Match *next);
00150 public:
00151     virtual bool match(char const *first, char const *last) const;
00152     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00153 private:
00154     Match   *m_next;
00155 private:
00156     class_type &operator =(class_type const &);
00157 };
00158 
00160 class MatchRange
00161     : public Match
00162 {
00163 public:
00164     typedef MatchRange  class_type;
00165 
00166 public:
00167     MatchRange(size_t len, char const *chars, unsigned flags);
00168     virtual ~MatchRange();
00169 
00170     virtual void setNext(Match *next);
00171 public:
00172     virtual bool match(char const *first, char const *last) const;
00173     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00174 protected:
00175     bool matchContents(char ch) const;
00176 protected:
00177     Match                   *m_next;
00178     const shwild_string_t   m_chars;
00179     const unsigned          m_flags;
00180 private:
00181     class_type &operator =(class_type const &);
00182 };
00183 
00185 class MatchNotRange
00186     : public MatchRange
00187 {
00188 public:
00189     typedef MatchRange      parent_class_type;
00190     typedef MatchNotRange   class_type;
00191 
00192 public:
00193     MatchNotRange(size_t len, char const *chars, unsigned flags);
00194     virtual ~MatchNotRange();
00195 
00196 public:
00197     virtual bool match(char const *first, char const *last) const;
00198 
00199 private:
00200     class_type &operator =(class_type const &);
00201 };
00202 
00204 class MatchEnd
00205     : public Match
00206 {
00207 public:
00208     typedef MatchEnd    class_type;
00209 
00210 public:
00211     explicit MatchEnd(unsigned flags);
00212     virtual ~MatchEnd();
00213 
00214     virtual void setNext(Match *next);
00215 public:
00216     virtual bool match(char const *first, char const *last) const;
00217     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00218 private:
00219     Match   *m_next;
00220 private:
00221     class_type &operator =(class_type const &);
00222 };
00223 
00225 class MatchLiteral
00226     : public Match
00227 {
00228 public:
00229     typedef MatchLiteral    class_type;
00230 
00231 public:
00232     MatchLiteral(size_t cchContents, char const *contents, unsigned flags);
00233     virtual ~MatchLiteral();
00234 
00235     virtual void setNext(Match *next);
00236 public:
00237     virtual bool match(char const *first, char const *last) const;
00238     virtual char const *nextSub(char const *first, char const *last, size_t *nextLen) const;
00239 private:
00240     Match                   *m_next;
00241     const shwild_string_t   m_contents;
00242     const unsigned          m_flags;
00243 private:
00244     class_type &operator =(class_type const &);
00245 };
00246 
00247 /* /////////////////////////////////////////////////////////////////////////////
00248  * Namespace
00249  */
00250 
00251 #if !defined(SHWILD_NO_NAMESPACE)
00252 } // namespace impl
00253 
00254 } // namespace shwild
00255 #endif /* !SHWILD_NO_NAMESPACE */
00256 
00257 /* ////////////////////////////////////////////////////////////////////////// */
00258 
00259 #endif /* !SHWILD_INCL_SRC_HPP_MATCHES */
00260 
00261 /* ////////////////////////////////////////////////////////////////////////// */

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