Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
f88a72a8
Commit
f88a72a8
authored
Jan 13, 2014
by
Damien George
Browse files
Merge pull request #168 from dhylands/add-strstr
Added public domain implementations of strchr and strstr.
parents
2300537c
c8effff9
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/objstr.c
View file @
f88a72a8
...
...
@@ -3,6 +3,7 @@
#include
<stdarg.h>
#include
<string.h>
#include
<assert.h>
#include
<sys/types.h>
#include
"nlr.h"
#include
"misc.h"
...
...
stm/std.h
View file @
f88a72a8
...
...
@@ -17,6 +17,8 @@ int strncmp(const char *s1, const char *s2, size_t n);
char
*
strndup
(
const
char
*
s
,
size_t
n
);
char
*
strcpy
(
char
*
dest
,
const
char
*
src
);
char
*
strcat
(
char
*
dest
,
const
char
*
src
);
char
*
strchr
(
const
char
*
s
,
int
c
);
char
*
strstr
(
const
char
*
haystack
,
const
char
*
needle
);
int
printf
(
const
char
*
fmt
,
...);
int
snprintf
(
char
*
str
,
size_t
size
,
const
char
*
fmt
,
...);
stm/string0.c
View file @
f88a72a8
...
...
@@ -108,3 +108,31 @@ char *strcat(char *dest, const char *src) {
*
d
=
'\0'
;
return
dest
;
}
// Public Domain implementation of strchr from:
// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strchr_function
char
*
strchr
(
const
char
*
s
,
int
c
)
{
/* Scan s for the character. When this loop is finished,
s will either point to the end of the string or the
character we were looking for. */
while
(
*
s
!=
'\0'
&&
*
s
!=
(
char
)
c
)
s
++
;
return
((
*
s
==
c
)
?
(
char
*
)
s
:
0
);
}
// Public Domain implementation of strstr from:
// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strstr_function
char
*
strstr
(
const
char
*
haystack
,
const
char
*
needle
)
{
size_t
needlelen
;
/* Check for the null needle case. */
if
(
*
needle
==
'\0'
)
return
(
char
*
)
haystack
;
needlelen
=
strlen
(
needle
);
for
(;
(
haystack
=
strchr
(
haystack
,
*
needle
))
!=
0
;
haystack
++
)
if
(
strncmp
(
haystack
,
needle
,
needlelen
)
==
0
)
return
(
char
*
)
haystack
;
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment