aboutsummaryrefslogtreecommitdiff
path: root/backends/PalmOS/Src/missing/_string.cpp
blob: 03a9aa2f9047ae57912c63422f0366fd4112aaee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001  Ludvig Strigeus
 * Copyright (C) 2001-2004 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#include <string.h>

void *memchr(const void *s, int c, UInt32 n) {
	UInt32 chr;
	for(chr = 0; chr < n;chr++,((UInt8 *)s)++)
		if ( *((UInt8 *)s) == c)
			return (void *)s;
	
	return NULL;
}

UInt32 strspn(const char *s1, const char *s2) {
	UInt32 chr = 0;

	while (	chr < strlen(s1) && 
			strchr(s2, s1[chr]) )
		chr++;

	return chr;
}

static Char *StrTokNext = NULL;

Char *strtok(Char *str, const Char *sep) {
	Char	*position = NULL,
			*found,
			*end;

	UInt16	loop = 0,
			chars= StrLen(sep);

	str			= (str)?(str):(StrTokNext);
	StrTokNext	= NULL;

	if (!str)
		return NULL;

	end = str+StrLen(str);

	while (loop<chars)
	{
		found = StrChr(str,sep[loop]);
		loop++;

		if (found == str)
		{
			str++;
			loop = 0;
		}
		else if (position == NULL || position > found)
			position = found;
	}

	if (position == NULL)
		if (str==end)
			return NULL;
		else
			return str;

	position[0] = 0;
	StrTokNext	= position+1;

	return str;
}

Char *strpbrk(const Char *s1, const Char *s2) {
	Char *found;
	UInt32 n;
	
	for (n=0; n <= StrLen(s2); n++) {
		found = StrChr(s1, s2[n]);
		if (found)
			return found;
	}
	
	return NULL;
}

Char *strrchr(const Char *s, int c) {
	UInt32 chr;
	UInt32 n = StrLen(s);

	for(chr = n; chr >= 0; chr--)
		if ( *((UInt8 *)s+chr) == c)
			return (Char *)(s+chr);

	return NULL;
} 

Char *strdup(const Char *s1) {
	Char* buf = (Char *)MemPtrNew(StrLen(s1)+1);

	if(buf)
		StrCopy(buf, s1);

	return buf;
}