Operating System
mystring.h
Go to the documentation of this file.
1 #ifndef __STRING_H_
2 #define __STRING_H_
3 #include <stdint.h>
4 
5 static inline int16_t strlen(const char* str) {
6  int index = 0;
7  while (str[index]) index++;
8  return index;
9 }
10 
11 int strcmp(const char*, const char*);
12 static inline int16_t strchr(const char* str, char chr) {
13  const char* p = str;
14  while (*p) {
15  if (*p == chr) {
16  return p - str;
17  }
18  p++;
19  }
20  return -1;
21 }
22 static inline int16_t strstr(const char* src, const char* tar) {
23  int16_t src_size = strlen(src);
24  int16_t tar_size = strlen(tar);
25  int jmp = 0;
26  for (int i = 0; i < src_size; ++i) {
27  for (int j = 0; j < tar_size; ++j) {
28  if (!tar[j] || !src[i+j] || src[i+j] != tar[j]) {
29  jmp = 1;
30  break;
31  }
32  }
33  if (jmp == 0) {
34  return i;
35  } else {
36  jmp = 0;
37  }
38  }
39  return -1;
40 }
41 #endif
static int16_t strstr(const char *src, const char *tar)
Definition: mystring.h:22
static int16_t strchr(const char *str, char chr)
Definition: mystring.h:12
int strcmp(const char *, const char *)
Definition: mystring.c:2
static int16_t strlen(const char *str)
Definition: mystring.h:5