diff --git a/lib/parse.C b/lib/parse.C index e1d56aaa41..fd621f9640 100644 --- a/lib/parse.C +++ b/lib/parse.C @@ -32,20 +32,41 @@ #include #include +#include "config.h" #include "error_numbers.h" #include "util.h" #include "parse.h" +#include "std_fixes.h" + +// test if a character is an xml tag delimiter +bool isxmldelim(char c) { + return ((c==' ') || (c=='\n') || (c=='\r') || + (c==',') || (c=='<') || (c=='>') || + (c==0)); +} // return true if the tag appears in the line // bool match_tag(const char* buf, const char* tag) { - if (strstr(buf, tag)) return true; + char tmp_tag[BUFSIZ]={'<',0}; + if (tag[0] == '<') { + strlcpy(tmp_tag,tag,BUFSIZ); + } else { + strlcat(tmp_tag,tag,BUFSIZ); + } + char *p=tmp_tag+strlen(tmp_tag); + do { + *(p--)=0; + } while (isxmldelim(*p)); + while ((buf=strstr(buf,tmp_tag))) { + if (isxmldelim(buf[strlen(tmp_tag)])) return true; + buf++; + } return false; } bool match_tag(const std::string &s, const char* tag) { - if (s.find(tag) != std::string::npos) return true; - return false; + return match_tag(s.c_str(),tag); } // parse an integer of the form 1234 @@ -265,10 +286,6 @@ char* sgets(char* buf, int len, char*& in) { return buf; } -bool isxmldelim(char c) { - return ((c==' ') || (c=='\n') || (c=='\r') || - (c==',') || (c=='<') || (c=='>')); -} bool extract_xml_record(const std::string &field, const char *tag, std::string &record) { std::string::size_type start_pos,end_pos; diff --git a/lib/std_fixes.h b/lib/std_fixes.h index eef757b00c..29d98f7c49 100644 --- a/lib/std_fixes.h +++ b/lib/std_fixes.h @@ -19,6 +19,10 @@ // Revision History: // // $Log$ +// Revision 1.5 2004/01/22 02:01:09 korpela +// Added strlcat(). +// Modified match tag to work with tags of the form "" and "tag" +// // Revision 1.4 2003/12/11 17:55:07 korpela // Added definition of strlcpy() for machines without it. // @@ -52,6 +56,30 @@ namespace std { #endif +#ifndef HAVE_STRLCAT +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +extern "C" { +size_t strlcat(char *dst, const char *src, size_t len); +} + +inline size_t strlcat(char *dst, const char *src, size_t len) { + strncat(dst,src,len-strlen(dst)-1); + dst[len-1]=0; + return strlen(dst); +} + +namespace std { + using ::strlcat; +} + +#endif + #ifndef HAVE_STD_MIN namespace std {