Loading src/exception.cpp +4 −4 Changes for src/exception.cpp: 4 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ const char* libhtmlpp::HTMLException::what(){ delete[] _printBuffer; _printBuffer = new char[bufsize+1]; for(Message *curmsg=_firstMessage; curmsg; curmsg=curmsg->_nextMessage){ scopy(curmsg->_Buffer,curmsg->_Buffer+curmsg->_BufferSize,_printBuffer+written); libsystempp::scopy(curmsg->_Buffer,curmsg->_Buffer+curmsg->_BufferSize,_printBuffer+written); written+=curmsg->_BufferSize; } _printBuffer[bufsize]='\0'; Loading @@ -99,9 +99,9 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::asign(const char *src){ _lastMessage=_lastMessage->_nextMessage; } _lastMessage->_CType=_curCType; _lastMessage->_BufferSize=getlen(src); _lastMessage->_BufferSize=libsystempp::getlen(src); _lastMessage->_Buffer=new char[_lastMessage->_BufferSize+1]; scopy(src,src+_lastMessage->_BufferSize+1,_lastMessage->_Buffer); libsystempp::scopy(src,src+_lastMessage->_BufferSize+1,_lastMessage->_Buffer); return *this; } Loading @@ -116,7 +116,7 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const char *src){ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(int src){ char *buf=new char[sizeof(int)+1]; itoa(src,buf); libsystempp::itoa(src,buf); asign(buf); delete[] buf; return *this; Loading src/html.cpp +12 −12 Changes for src/html.cpp: 12 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -48,8 +48,8 @@ void libhtmlpp::HtmlString::assign(const char* src, size_t srcsize){ size_t nsize=_DataSize+srcsize; char *buf=new char [nsize+1]; size_t i=0; scopy(_Data,_Data+_DataSize,buf); scopy(src,src+srcsize,buf+_DataSize); libsystempp::scopy(_Data,_Data+_DataSize,buf); libsystempp::scopy(src,src+srcsize,buf+_DataSize); _DataSize=nsize; delete[] _Data; buf[nsize]='\0'; Loading @@ -71,7 +71,7 @@ void libhtmlpp::HtmlString::push_back(const char src){ } void libhtmlpp::HtmlString::assign(const char* src) { assign(src,getlen(src)); assign(src,libsystempp::getlen(src)); } void libhtmlpp::HtmlString::insert(size_t pos, char src){ Loading Loading @@ -106,7 +106,7 @@ libhtmlpp::HtmlString & libhtmlpp::HtmlString::operator+=(libhtmlpp::HtmlString& libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator=(const char *src){ clear(); _DataSize=getlen(src); _DataSize=libsystempp::getlen(src); _Data = new char[_DataSize]; for(size_t i = 0; i<_DataSize; ++i){ _Data[i]=src[i]; Loading @@ -125,7 +125,7 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(const char* src){ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(int src){ char *buf=new char[sizeof(int)+1]; itoa(src,buf); libsystempp::itoa(src,buf); assign(buf); delete[] buf; return *this; Loading @@ -133,7 +133,7 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(int src){ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(unsigned long src){ char *buf=new char[sizeof(int)+1]; ultoa(src,buf); libsystempp::ultoa(src,buf); assign(buf); delete[] buf; return *this; Loading Loading @@ -277,7 +277,7 @@ FINDTAGNAMEPOS: ++enpos; goto FINDTAGNAMEPOS; } return substr(_Data,tagname,anpos,enpos); return libsystempp::substr(_Data,tagname,anpos,enpos); } void libhtmlpp::HtmlString::_buildTree(HtmlElement **node,size_t &spos,size_t &tpos){ Loading @@ -293,7 +293,7 @@ void libhtmlpp::HtmlString::_buildTree(HtmlElement **node,size_t &spos,size_t &t else (*node)->_nextElement=tagel; size_t ctagsize=_getTagName(_HTable[spos][0],_HTable[spos][2],&prvname); if(ctagsize>0 && ncompare(tag,tagsize,prvname,ctagsize)){ if(ctagsize>0 && libsystempp::ncompare(tag,tagsize,prvname,ctagsize)){ _buildTree(&tagel->_Child,++spos,--tpos); }else{ _buildTree(&tagel->_prevElement,++spos,--tpos); Loading Loading @@ -351,7 +351,7 @@ READFILE: ssize_t rdd=fd.read(buf,HTML_BLOCKSIZE); if(rdd>0){ char *dest; size_t cdd=cleannewline(buf,rdd,&dest); size_t cdd=libsystempp::cleannewline(buf,rdd,&dest); _HtmlDocument->assign(dest,cdd); delete[] dest; goto READFILE; Loading @@ -361,7 +361,7 @@ READFILE: void libhtmlpp::HtmlElement::setID(const char *id){ HTMLException excp; if(!setter(id,getlen(id),&_ID)){ if(!setter(id,libsystempp::getlen(id),&_ID)){ excp[HTMLException::Error] << "HtmlTable can't id: " << id; throw excp; } Loading @@ -369,7 +369,7 @@ void libhtmlpp::HtmlElement::setID(const char *id){ void libhtmlpp::HtmlElement::setClass(const char *cname){ HTMLException excp; if(!setter(cname,getlen(cname),&_Class)){ if(!setter(cname,libsystempp::getlen(cname),&_Class)){ excp[HTMLException::Error] << "HtmlTable can't class name: " << cname; throw excp; } Loading @@ -377,7 +377,7 @@ void libhtmlpp::HtmlElement::setClass(const char *cname){ void libhtmlpp::HtmlElement::setStyle(const char *css){ HTMLException excp; if(!setter(css,getlen(css),&_Style,":;(),+~'")){ if(!setter(css,libsystempp::getlen(css),&_Style,":;(),+~'")){ excp[HTMLException::Error] << "HtmlTable can't set Style: " << css; throw excp; } Loading src/utils.h +5 −112 Changes for src/utils.h: 5 added lines, 112 removed lines. Original line number Diff line number Diff line Loading @@ -25,57 +25,27 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <systempp/sysutils.h> #include "exception.h" #include <ctype.h> #ifndef UTIL_H #define UTIL_H namespace libhtmlpp { inline size_t getlen(const char *str){ if(!str) return 0; size_t len= 0; while (*(str++) != '\0') ++len; return len; } inline void reverse(char s[]){ int i, j; char c; for (i = 0, j = getlen(s)-1; i<j; i++, j--) { for (i = 0, j = libsystempp::getlen(s)-1; i<j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } } inline void itoa(int n, char s[]){ int i, sign; if ((sign = n) < 0) n = -n; i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; s[i] = '\0'; reverse(s); } inline void ultoa(unsigned long n, char s[]){ unsigned int i; i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ s[i] = '\0'; reverse(s); } inline bool isdigit(const char src){ const char numbers[10]={0,1,2,3,4,5,6,7,8,9}; for(int i=0; i<10; ++i){ Loading Loading @@ -103,7 +73,7 @@ namespace libhtmlpp { for(int i=0; i<srcsize; ++i){ if(!isdigit(src[i]) || !isalpha(src[i]) || ssigns){ nallowd=true; for(size_t pos=0; pos<getlen(ssigns); ++pos){ for(size_t pos=0; pos<libsystempp::getlen(ssigns); ++pos){ if(ssigns[pos]==src[i]){ nallowd=false; } Loading @@ -120,83 +90,6 @@ namespace libhtmlpp { *dest=buf; return true; } inline int substr(const char *src,char **dest,size_t spos,size_t endpos){ size_t srcsize=endpos-spos; char *buf = new char[srcsize+1]; for(int i=spos,j=0; j<srcsize; ++i,++j){ buf[j]=src[i]; } buf[srcsize]='\0'; *dest=buf; return srcsize; } inline const char *scopy(const char* first, const char* last, char* des){ while (first != last) { *des++ = *first++; } return des; } inline size_t cleannewline(const char *src,size_t srcsize,char **dest){ struct buffer { buffer(){ nextbuffer=nullptr; } ~buffer(){ delete[] text; delete nextbuffer; } char *text; size_t tsize; buffer *nextbuffer; }*ftbuf=nullptr,*ltbuf=nullptr; size_t spos=0; for(size_t i=0; i<srcsize; ++i){ if(src[i] == '\n' || src[i] == '\r'){ if(ftbuf){ ltbuf->nextbuffer= new buffer; ltbuf=ltbuf->nextbuffer; }else{ ftbuf=new buffer; ltbuf=ftbuf; } ltbuf->tsize=substr(src,<buf->text,spos,i); if((i+1)<srcsize && (i+1)=='\n') spos=(i+=2); else spos=(++i); } } size_t ssize=0,written=0; for(buffer *cbuf=ftbuf; cbuf; cbuf=cbuf->nextbuffer) ssize+=cbuf->tsize; *dest=new char[ssize+1]; for(buffer *cbuf=ftbuf; cbuf; cbuf=cbuf->nextbuffer){ scopy(cbuf->text,cbuf->text+cbuf->tsize,*dest+written); written+=cbuf->tsize; } delete ftbuf; return ssize; } inline bool ncompare(char *src,size_t ssize,char *comp,size_t csize){ if(ssize<csize) return false; for(int i=0; i<csize; ++i){ if(src[i]!=comp[i]) return false; } return true; } }; #endif Loading
src/exception.cpp +4 −4 Changes for src/exception.cpp: 4 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ const char* libhtmlpp::HTMLException::what(){ delete[] _printBuffer; _printBuffer = new char[bufsize+1]; for(Message *curmsg=_firstMessage; curmsg; curmsg=curmsg->_nextMessage){ scopy(curmsg->_Buffer,curmsg->_Buffer+curmsg->_BufferSize,_printBuffer+written); libsystempp::scopy(curmsg->_Buffer,curmsg->_Buffer+curmsg->_BufferSize,_printBuffer+written); written+=curmsg->_BufferSize; } _printBuffer[bufsize]='\0'; Loading @@ -99,9 +99,9 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::asign(const char *src){ _lastMessage=_lastMessage->_nextMessage; } _lastMessage->_CType=_curCType; _lastMessage->_BufferSize=getlen(src); _lastMessage->_BufferSize=libsystempp::getlen(src); _lastMessage->_Buffer=new char[_lastMessage->_BufferSize+1]; scopy(src,src+_lastMessage->_BufferSize+1,_lastMessage->_Buffer); libsystempp::scopy(src,src+_lastMessage->_BufferSize+1,_lastMessage->_Buffer); return *this; } Loading @@ -116,7 +116,7 @@ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(const char *src){ libhtmlpp::HTMLException& libhtmlpp::HTMLException::operator<<(int src){ char *buf=new char[sizeof(int)+1]; itoa(src,buf); libsystempp::itoa(src,buf); asign(buf); delete[] buf; return *this; Loading
src/html.cpp +12 −12 Changes for src/html.cpp: 12 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -48,8 +48,8 @@ void libhtmlpp::HtmlString::assign(const char* src, size_t srcsize){ size_t nsize=_DataSize+srcsize; char *buf=new char [nsize+1]; size_t i=0; scopy(_Data,_Data+_DataSize,buf); scopy(src,src+srcsize,buf+_DataSize); libsystempp::scopy(_Data,_Data+_DataSize,buf); libsystempp::scopy(src,src+srcsize,buf+_DataSize); _DataSize=nsize; delete[] _Data; buf[nsize]='\0'; Loading @@ -71,7 +71,7 @@ void libhtmlpp::HtmlString::push_back(const char src){ } void libhtmlpp::HtmlString::assign(const char* src) { assign(src,getlen(src)); assign(src,libsystempp::getlen(src)); } void libhtmlpp::HtmlString::insert(size_t pos, char src){ Loading Loading @@ -106,7 +106,7 @@ libhtmlpp::HtmlString & libhtmlpp::HtmlString::operator+=(libhtmlpp::HtmlString& libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator=(const char *src){ clear(); _DataSize=getlen(src); _DataSize=libsystempp::getlen(src); _Data = new char[_DataSize]; for(size_t i = 0; i<_DataSize; ++i){ _Data[i]=src[i]; Loading @@ -125,7 +125,7 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(const char* src){ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(int src){ char *buf=new char[sizeof(int)+1]; itoa(src,buf); libsystempp::itoa(src,buf); assign(buf); delete[] buf; return *this; Loading @@ -133,7 +133,7 @@ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(int src){ libhtmlpp::HtmlString &libhtmlpp::HtmlString::operator<<(unsigned long src){ char *buf=new char[sizeof(int)+1]; ultoa(src,buf); libsystempp::ultoa(src,buf); assign(buf); delete[] buf; return *this; Loading Loading @@ -277,7 +277,7 @@ FINDTAGNAMEPOS: ++enpos; goto FINDTAGNAMEPOS; } return substr(_Data,tagname,anpos,enpos); return libsystempp::substr(_Data,tagname,anpos,enpos); } void libhtmlpp::HtmlString::_buildTree(HtmlElement **node,size_t &spos,size_t &tpos){ Loading @@ -293,7 +293,7 @@ void libhtmlpp::HtmlString::_buildTree(HtmlElement **node,size_t &spos,size_t &t else (*node)->_nextElement=tagel; size_t ctagsize=_getTagName(_HTable[spos][0],_HTable[spos][2],&prvname); if(ctagsize>0 && ncompare(tag,tagsize,prvname,ctagsize)){ if(ctagsize>0 && libsystempp::ncompare(tag,tagsize,prvname,ctagsize)){ _buildTree(&tagel->_Child,++spos,--tpos); }else{ _buildTree(&tagel->_prevElement,++spos,--tpos); Loading Loading @@ -351,7 +351,7 @@ READFILE: ssize_t rdd=fd.read(buf,HTML_BLOCKSIZE); if(rdd>0){ char *dest; size_t cdd=cleannewline(buf,rdd,&dest); size_t cdd=libsystempp::cleannewline(buf,rdd,&dest); _HtmlDocument->assign(dest,cdd); delete[] dest; goto READFILE; Loading @@ -361,7 +361,7 @@ READFILE: void libhtmlpp::HtmlElement::setID(const char *id){ HTMLException excp; if(!setter(id,getlen(id),&_ID)){ if(!setter(id,libsystempp::getlen(id),&_ID)){ excp[HTMLException::Error] << "HtmlTable can't id: " << id; throw excp; } Loading @@ -369,7 +369,7 @@ void libhtmlpp::HtmlElement::setID(const char *id){ void libhtmlpp::HtmlElement::setClass(const char *cname){ HTMLException excp; if(!setter(cname,getlen(cname),&_Class)){ if(!setter(cname,libsystempp::getlen(cname),&_Class)){ excp[HTMLException::Error] << "HtmlTable can't class name: " << cname; throw excp; } Loading @@ -377,7 +377,7 @@ void libhtmlpp::HtmlElement::setClass(const char *cname){ void libhtmlpp::HtmlElement::setStyle(const char *css){ HTMLException excp; if(!setter(css,getlen(css),&_Style,":;(),+~'")){ if(!setter(css,libsystempp::getlen(css),&_Style,":;(),+~'")){ excp[HTMLException::Error] << "HtmlTable can't set Style: " << css; throw excp; } Loading
src/utils.h +5 −112 Changes for src/utils.h: 5 added lines, 112 removed lines. Original line number Diff line number Diff line Loading @@ -25,57 +25,27 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <systempp/sysutils.h> #include "exception.h" #include <ctype.h> #ifndef UTIL_H #define UTIL_H namespace libhtmlpp { inline size_t getlen(const char *str){ if(!str) return 0; size_t len= 0; while (*(str++) != '\0') ++len; return len; } inline void reverse(char s[]){ int i, j; char c; for (i = 0, j = getlen(s)-1; i<j; i++, j--) { for (i = 0, j = libsystempp::getlen(s)-1; i<j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } } inline void itoa(int n, char s[]){ int i, sign; if ((sign = n) < 0) n = -n; i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = '-'; s[i] = '\0'; reverse(s); } inline void ultoa(unsigned long n, char s[]){ unsigned int i; i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ s[i] = '\0'; reverse(s); } inline bool isdigit(const char src){ const char numbers[10]={0,1,2,3,4,5,6,7,8,9}; for(int i=0; i<10; ++i){ Loading Loading @@ -103,7 +73,7 @@ namespace libhtmlpp { for(int i=0; i<srcsize; ++i){ if(!isdigit(src[i]) || !isalpha(src[i]) || ssigns){ nallowd=true; for(size_t pos=0; pos<getlen(ssigns); ++pos){ for(size_t pos=0; pos<libsystempp::getlen(ssigns); ++pos){ if(ssigns[pos]==src[i]){ nallowd=false; } Loading @@ -120,83 +90,6 @@ namespace libhtmlpp { *dest=buf; return true; } inline int substr(const char *src,char **dest,size_t spos,size_t endpos){ size_t srcsize=endpos-spos; char *buf = new char[srcsize+1]; for(int i=spos,j=0; j<srcsize; ++i,++j){ buf[j]=src[i]; } buf[srcsize]='\0'; *dest=buf; return srcsize; } inline const char *scopy(const char* first, const char* last, char* des){ while (first != last) { *des++ = *first++; } return des; } inline size_t cleannewline(const char *src,size_t srcsize,char **dest){ struct buffer { buffer(){ nextbuffer=nullptr; } ~buffer(){ delete[] text; delete nextbuffer; } char *text; size_t tsize; buffer *nextbuffer; }*ftbuf=nullptr,*ltbuf=nullptr; size_t spos=0; for(size_t i=0; i<srcsize; ++i){ if(src[i] == '\n' || src[i] == '\r'){ if(ftbuf){ ltbuf->nextbuffer= new buffer; ltbuf=ltbuf->nextbuffer; }else{ ftbuf=new buffer; ltbuf=ftbuf; } ltbuf->tsize=substr(src,<buf->text,spos,i); if((i+1)<srcsize && (i+1)=='\n') spos=(i+=2); else spos=(++i); } } size_t ssize=0,written=0; for(buffer *cbuf=ftbuf; cbuf; cbuf=cbuf->nextbuffer) ssize+=cbuf->tsize; *dest=new char[ssize+1]; for(buffer *cbuf=ftbuf; cbuf; cbuf=cbuf->nextbuffer){ scopy(cbuf->text,cbuf->text+cbuf->tsize,*dest+written); written+=cbuf->tsize; } delete ftbuf; return ssize; } inline bool ncompare(char *src,size_t ssize,char *comp,size_t csize){ if(ssize<csize) return false; for(int i=0; i<csize; ++i){ if(src[i]!=comp[i]) return false; } return true; } }; #endif