/*
+ * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
* Copyright (C) 2005 QSDN,Inc. All rights reserved.
- * Copyright (C) 2005 Atsushi Konno All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 = 0;
- int backslash = 0;
+ char *name;
+ char *value;
+ Attr *attr;
+ int use_quote_sq;
+ int use_quote_dq;
+ int backslash;
+
+ 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 '=' */
size = 0;
if (!novalue) {
+
/*
* ignore space
*/
backslash = 1;
break;
}
- if (s[ii] == '\'' || s[ii] == '"') {
- use_quote = 1;
+ if (s[ii] == '\'') {
+ use_quote_sq = 1;
ii++;
break;
}
- if (!is_white_space(s[ii])) {
+ if (s[ii] == '"') {
+ use_quote_dq = 1;
+ ii++;
break;
}
+ if (!is_white_space(s[ii]))
+ break;
}
start_pos = ii;
ii++;
continue;
}
+
if (is_sjis_kana(s[ii]))
continue;
+
if (is_white_space(s[ii])) {
- if (! use_quote)
+ if (! use_quote_sq && ! use_quote_dq)
break;
}
- if (s[ii] == '\\')
+
+ if (s[ii] == '\\') {
+ ii++;
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->name = name;
attr->value = value;
- QX_LOGGER_DEBUG(attr->name);
- QX_LOGGER_DEBUG(attr->value);
-
QX_LOGGER_DEBUG("end qs_parse_attr()");
*pos = ii;
+
return attr;
}
-Attr*
-qs_new_attr(Doc* doc)
+
+Attr *
+qs_new_attr(Doc *doc)
{
- Attr* attr = (Attr*)apr_palloc(doc->pool,sizeof(Attr));
+ Attr *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;
attr->parent = NULL;
attr->name = NULL;
attr->value = NULL;
+
return attr;
}
/*