Import backup from 2004-03-08
This commit is contained in:
1 parent
0b9d7fde22
commit
8d0e6de040
45 files changed
+243
-219
No files matched your search
@@ -0,0 +1,88 @@
|
||||
// string.c
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements string functions
|
||||
|
||||
#include "string.h"
|
||||
|
||||
char *strcat(char *dest, char *src)
|
||||
{
|
||||
strcpy(dest+strlen(dest), src);
|
||||
}
|
||||
|
||||
|
||||
//Splits a string into multiple strings by turning all characters
|
||||
// equal to delim into null values (string termination character)
|
||||
//Returns the number of strings after the split, 1 if no delim chars
|
||||
int string_split(char *str, char delim)
|
||||
{
|
||||
if (strlen(str) < 1)
|
||||
return 0; //empty string
|
||||
int count = 1;
|
||||
for (; *str; str++)
|
||||
{
|
||||
if (*str == delim)
|
||||
{
|
||||
count++;
|
||||
*str = 0;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
//Advances a char pointer to the byte after the current string's
|
||||
// null-terminating character
|
||||
//Useful after calling string_split()
|
||||
//Returns a pointer to the following string
|
||||
char *string_advance(char *str)
|
||||
{
|
||||
for (; *str; str++);
|
||||
return str+1;
|
||||
}
|
||||
|
||||
|
||||
void rtrim(char *str)
|
||||
{
|
||||
str += strlen(str); //now points to the null character at the end of the string
|
||||
str--;
|
||||
for (;;)
|
||||
{
|
||||
if ((*str == ' ') || (*str == '\t') || (*str == '\n'))
|
||||
*str-- = 0;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *ucase(char *str)
|
||||
{
|
||||
char *ret = str;
|
||||
for (;;)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
if ((*str >= 'a') && (*str <= 'z'))
|
||||
*str = (*str) - 32;
|
||||
str++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
char *lcase(char *str)
|
||||
{
|
||||
char *ret = str;
|
||||
for (;;)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
if ((*str >= 'A') && (*str <= 'Z'))
|
||||
*str = (*str) + 32;
|
||||
str++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// strings.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements string functions
|
||||
|
||||
#ifndef __HOS_STRING__
|
||||
#define __HOS_STRING__ __HOS_STRING__
|
||||
|
||||
char *strcat(char *dest, char *src);
|
||||
int string_split(char *str, char delim);
|
||||
char *string_advance(char *str);
|
||||
void rtrim(char *str);
|
||||
char *ucase(char *str);
|
||||
char *lcase(char *str);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user