Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

get.cc

Go to the documentation of this file.
00001 /*
00002  *
00003  *  This file  is part of the PCRE++ Class Library.
00004  *
00005  *  By  accessing  this software,  PCRE++, you  are  duly informed
00006  *  of and agree to be  bound  by the  conditions  described below
00007  *  in this notice:
00008  *
00009  *  This software product,  PCRE++,  is developed by Thomas Linden
00010  *  and copyrighted (C) 2002-2003 by Thomas Linden,with all rights 
00011  *  reserved.
00012  *
00013  *  There  is no charge for PCRE++ software.  You can redistribute
00014  *  it and/or modify it under the terms of the GNU  Lesser General
00015  *  Public License, which is incorporated by reference herein.
00016  *
00017  *  PCRE++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS,
00018  *  OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that
00019  *  the use of it will not infringe on any third party's intellec-
00020  *  tual property rights.
00021  *
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with PCRE++.  Copies can also be obtained from:
00024  *
00025  *    http://www.gnu.org/licenses/lgpl.txt
00026  *
00027  *  or by writing to:
00028  *
00029  *  Free Software Foundation, Inc.
00030  *  59 Temple Place, Suite 330
00031  *  Boston, MA 02111-1307
00032  *  USA
00033  *
00034  *  Or contact:
00035  *
00036  *   "Thomas Linden" <tom@daemon.de>
00037  *
00038  *
00039  */
00040 
00041 
00042 #include "pcre++.h"
00043 
00044 using namespace std;
00045 using namespace pcrepp;
00046 
00047 /*
00048  * get_*() methods which return (sub)informations such as matches
00049  * or strings
00050  */
00051 
00052 
00053 vector<string>* Pcre::get_sub_strings() const {
00054   if(resultset != NULL)
00055     return resultset;
00056   else
00057     return NULL;
00058 }
00059 
00060 string Pcre::get_match(int pos) const {
00061   if(pos >= 0 && pos < num_matches) {
00062     vector<string>::iterator P = resultset->begin() + pos;
00063     return *P;
00064   }
00065   else {
00066     throw exception("Pcre::get_match(int): out of range");
00067   }
00068 }
00069 
00070 int Pcre::get_match_start() const {
00071   if (sub_vec)
00072     return sub_vec[0];
00073   else
00074     return -1;
00075 }
00076 
00077 int Pcre::get_match_end() const {
00078   if (sub_vec)
00079     return sub_vec[1] - 1;
00080   else
00081     return -1;
00082 }
00083 
00084 int Pcre::get_match_start(int pos) const {
00085   if(pos >= 0 && pos <= num_matches) {
00086     /*
00087      * sub_vec[0] and [1] is the start/end of the entire string.
00088      */
00089     return sub_vec[ (++pos) * 2 ];
00090   }
00091   else {
00092     throw exception("Pcre::get_match_start(int): out of range");
00093   }  
00094 }
00095 
00096 int Pcre::get_match_end(int pos) const {
00097   if(pos >= 0 && pos <= num_matches) {
00098     /*
00099      * the end offset of a subpattern points to
00100      * the first offset of the next substring,
00101      * therefore -1
00102      */
00103     return sub_vec[ ((++pos) * 2) + 1 ] - 1;
00104   }
00105   else {
00106     throw exception("Pcre::get_match_end(int): out of range");
00107   }
00108 }
00109 
00110 size_t Pcre::get_match_length(int pos) const {
00111   if(pos >= 0 && pos < num_matches) {
00112     vector<string>::iterator P = resultset->begin() + pos;
00113     return P->length();
00114   }
00115   else {
00116     throw exception("Pcre::get_match_length(int): out of range");
00117   }
00118 }

Generated on Wed Aug 25 01:38:04 2004 for PCRE++ by doxygen1.3-rc3