mirror of https://github.com/BOINC/boinc.git
Added strlcat().
Modified match tag to work with tags of the form "<tag>" and "tag" svn path=/trunk/boinc/; revision=2918
This commit is contained in:
parent
246543094f
commit
61e8348017
31
lib/parse.C
31
lib/parse.C
|
@ -32,20 +32,41 @@
|
|||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#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 <tag>1234</tag>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 "<tag>" 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 <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue