modules/up/src/rpsl/rpsl/regexp.cc

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. dup
  2. dup
  3. dup
  4. dup
  5. dup
  6. dup
  7. dup
  8. dup

   1 //  $Id: regexp.cc,v 1.1.1.1 2000/03/10 16:32:24 engin Exp $
   2 //
   3 //  Copyright (c) 1994 by the University of Southern California
   4 //  All rights reserved.
   5 //
   6 //  Permission to use, copy, modify, and distribute this software and its
   7 //  documentation in source and binary forms for lawful non-commercial
   8 //  purposes and without fee is hereby granted, provided that the above
   9 //  copyright notice appear in all copies and that both the copyright
  10 //  notice and this permission notice appear in supporting documentation,
  11 //  and that any documentation, advertising materials, and other materials
  12 //  related to such distribution and use acknowledge that the software was
  13 //  developed by the University of Southern California, Information
  14 //  Sciences Institute. The name of the USC may not be used to endorse or
  15 //  promote products derived from this software without specific prior
  16 //  written permission.
  17 //
  18 //  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
  19 //  REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
  20 //  PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  21 //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  22 //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
  23 //  TITLE, AND NON-INFRINGEMENT.
  24 //
  25 //  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
  26 //  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
  27 //  OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
  28 //  OR PERFORMANCE OF THIS SOFTWARE.
  29 //
  30 //  Questions concerning this software should be directed to 
  31 //  ratoolset@isi.edu.
  32 //
  33 //  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
  34 
  35 #include "config.h"
  36 
  37 #include "regexp.hh"
  38 #include <cstring>
  39 #include "symbols.hh"
  40 
  41 // Static members
  42 int regexp_symbol::MIN_AS = 0;
  43 int regexp_symbol::MAX_AS = RANGE_TOP;
  44 
  45 ////////////////////////////// output ////////////////////
  46 
  47 ostream& operator<<(ostream& os, regexp_symbol& rs) {
  48    static RangeList::Range zero_to_zero(0, 0);
  49 
  50    int put_brackets = 0;
  51 
  52    if (rs.asSets.empty() && ! rs.asnumbers.universal()
  53        && rs.asnumbers.contains(zero_to_zero)) {
  54       rs.complemented = ! rs.complemented;
  55       rs.asnumbers.complement();
  56    }
  57 
  58    if (rs.complemented 
  59        || ! ((rs.asnumbers.is_singleton() && rs.asSets.length() == 0)
  60              || (rs.asnumbers.empty() && rs.asSets.length() == 1))) {
  61       put_brackets = 1;
  62       os << "[";
  63       if (rs.complemented)
  64          os << "^";
  65    }
  66 
  67    if (!rs.asnumbers.empty() || rs.asSets.empty())
  68       os << rs.asnumbers;
  69 
  70    for (Pix p = rs.asSets.first(); p; rs.asSets.next(p))
  71       os << " " << rs.asSets(p);
  72 
  73    if (put_brackets)
  74       os << "]";
  75 }
  76 
  77 ostream& operator<<(ostream& os, const regexp& r) {
  78    if (typeid(r) == typeid(regexp_bol))
  79       os << "^";
  80    else if (typeid(r) == typeid(regexp_eol))
  81       os << "$";
  82    else if (typeid(r) == typeid(regexp_symbol))
  83       os << (regexp_symbol &) r;
  84    else if (typeid(r) == typeid(regexp_cat))
  85       os << *((regexp_cat &) r).left << " " << *((regexp_cat &) r).right;
  86    else if (typeid(r) == typeid(regexp_or))
  87       os << "(" << *((regexp_or &) r).left 
  88          << " | " << *((regexp_or &) r).right << ")";
  89    else if (typeid(r) == typeid(regexp_star))
  90       if (typeid(((regexp_star &) r).left) == typeid(regexp_cat))
  91          os << "(" << *((regexp_star &) r).left << ")*";
  92       else 
  93          os << *((regexp_star &) r).left << "*";
  94    else if (typeid(r) == typeid(regexp_question))
  95       if (typeid(((regexp_question &) r).left) == typeid(regexp_cat))
  96          os << "(" << *((regexp_question &) r).left << ")?";
  97       else 
  98          os << *((regexp_question &) r).left << "?";
  99    else if (typeid(r) == typeid(regexp_plus))
 100       if (typeid(((regexp_plus &) r).left) == typeid(regexp_cat))
 101          os << "(" << *((regexp_plus &) r).left << ")+";
 102       else 
 103          os << *((regexp_plus &) r).left << "+";
 104    else
 105       os << "REGEXP_UNKNOWN";
 106 
 107    return os;
 108 }
 109 
 110 ////////////////////////////// virtual dup ////////////////////
 111 
 112 regexp* regexp_bol::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 113    return new regexp_bol;
 114 }
 115 
 116 regexp* regexp_eol::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 117    return new regexp_eol;
 118 }
 119 
 120 regexp* regexp_symbol::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 121    return new regexp_symbol((regexp_symbol&) *this);
 122 }
 123 
 124 regexp* regexp_cat::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 125    return new regexp_cat(*this);
 126 }
 127 
 128 regexp* regexp_or::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 129    return new regexp_or(*this);
 130 }
 131 
 132 regexp* regexp_star::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 133    return new regexp_star(*this);
 134 }
 135 
 136 regexp* regexp_question::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 137    return new regexp_question(*this);
 138 }
 139 
 140 regexp* regexp_plus::dup() const { 
     /* [<][>][^][v][top][bottom][index][help] */
 141    return new regexp_plus(*this);
 142 }

/* [<][>][^][v][top][bottom][index][help] */