/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "Licence").
 * You may not use this file except in compliance with the Licence.
 *
 * You can obtain a copy of the licence at RISC OS path @.^.LICENCE
 * or  http://www.riscosdev.com/lanman98/LICENCE.CDDL
 * See the Licence for the specific language governing permissions
 * and limitations under the Licence.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the Licence file. If applicable, add the
 * following below this CDDL HEADER, with the fields enclosed by
 * brackets "[]" replaced with your own identifying information:
 * Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
 
/*
 *   Copyright 1996 Warm Silence Software Ltd.  All rights reserved.
 *   Use is subject to license terms.
 */

/*   PHBG 28/4/97: Initial version
 */

#include <ctype.h>
#include <string.h>
#include "memory.h"

#include "strext.h"

char *strdup(char *s)
{
    char *res;

    if(s == NULL) return NULL;
    res = Malloc(strlen(s)+1);
    strcpy(res, s);
    return res;
}

int ci_strcmp(char *s1, char *s2)
{
    while(*s1 && toupper(*s1) == toupper(*s2))
    {
        s1++;
        s2++;
    }
    return toupper(*s1) - toupper(*s2);
}

int ustrlen(unicode_t *s)
{
    int i;

    for(i = 0; 1; i++)
        if(*s++ == 0)
            return i;
}

int ustrcmp(unicode_t *s, unicode_t *t)
{
    while(*s && *s == *t)
    {
        s++; t++;
    }
    return *s - *t;
}

unicode_t *ustrdup(unicode_t *s)
{
    unicode_t *res;
    int l;

    l = (ustrlen(s) + 1) * sizeof(unicode_t);
    res = Malloc(l);
    memcpy(res, s, l);
    return res;
}

unicode_t *ustrrchr(unicode_t *s, unicode_t c)
{
    unicode_t *res;

    res = NULL;
    while(*s)
    {
        if(*s == c) res = s;
        s++;
    }
    return res;
}
