This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Created by Romain on 10/09/2020. | ||
|
||
#include "stringC.hpp" | ||
|
||
namespace stdstring { | ||
int strcmp(const char* a, const char* b) { | ||
u32 i = 0; | ||
while (true) { | ||
if (a[i] < b[i]) { | ||
return -1; | ||
} | ||
else if (a[i] > b[i]) { | ||
return 1; | ||
} | ||
else { | ||
if (a[i] == '\0') { | ||
return 0; | ||
} | ||
++i; | ||
} | ||
} | ||
} | ||
|
||
u32 strlen(const char* str) { | ||
u32 i = 0; | ||
while (str[i] != '\0') { | ||
++i; | ||
} | ||
return i; | ||
} | ||
|
||
char* strdup(const char* str) { | ||
int len = strlen(str); | ||
return (char*) stdlib::memcpy(malloc(sizeof(char) * (len + 1)), str, len + 1);; | ||
} | ||
|
||
char* strcpy(char* dest, const char* src) { | ||
return (char*) stdlib::memcpy(dest, src, strlen(src) + 1); | ||
} | ||
} |
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,49 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// Created by Romain on 07/11/2020. | ||
|
||
#ifndef ROMAINOS_STRINGC_HPP | ||
#define ROMAINOS_STRINGC_HPP | ||
|
||
#include <memory.h> | ||
|
||
namespace stdstring { | ||
/** | ||
* Compare deux string | ||
* | ||
* @param a String 1 | ||
* @param b String 2 | ||
* | ||
* @return 0 si a == b, -1 si a < b, 1 si a > b | ||
*/ | ||
int strcmp(const char* a, const char* b); | ||
|
||
/** | ||
* Calcule la taille d'une chaîne | ||
* | ||
* @param str String | ||
* | ||
* @return Taille | ||
*/ | ||
u32 strlen(const char* str); | ||
|
||
/** | ||
* Duplique une chaine en effectuant un malloc | ||
* | ||
* @param str Chaine | ||
* | ||
* @return Taille | ||
*/ | ||
char* strdup(const char* str); | ||
|
||
/** | ||
* Copie une chaine | ||
* | ||
* @param dest Destination | ||
* @param src Source | ||
* | ||
* @return Chaine copiée | ||
*/ | ||
char* strcpy(char* dest, const char* src); | ||
} | ||
|
||
#endif //ROMAINOS_STRINGC_HPP |