FireBirdLib - Topfield TMS PVR TAP Programming Library
ValidFileName.c
Go to the documentation of this file.
1#include <string.h>
2#include "FBLib_string.h"
3
4char *ValidFileName(const char *strName, eRemoveChars ControlCharacters, char *Result, int ResultSize)
5{
7
8 const char *s;
9 char *d, *l;
10 byte BytesPerCharacter;
11
12 d = Result;
13
14 if(strName && *strName && Result && (ResultSize > (int)strlen(strName)))
15 {
16 strcpy(Result, strName);
17 s = strName;
18 l = d + MAX_FILE_NAME_SIZE;
19
20 while(*s)
21 {
22 if(isLegalChar(s, ControlCharacters))
23 {
24 if(isUTF8Char(s, &BytesPerCharacter))
25 {
26 if(d + BytesPerCharacter >= l) break;
27
28 //As this is a multibyte UTF character, copy all bytes
29 memcpy(d, (void *) s, BytesPerCharacter);
30 d += BytesPerCharacter;
31 s += (BytesPerCharacter - 1);
32 }
33 else
34 {
35 if(d == l) break;
36
37 *d = *s;
38 d++;
39 }
40 }
41 s++;
42 }
43 }
44 if(ResultSize) *d = '\0';
45
46 TRACEEXIT();
47 return Result;
48}
bool isLegalChar(const byte *, eRemoveChars)
Definition: isLegalChar.c:3
char * ValidFileName(const char *strName, eRemoveChars ControlCharacters, char *Result, int ResultSize)
Definition: ValidFileName.c:4
eRemoveChars
Definition: libFireBird.h:2503
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
bool isUTF8Char(const byte *p, byte *BytesPerChar)
Definition: isUTF8Char.c:3