00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "precomp.h"
00030 #include "regexp_match.h"
00031
00033
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
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
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