* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
+#include <ctype.h>
#include <glib.h>
#define set_error(msg, ...) do { if (error != NULL) *error = g_error_new (GINT_TO_POINTER (1), 1, msg, __VA_ARGS__); } while (0);
g_free (context);
}
+static gboolean
+my_isspace (char c)
+{
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v')
+ return TRUE;
+ return FALSE;
+}
+
+static gboolean
+my_isalnum (char c)
+{
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
+ return TRUE;
+ if (c >= '0' && c <= '9')
+ return TRUE;
+
+ return FALSE;
+}
+
+static gboolean
+my_isalpha (char c)
+{
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
+ return TRUE;
+ return FALSE;
+}
+
static const char *
skip_space (const char *p, const char *end)
{
- for (; p < end && isspace (*p); p++)
+ for (; p < end && my_isspace (*p); p++)
;
return p;
}
const char *start = p;
int l;
- for (; p < end && isalnum (*p); p++)
+ for (; p < end && my_isalnum (*p); p++)
;
if (p == end)
return end;
switch (context->state){
case START:
- if (c == ' ' || c == '\t' || c == '\f' || c == '\n')
+ if (c == ' ' || c == '\t' || c == '\f' || c == '\n' || (c & 0x80))
continue;
if (c == '<'){
if (p+1 < end && p [1] == '?'){
int full_stop = 0, l;
gchar **names = NULL, **values = NULL;
- for (; p < end && isspace (*p); p++)
+ for (; p < end && my_isspace (*p); p++)
;
if (p == end){
set_error ("%s", "Unfinished element");
break;
}
- if (!(isascii (*p) && isalpha (*p))){
+ if (!my_isalpha (*p)){
set_error ("%s", "Expected an element name");
goto fail;
}
- for (++p; p < end && (isalnum (*p) || (*p == '.')); p++)
+ for (++p; p < end && (my_isalnum (*p) || (*p == '.')); p++)
;
if (p == end){
set_error ("%s", "Expected an element");
}
element_end = p;
- for (; p < end && isspace (*p); p++)
+ for (; p < end && my_isspace (*p); p++)
;
if (p == end){
set_error ("%s", "Unfinished element");
if (context->parser.end_element != NULL && context->state == START_ELEMENT){
context->parser.end_element (context, ename, context->user_data, error);
if (error != NULL && *error != NULL){
- free (ename);
+ g_free (ename);
goto fail;
}
}
break;
case FLUSH_TEXT:
- if (context->parser.text != NULL){
+ if (context->parser.text != NULL && context->text != NULL){
context->parser.text (context, context->text->str, context->text->len,
context->user_data, error);
if (error != NULL && *error != NULL)