Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

regexp_match.cpp

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #include "precomp.h"
00030 #include "regexp_match.h"
00031 
00033 // CL_RegExpMatch Construction:
00034 
00035 CL_RegExpMatch::CL_RegExpMatch()
00036 : vector(0), size(0), allocated(0), captures_count(0), partial(false)
00037 {
00038 }
00039 
00040 CL_RegExpMatch::CL_RegExpMatch(const CL_RegExpMatch &other)
00041 : vector(0), size(0), allocated(0), captures_count(0), partial(false)
00042 {
00043         set_vector_size(other.size);
00044         memcpy(vector, other.vector, sizeof(int)*size);
00045         captures_count = other.captures_count;
00046         partial = other.partial;
00047 }
00048 
00049 CL_RegExpMatch::~CL_RegExpMatch()
00050 {
00051         delete[] vector;
00052 }
00053 
00055 // CL_RegExpMatch Attributes:
00056 
00057 const int *CL_RegExpMatch::get_vector() const
00058 {
00059         return vector;
00060 }
00061         
00062 int *CL_RegExpMatch::get_vector()
00063 {
00064         return vector;
00065 }
00066         
00067 int CL_RegExpMatch::get_vector_size() const
00068 {
00069         return size;
00070 }
00071         
00072 int CL_RegExpMatch::get_capture_pos(int capture) const
00073 {
00074         if (capture < 0 || capture >= captures_count)
00075                 return -1;
00076         return vector[capture*2];
00077 }
00078         
00079 int CL_RegExpMatch::get_capture_length(int capture) const
00080 {
00081         if (capture < 0 || capture >= captures_count)
00082                 return 0;
00083         return vector[capture*2+1] - vector[capture*2];
00084 }
00085         
00086 int CL_RegExpMatch::get_capture_end(int capture) const
00087 {
00088         if (capture < 0 || capture >= captures_count)
00089                 return 0;
00090         return vector[capture*2+1];
00091 }
00092         
00093 int CL_RegExpMatch::get_captures_count() const
00094 {
00095         return captures_count;
00096 }
00097 
00098 bool CL_RegExpMatch::is_partial() const
00099 {
00100         return partial;
00101 }
00102         
00103 bool CL_RegExpMatch::is_match() const
00104 {
00105         return captures_count > 0;
00106 }
00107 
00109 // CL_RegExpMatch Operations:
00110 
00111 CL_RegExpMatch &CL_RegExpMatch::operator =(const CL_RegExpMatch &other)
00112 {
00113         set_vector_size(other.size);
00114         memcpy(vector, other.vector, sizeof(int)*size);
00115         captures_count = other.captures_count;
00116         partial = other.partial;
00117         return *this;
00118 }
00119 
00120 void CL_RegExpMatch::set_vector_size(int new_size)
00121 {
00122         captures_count = 0;
00123         partial = false;
00124         if (new_size > allocated)
00125         {
00126                 delete[] vector;
00127                 vector = new int[new_size];
00128                 allocated = new_size;
00129         }
00130         size = new_size;
00131 }
00132         
00133 void CL_RegExpMatch::set_captures_count(int count)
00134 {
00135         captures_count = count;
00136 }
00137         
00138 void CL_RegExpMatch::set_partial_match(bool new_partial)
00139 {
00140         partial = new_partial;
00141 }
00142 
00144 // CL_RegExpMatch Implementation:

Generated on Sat Feb 19 22:51:16 2005 for npcore by  doxygen 1.4.1