/* File: strlib.c
 * Desc: StrLib library implementation
 * Implementation notes:
 *	Strings are defined as arrays of 256 characters.
 *	All strings are null terminated.
 *	Maximum number of characters that may be stored is 255 + null
 *	terminator.
 * Cristina Cifuentes
 * 3 August 1997
*/

#include "strlib.h"
#include "ctype.h"	/* tolower, toupper */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>


void clearString (String s)
{
	*s = 0;
}

int stringLength (String s)
{
	return strlen(s);
}

void stringConcat (String dst, String src)
{
	strcat(dst, src);
}

void stringCopy (String dst, String src)
{
	strcpy(dst, src);
}

int stringCompare (String s1, String s2)
{
	return strcmp(s1, s2);
}

void subString (String src, unsigned start, unsigned length, String dst)
{
	strncpy(dst, src + start, length);
	dst[length] = 0;
}

char charAtPos (String s, int n)
{
	return s[n];
}

void lowerCase (String s)
{
	while (*s)
		*s++ = tolower(*s);
}

void upperCase (String s)
{
	while (*s)
		*s++ = toupper(*s);
}

int findString (String s1, String s2, int start)
{
	return strstr(s1 + start, s2) - s1;
}

int findCharacter (String s, char c, int start)
{
	return strchr(s + start, c) - s;
}


