1 /*****************************************************************************
2 * FullFAT - High Performance, Thread-Safe Embedded FAT File-System *
3 * Copyright (C) 2009 James Walmsley (james@worm.me.uk) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
20 * Alternative Licensing is available directly from the Copyright holder, *
21 * (James Walmsley). For more information consult LICENSING.TXT to obtain *
22 * a Commercial license. *
24 * See RESTRICTIONS.TXT for extra restrictions on the use of FullFAT. *
26 * Removing the above notice is illegal and will invalidate this license. *
27 *****************************************************************************
28 * See http://worm.me.uk/fullfat for more information. *
29 * Or http://fullfat.googlecode.com/ for latest releases and the wiki. *
30 *****************************************************************************/
34 * @author James Walmsley
37 * @defgroup STRING FullFAT String Library
38 * @brief Portable String Library for FullFAT
45 #include "ff_string.h"
48 * These will eventually be moved into a platform independent string
49 * library. Which will be optional. (To allow the use of system specific versions).
54 * @brief Converts an ASCII string to lowercase.
56 void FF_tolower(FF_T_INT8
*string
, FF_T_UINT32 strLen
) {
58 for(i
= 0; i
< strLen
; i
++) {
59 if(string
[i
] >= 'A' && string
[i
] <= 'Z')
68 * @brief Converts an ASCII string to uppercase.
70 void FF_toupper(FF_T_INT8
*string
, FF_T_UINT32 strLen
) {
72 for(i
= 0; i
< strLen
; i
++) {
73 if(string
[i
] >= 'a' && string
[i
] <= 'z')
83 * @brief Compares 2 strings for the specified length, and returns FF_TRUE is they are identical
84 * otherwise FF_FALSE is returned.
87 FF_T_BOOL
FF_strmatch(const FF_T_INT8
*str1
, const FF_T_INT8
*str2
, FF_T_UINT16 len
) {
88 register FF_T_UINT16 i
;
89 register FF_T_INT8 char1
, char2
;
92 if(strlen(str1
) != strlen(str2
)) {
95 len
= (FF_T_UINT16
) strlen(str1
);
98 for(i
= 0; i
< len
; i
++) {
101 if(char1
>= 'A' && char1
<= 'Z') {
104 if(char2
>= 'A' && char2
<= 'Z') {
118 * @brief A re-entrant Strtok function. No documentation is provided :P
119 * Use at your own risk. (This is for FullFAT's use only).
121 FF_T_INT8
*FF_strtok(const FF_T_INT8
*string
, FF_T_INT8
*token
, FF_T_UINT16
*tokenNumber
, FF_T_BOOL
*last
, FF_T_UINT16 Length
) {
122 FF_T_UINT16 strLen
= Length
;
123 FF_T_UINT16 i
,y
, tokenStart
, tokenEnd
= 0;
128 if(string
[i
] == '\\' || string
[i
] == '/') {
135 if(string
[i
] == '\\' || string
[i
] == '/') {
137 if(y
== *tokenNumber
) {
138 tokenStart
= (FF_T_UINT16
)(i
+ 1);
140 if(y
== (*tokenNumber
+ 1)) {
149 if(*last
== FF_TRUE
) {
157 memcpy(token
, (string
+ tokenStart
), (FF_T_UINT32
)(tokenEnd
- tokenStart
));
158 token
[tokenEnd
- tokenStart
] = '\0';
165 FF_T_BOOL
FF_wildcompare(const FF_T_INT8
*pszWildCard
, const FF_T_INT8
*pszString
) {
166 /* Check to see if the string contains the wild card */
167 if (!memchr(pszWildCard
, '*', strlen(pszWildCard
)))
169 /* if it does not then do a straight string compare */
170 if (strcmp(pszWildCard
, pszString
))
177 while ((*pszWildCard
)
180 /* Test for the wild card */
181 if (*pszWildCard
== '*')
183 /* Eat more than one */
184 while (*pszWildCard
== '*')
188 /* If there are more chars in the string */
191 /* Search for the next char */
192 pszString
= memchr(pszString
, (int)*pszWildCard
, strlen(pszString
));
193 /* if it does not exist then the strings don't match */
215 /* Fail if they don't match */
216 if (*pszWildCard
!= *pszString
)
221 /* Bump both pointers */
225 /* fail if different lengths */
226 if (*pszWildCard
!= *pszString
)