-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef _STRING_STR_T_ | ||
#define _STRING_STR_T_ | ||
|
||
typedef | ||
struct | ||
{ | ||
char str[200]; | ||
}str_t; | ||
|
||
#endif /*_STRING_STR_T_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _LIBC_STRING_STRSTR_H_ | ||
#define _LIBC_STRING_STRSTR_H_ | ||
|
||
#include <str_t.h> | ||
|
||
extern str_t strstr(char* __str, char* __substr); | ||
|
||
#endif /*_LIBC_STRING_STRSTR_H_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
** This file is part of BoneOS. | ||
** | ||
** BoneOS 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 3 of the License, or | ||
** (at your option) any later version. | ||
** BoneOS 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 BoneOS. If not, see <http://www.gnu.org/licenses/>. | ||
** | ||
** @main_author : Amanuel Bogale | ||
** | ||
** @contributors: | ||
** Amanuel Bogale <amanuel2> : start | ||
**/ | ||
|
||
/* | ||
* @function strstr: | ||
* Returns substring + rest of | ||
* string , from the string. | ||
* | ||
* @param __str (char*): | ||
* Specified string | ||
* to find substring from. | ||
* | ||
* @param __substr (char*): | ||
* the Substring to be searched | ||
* for. | ||
* @return (str_t): | ||
* Returns the substring + rest | ||
* of string. | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <strstr/strstr.h> | ||
#include <strlen/strlen.h> | ||
#include <strcmp/strcmp.h> | ||
|
||
str_t strstr(char* __str, char* __substr) | ||
{ | ||
size_t strlen__substr = strlen(__substr); | ||
size_t strlen__str = strlen(__str); | ||
char __temp[strlen__substr]; | ||
str_t __return_str; | ||
int __start_index=0; | ||
bool __found=false; | ||
|
||
int index=0; | ||
while(__str[index]) | ||
{ | ||
if(__str[index] == __substr[0]) | ||
{ | ||
int i=0; | ||
for(; __substr[i]; i++) | ||
__temp[i] = __str[i+index]; | ||
|
||
if(strcmp(__temp,__substr)==0) | ||
{ | ||
__start_index = (i+index)-strlen__substr; | ||
__found=true; | ||
for(uint32_t i=__start_index,j=0; i<strlen__str;i++,j++) | ||
__return_str.str[j]=__str[i]; | ||
} | ||
index++; | ||
} | ||
else | ||
index++; | ||
} | ||
|
||
if(__found==false) | ||
__return_str.str[0] = 0; | ||
return __return_str; | ||
} | ||
|