4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 Copyright (c) 2000-2017 Expat development team
11 Licensed under the MIT license:
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to permit
18 persons to whom the Software is furnished to do so, subject to the
21 The above copyright notice and this permission notice shall be included
22 in all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
27 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
29 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
30 USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #ifdef HAVE_EXPAT_CONFIG_H
34 #include <expat_config.h>
36 #include "minicheck.h"
46 xmlstrlen(const XML_Char *s)
57 CharData_Init(CharData *storage)
59 assert(storage != NULL);
64 CharData_AppendString(CharData *storage, const char *s)
66 int maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
71 if (storage->count < 0)
73 if ((len + storage->count) > maxchars) {
74 len = (maxchars - storage->count);
76 if (len + storage->count < (int)sizeof(storage->data)) {
77 memcpy(storage->data + storage->count, s, len);
78 storage->count += len;
83 CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len)
87 assert(storage != NULL);
89 maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
90 if (storage->count < 0)
94 if ((len + storage->count) > maxchars) {
95 len = (maxchars - storage->count);
97 if (len + storage->count < (int)sizeof(storage->data)) {
98 memcpy(storage->data + storage->count, s,
99 len * sizeof(storage->data[0]));
100 storage->count += len;
105 CharData_CheckString(CharData *storage, const char *expected)
111 assert(storage != NULL);
112 assert(expected != NULL);
113 count = (storage->count < 0) ? 0 : storage->count;
114 len = strlen(expected);
116 if (sizeof(XML_Char) == 1)
117 sprintf(buffer, "wrong number of data characters:"
118 " got %d, expected %d:\n%s", count, len, storage->data);
121 "wrong number of data characters: got %d, expected %d",
126 if (memcmp(expected, storage->data, len) != 0) {
127 fail("got bad data bytes");
134 CharData_CheckXMLChars(CharData *storage, const XML_Char *expected)
137 int len = xmlstrlen(expected);
140 assert(storage != NULL);
141 count = (storage->count < 0) ? 0 : storage->count;
143 sprintf(buffer, "wrong number of data characters: got %d, expected %d",
148 if (memcmp(expected, storage->data, len * sizeof(storage->data[0])) != 0) {
149 fail("got bad data bytes");