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 
00046 /*
00047  * get_*() methods which return (sub)informations such as matches
00048  * or strings
00049  */
00050 
00051 
00052 Array* Pcre::get_sub_strings() {
00053   if(resultset != NULL)
00054     return resultset;
00055   else
00056     return NULL;
00057 }
00058 
00059 string Pcre::get_match(int pos) {
00060   if(pos >= 0 && pos < num_matches) {
00061     ArrayIterator P = resultset->begin() + pos;
00062     return *P;
00063   }
00064   else {
00065     throw exception("Pcre::get_match(int): out of range");
00066   }
00067 }
00068 
00069 int Pcre::get_match_start() {
00070   if (sub_vec)
00071     return sub_vec[0];
00072   else
00073     return -1;
00074 }
00075 
00076 int Pcre::get_match_end() {
00077   if (sub_vec)
00078     return sub_vec[1] - 1;
00079   else
00080     return -1;
00081 }
00082 
00083 int Pcre::get_match_start(int pos) {
00084   if(pos >= 0 && pos <= num_matches) {
00085     /*
00086      * sub_vec[0] and [1] is the start/end of the entire string.
00087      */
00088     return sub_vec[ (++pos) * 2 ];
00089   }
00090   else {
00091     throw exception("Pcre::get_match_start(int): out of range");
00092   }  
00093 }
00094 
00095 int Pcre::get_match_end(int pos) {
00096   if(pos >= 0 && pos <= num_matches) {
00097     /*
00098      * the end offset of a subpattern points to
00099      * the first offset of the next substring,
00100      * therefore -1
00101      */
00102     return sub_vec[ ((++pos) * 2) + 1 ] - 1;
00103   }
00104   else {
00105     throw exception("Pcre::get_match_end(int): out of range");
00106   }
00107 }
00108 
00109 size_t Pcre::get_match_length(int pos) {
00110   if(pos >= 0 && pos < num_matches) {
00111     ArrayIterator P = resultset->begin() + pos;
00112     return P->length();
00113   }
00114   else {
00115     throw exception("Pcre::get_match_length(int): out of range");
00116   }
00117 }

Generated on Wed Jun 25 00:39:01 2003 for PCRE++ by doxygen1.3-rc3