/*
- * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
* Copyright (C) 2005 QSDN,Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include "qs_ignore_sp.h"
-Attr*
-qs_parse_attr(Doc* doc, const char*s, int len, int *pos)
+Attr *
+qs_parse_attr(Doc *doc, const char *s, int len, int *pos)
{
int ii;
int start_pos;
int size;
int novalue;
- char* name;
- char* value;
- Attr* attr;
- int use_quote;
+ char *name;
+ char *value;
+ Attr *attr;
+ int use_quote_sq;
+ int use_quote_dq;
int backslash;
- use_quote = 0;
+ if (! doc) {
+ QX_LOGGER_FATAL("runtime exception: qs_parse_attr(): doc is null");
+ return NULL;
+ }
+ if (! doc->pool) {
+ QX_LOGGER_FATAL("runtime exception: qs_parse_attr(): doc->pool is null");
+ return NULL;
+ }
+ if (! s) return NULL;
+
+ use_quote_sq = 0;
+ use_quote_dq = 0;
backslash = 0;
QX_LOGGER_DEBUG("start qs_parse_attr()");
return NULL;
}
- name = (char*)apr_palloc(doc->pool,size+1);
+ name = (char *)apr_palloc(doc->pool,size+1);
memset(name, 0, size+1);
memcpy(name, &s[start_pos], size);
- QX_LOGGER_DEBUG((char*)name);
+ QX_LOGGER_DEBUG((char *)name);
novalue = 0;
/* find '=' */
backslash = 1;
break;
}
- if (s[ii] == '\'' || s[ii] == '"') {
- use_quote = 1;
+ if (s[ii] == '\'') {
+ use_quote_sq = 1;
+ ii++;
+ break;
+ }
+ if (s[ii] == '"') {
+ use_quote_dq = 1;
ii++;
break;
}
continue;
if (is_white_space(s[ii])) {
- if (! use_quote)
+ if (! use_quote_sq && ! use_quote_dq)
break;
}
continue;
}
- if (s[ii] == '"')
+ if (s[ii] == '"' && use_quote_dq)
break;
- if (s[ii] == '\'')
+ if (s[ii] == '\'' && use_quote_sq)
break;
}
size = ii - start_pos;
QX_LOGGER_DEBUG_INT("size",size);
}
- value = (char*)apr_palloc(doc->pool, size+1);
+ value = (char *)apr_palloc(doc->pool, size+1);
memset(value, 0, size+1);
if (size != 0)
memcpy(value, &s[start_pos], size);
}
-Attr*
-qs_new_attr(Doc* doc)
+Attr *
+qs_new_attr(Doc *doc)
{
- Attr* attr;
+ Attr *attr;
- attr = (Attr*)apr_palloc(doc->pool,sizeof(Attr));
+ if (!doc) {
+ QX_LOGGER_FATAL("runtime exception: qs_new_attr(): doc is null");
+ return NULL;
+ }
+ if (!doc->pool) {
+ QX_LOGGER_FATAL("runtime exception: qs_new_attr(): doc->pool is null");
+ return NULL;
+ }
+ attr = (Attr *)apr_palloc(doc->pool,sizeof(Attr));
if (attr == NULL) {
QX_LOGGER_FATAL("Out Of Memory");
+ return NULL;
}
attr->next = NULL;