Xyris  0.5
string.hpp
Go to the documentation of this file.
1 /**
2  * @file string.hpp
3  * @author Keeton Feavel ([email protected])
4  * @brief Standard string and memory utility library
5  * @version 0.3
6  * @date 2020-06-17
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2020
9  *
10  */
11 #pragma once
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 /**
17  * @brief Returns the length of a string.
18  *
19  * @param s Input string
20  * @return int Length of string
21  */
22 int strlen(const char* s);
23 
24 /**
25  * @brief Copys a string from the source to the destination.
26  *
27  * @param source String to be copied
28  * @param destination Location where string will be copied
29  */
30 void strcpy(char* destination, const char* source);
31 
32 /**
33  * @brief Copys a string from the source to the destination.
34  *
35  * @param source String to be copied
36  * @param destination Location where string will be copied
37  * @param len Maximum string length
38  */
39 void strncpy(char* destination, const char* source, size_t len);
40 
41 /**
42  * @brief Concatanates source onto destination.
43  *
44  * @param dest Destination
45  * @param src Source
46  * @return char* Pointer to destination
47  */
48 char* strcat(char* dest, const char* src);
49 
50 /**
51  * @brief Compares two strings
52  *
53  * @param s1 String one
54  * @param s2 String two
55  * @return int Returns a negative value if a value in s1 is less than s2,
56  * a positive number in the inverse case, and zero if both
57  * string match.
58  */
59 int strcmp(const char *s1, const char *s2);
60 
61 /**
62  * @brief Locates a substring (needle) within a containing string (haystack)
63  *
64  * @param haystack String to be searched
65  * @param needle Substring to be located
66  * @return char* Pointer to the beginning of the substring
67  */
68 const char* strstr(const char* haystack, const char* needle);
69 
70 /**
71  * @brief Reverses the inputted string.
72  *
73  * @param s String to be reversed
74  */
75 void reverse(char* s);
76 
77 /**
78  * @brief Converts an integer into its ASCII representation.
79  * (This does not have a standard, ANSI implementation.)
80  *
81  * @param n Number to be converted to ASCII
82  * @param str Buffer to hold result
83  */
84 void itoa(int n, char str[]);
85 
86 /**
87  * @brief Sets the number of bytes in memory at ptr to the value.
88  *
89  * @param bufptr Pointer to location in memory
90  * @param value Value to be written in memory
91  * @param num Number of bytes
92  * @return void* Pointer to location in memory
93  */
94 void* memset(void* bufptr, int value, size_t num);
95 
96 /**
97  * @brief Compares a given number of bytes in memory at pointer A to pointer B.
98  *
99  * @param ptr1 Source pointer
100  * @param ptr2 Destination pointer
101  * @param num Number of bytes
102  * @return int Returns 0 if identical. If negative, pointer A is less than
103  * than pointer B and vice versa for positive.
104  */
105 int memcmp(const void* ptr1, const void* ptr2, size_t num);
106 
107 /**
108  * @brief Moves a given number of bytes from the source to the destination.
109  *
110  * @param destination Destination pointer
111  * @param source Source pointer
112  * @param size Number of bytes
113  * @return void* Pointer to the destination
114  */
115 void* memmove(void* destination, const void* source, size_t size);
116 
117 /**
118  * @brief
119  *
120  * @param dstptr
121  * @param srcptr
122  * @param size
123  * @return void*
124  */
125 void* memcpy(void* dstptr, const void* srcptr, size_t size);
size
uint16_t size
Definition: regs.hpp:2
memcpy
void * memcpy(void *dstptr, const void *srcptr, size_t size)
Definition: string.cpp:141
itoa
void itoa(int n, char str[])
Converts an integer into its ASCII representation. (This does not have a standard,...
Definition: string.cpp:89
strcpy
void strcpy(char *destination, const char *source)
Copys a string from the source to the destination.
Definition: string.cpp:31
strlen
int strlen(const char *s)
Returns the length of a string.
Definition: string.cpp:14
memcmp
int memcmp(const void *ptr1, const void *ptr2, size_t num)
Compares a given number of bytes in memory at pointer A to pointer B.
Definition: string.cpp:114
strncpy
void strncpy(char *destination, const char *source, size_t len)
Copys a string from the source to the destination.
Definition: string.cpp:41
memset
void * memset(void *bufptr, int value, size_t num)
Sets the number of bytes in memory at ptr to the value.
Definition: string.cpp:106
strstr
const char * strstr(const char *haystack, const char *needle)
Locates a substring (needle) within a containing string (haystack)
Definition: string.cpp:65
strcmp
int strcmp(const char *s1, const char *s2)
Compares two strings.
Definition: string.cpp:51
strcat
char * strcat(char *dest, const char *src)
Concatanates source onto destination.
Definition: string.cpp:23
memmove
void * memmove(void *destination, const void *source, size_t size)
Moves a given number of bytes from the source to the destination.
Definition: string.cpp:127
reverse
void reverse(char *s)
Reverses the inputted string.
Definition: string.cpp:78