Rev 8687 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8687 | turbocat | 1 | /* String handling |
2 | |||
3 | This file is part of the Public Domain C Library (PDCLib). |
||
4 | Permission is granted to use, modify, and / or redistribute at will. |
||
5 | */ |
||
6 | |||
7 | #ifndef _STRING_H_ |
||
8 | #define _STRING_H_ |
||
9 | |||
10 | #include |
||
11 | |||
12 | #ifdef __cplusplus |
||
13 | extern "C" { |
||
14 | #endif |
||
15 | |||
16 | /* String function conventions */ |
||
17 | |||
18 | /* |
||
19 | In any of the following functions taking a size_t n to specify the length of |
||
20 | an array or size of a memory region, n may be 0, but the pointer arguments to |
||
21 | the call shall still be valid unless otherwise stated. |
||
22 | */ |
||
23 | |||
24 | /* Copying functions */ |
||
25 | |||
26 | extern void* _FUNC(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n); |
||
27 | |||
28 | /* Copy a number of n characters from the memory area pointed to by s2 to the |
||
29 | area pointed to by s1. If the two areas overlap, behaviour is undefined. |
||
30 | Returns the value of s1. |
||
31 | */ |
||
32 | |||
8718 | turbocat | 33 | #ifdef __TINYC__ |
34 | extern void* memcpy(void* s1, const void* s2, size_t n); |
||
35 | extern void* memset(void* s, int c, size_t n); |
||
8687 | turbocat | 36 | extern void* memmove(void* s1, const void* s2, size_t n); |
8718 | turbocat | 37 | #else |
38 | extern void* _FUNC(memcpy)(void* s1, const void* s2, size_t n); |
||
39 | extern void* _FUNC(memset)(void* s, int c, size_t n); |
||
40 | extern void* _FUNC(memmove)(void* s1, const void* s2, size_t n); |
||
41 | #endif |
||
8687 | turbocat | 42 | |
43 | /* Copy the character array s2 (including terminating '\0' byte) into the |
||
44 | character array s1. |
||
45 | Returns the value of s1. |
||
46 | */ |
||
47 | extern char* _FUNC(strcpy)(char* s1, const char* s2); |
||
48 | |||
49 | /* Copy a maximum of n characters from the character array s2 into the character |
||
50 | array s1. If s2 is shorter than n characters, '\0' bytes will be appended to |
||
51 | the copy in s1 until n characters have been written. If s2 is longer than n |
||
52 | characters, NO terminating '\0' will be written to s1. If the arrays overlap, |
||
53 | behaviour is undefined. |
||
54 | Returns the value of s1. |
||
55 | */ |
||
56 | extern char* _FUNC(strncpy)(char* s1, const char* s2, size_t n); |
||
57 | |||
58 | /* Concatenation functions */ |
||
59 | |||
60 | /* Append the contents of the character array s2 (including terminating '\0') to |
||
61 | the character array s1 (first character of s2 overwriting the '\0' of s1). If |
||
62 | the arrays overlap, behaviour is undefined. |
||
63 | Returns the value of s1. |
||
64 | */ |
||
65 | extern char* _FUNC(strcat)(char* s1, const char* s2); |
||
66 | |||
67 | /* Append a maximum of n characters from the character array s2 to the character |
||
68 | array s1 (first character of s2 overwriting the '\0' of s1). A terminating |
||
69 | '\0' is ALWAYS appended, even if the full n characters have already been |
||
70 | written. If the arrays overlap, behaviour is undefined. |
||
71 | Returns the value of s1. |
||
72 | */ |
||
73 | extern char* _FUNC(strncat)(char* s1, const char* s2, size_t n); |
||
74 | |||
75 | /* Comparison functions */ |
||
76 | |||
77 | /* Compare the first n characters of the memory areas pointed to by s1 and s2. |
||
78 | Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if |
||
79 | s1 > s2. |
||
80 | */ |
||
81 | extern int _FUNC(memcmp)(const void * s1, const void* s2, size_t n); |
||
82 | |||
83 | /* Compare the character arrays s1 and s2. |
||
84 | Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if |
||
85 | s1 > s2. |
||
86 | */ |
||
87 | extern int _FUNC(strcmp)(const char * s1, const char* s2); |
||
88 | |||
89 | /* Compare the character arrays s1 and s2, interpreted as specified by the |
||
90 | LC_COLLATE category of the current locale. |
||
91 | Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if |
||
92 | s1 > s2. |
||
93 | TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support |
||
94 | locales. |
||
95 | */ |
||
96 | extern int _FUNC(strcoll)(const char* s1, const char* s2); |
||
97 | |||
98 | /* Compare no more than the first n characters of the character arrays s1 and |
||
99 | s2. |
||
100 | Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if |
||
101 | s1 > s2. |
||
102 | */ |
||
103 | extern int _FUNC(strncmp)(const char* s1, const char* s2, size_t n); |
||
104 | |||
105 | /* Transform the character array s2 as appropriate for the LC_COLLATE setting of |
||
106 | the current locale. If length of resulting string is less than n, store it in |
||
107 | the character array pointed to by s1. Return the length of the resulting |
||
108 | string. |
||
109 | */ |
||
110 | extern size_t _FUNC(strxfrm)(char* s1, const char* s2, size_t n); |
||
111 | |||
112 | /* Search functions */ |
||
113 | |||
114 | /* Search the first n characters in the memory area pointed to by s for the |
||
115 | character c (interpreted as unsigned char). |
||
116 | Returns a pointer to the first instance found, or NULL. |
||
117 | */ |
||
118 | extern void* _FUNC(memchr)(const void* s, int c, size_t n); |
||
119 | |||
120 | /* Search the character array s (including terminating '\0') for the character c |
||
121 | (interpreted as char). |
||
122 | Returns a pointer to the first instance found, or NULL. |
||
123 | */ |
||
124 | extern char* _FUNC(strchr)(const char* s, int c); |
||
125 | |||
126 | /* Determine the length of the initial substring of character array s1 which |
||
127 | consists only of characters not from the character array s2. |
||
128 | Returns the length of that substring. |
||
129 | */ |
||
130 | extern size_t _FUNC(strcspn)(const char* s1, const char* s2); |
||
131 | |||
132 | /* Search the character array s1 for any character from the character array s2. |
||
133 | Returns a pointer to the first occurrence, or NULL. |
||
134 | */ |
||
135 | extern char* _FUNC(strpbrk)(const char* s1, const char* s2); |
||
136 | |||
137 | /* Search the character array s (including terminating '\0') for the character c |
||
138 | (interpreted as char). |
||
139 | Returns a pointer to the last instance found, or NULL. |
||
140 | */ |
||
141 | extern char* _FUNC(strrchr)(const char * s, int c ); |
||
142 | |||
143 | /* Determine the length of the initial substring of character array s1 which |
||
144 | consists only of characters from the character array s2. |
||
145 | Returns the length of that substring. |
||
146 | */ |
||
147 | extern size_t _FUNC(strspn)(const char * s1, const char * s2); |
||
148 | |||
149 | /* Search the character array s1 for the substring in character array s2. |
||
150 | Returns a pointer to that sbstring, or NULL. If s2 is of length zero, |
||
151 | returns s1. |
||
152 | */ |
||
153 | extern char* _FUNC(strstr)(const char * s1, const char * s2); |
||
154 | |||
155 | /* In a series of subsequent calls, parse a C string into tokens. |
||
156 | On the first call to strtok(), the first argument is a pointer to the to-be- |
||
157 | parsed C string. On subsequent calls, the first argument is NULL unless you |
||
158 | want to start parsing a new string. s2 holds an array of separator characters |
||
159 | which can differ from call to call. Leading separators are skipped, the first |
||
160 | trailing separator overwritten with '\0'. |
||
161 | Returns a pointer to the next token. |
||
162 | WARNING: This function uses static storage, and as such is not reentrant. |
||
163 | */ |
||
164 | extern char* _FUNC(strtok)(char* s1, const char* s2); |
||
165 | |||
166 | /* Map an error number to a (locale-specific) error message string. Error |
||
167 | numbers are typically errno values, but any number is mapped to a message. |
||
168 | TODO: PDCLib does not yet support locales. |
||
169 | */ |
||
170 | extern char* _FUNC(strerror)(int errnum); |
||
171 | |||
172 | /* Returns the length of the string s (excluding terminating '\0').*/ |
||
173 | extern size_t _FUNC(strlen)(const char * s); |
||
174 | |||
175 | /* The function reverses the sequence of characters in the string pointed to by str. */ |
||
176 | extern char* _FUNC(strrev)(char *str); |
||
177 | |||
178 | /* The strdup function executes the function pointed to by the str argument. */ |
||
179 | extern char* _FUNC(strdup)(const char *str); |
||
180 | |||
181 | #endif>>>> |