2 * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "qs_parse_string.h"
20 #include "qs_parse_attr.h"
21 #include "qs_parse_tag.h"
23 static char *s_get_tag_name(Doc *doc, const char *s, int len) ;
28 qs_parse_tag(Doc *doc, const char *s, int len)
38 QX_LOGGER_FATAL("runtime exception: qs_parse_tag(): doc is null");
42 sv_s = sp = (char *)s;
46 QX_LOGGER_DEBUG("start parse_tag()");
50 * s[0] == '<' && s[len] == '>'
52 tag_name = (char *)s_get_tag_name(doc, ++s, --ll);
54 node = (Node *)qs_new_tag(doc);
56 QX_LOGGER_DEBUG("runtime exception: qs_parse_tag(): Out of memory.");
59 node->name = tag_name;
60 node->otext = apr_palloc(doc->pool,len+2);
61 memset(node->otext, 0, len+2);
62 memcpy(node->otext, sp, len+1);
64 QX_LOGGER_DEBUG(tag_name);
66 ll -= (strlen(tag_name));
67 QX_LOGGER_DEBUG_INT("ll",ll);
68 sp += (strlen(tag_name)+1);
70 Attr *attr = qs_parse_attr(doc,sp, ll, &next_point);
72 QX_LOGGER_DEBUG("End of QS_PARSE_ATTR()");
75 QX_LOGGER_DEBUG(attr->name);
76 QX_LOGGER_DEBUG(attr->value);
79 QX_LOGGER_DEBUG_INT(sp, ll);
80 node = (Node *)qs_add_attr(doc,node, attr);
83 if (sv_s[len-1] == '/') {
84 node->closed_by_itself = 1;
87 node->closed_by_itself = 0;
89 QX_LOGGER_DEBUG("end parse_tag()");
98 s_get_tag_name(Doc *doc, const char *s, int len)
103 char *return_value = NULL;
106 for (ii = 0; ii < len; ii++) {
107 if (is_white_space(s[ii]))
113 for (;ii<len; ii++) {
114 if (is_white_space(s[ii]))
120 return_value = (char *)apr_palloc(doc->pool, size+1);
122 memset(return_value, 0, size+1);
123 memcpy(return_value, &s[sp], size);
125 QX_LOGGER_DEBUG(return_value);
137 QX_LOGGER_FATAL("runtime exception: qs_new_tag(): doc is NULL");
141 QX_LOGGER_FATAL("runtime exception: qs_new_tag(): doc->pool is NULL");
145 node = (Node *)apr_palloc(doc->pool, sizeof(Node));
149 node->child_tail= NULL;
151 node->attr_tail = NULL;
162 qs_add_attr(Doc *doc, Node *node, Attr *attr)
165 QX_LOGGER_FATAL("runtime exception: qs_add_attr(): node is null");
175 if (node->attr == NULL) {
177 node->attr_tail = attr;
182 node->attr_tail->next = attr;
183 node->attr_tail = attr;