FireBirdLib - Topfield TMS PVR TAP Programming Library
isLegalChar.c
Go to the documentation of this file.
1#include "FBLib_string.h"
2
3bool isLegalChar(const byte *c, eRemoveChars ControlCharacters)
4{
6
7 byte s;
8
9 if(c == NULL)
10 {
11 TRACEEXIT();
12 return FALSE;
13 }
14
15 s = *c;
16
17 if((ControlCharacters & ControlChars) != 0)
18 {
19 // Anything below 32 is a control character!
20 if((s < 0x20) && (s != 0x0a))
21 {
22 TRACEEXIT();
23 return FALSE;
24 }
25
26 //Before destroying some bytes, check if this is a UTF8 character
27 if(!isUTF8Char(c, NULL))
28 {
29 // these characters are unused in Windows system font and cause trouble
30 if((s >= 0x7f) && (s <= 0x9f) && (s != 0x80) && (s != 0x8a) && (s != 0x91) && (s != 0x92))
31 {
32 TRACEEXIT();
33 return FALSE;
34 }
35 }
36 }
37
38 if((ControlCharacters & LFChars) != 0)
39 {
40 if((s == 0x0a) || (s == 0x8a))
41 {
42 TRACEEXIT();
43 return FALSE;
44 }
45 }
46
47 if((ControlCharacters & InvalidFileNameChars) != 0)
48 {
49 switch(s)
50 {
51 // this character will cause a filename not displayed in recording list
52 // Remarked for UTF8 compatibility
53 // case 'à':
54
55 // These characters are not allowed in Windows.
56 case ':':
57 case '/':
58 case '\\':
59 case '*':
60 case '?':
61 case '"':
62 case '<':
63 case '>':
64 case '|':
65 {
66 TRACEEXIT();
67 return FALSE;
68 }
69 }
70 }
71
72 if((ControlCharacters & NonPrintableChars) != 0)
73 {
74 TRACEEXIT();
75 return (s >= ' ' && s <= '~');
76 }
77
78 TRACEEXIT();
79 return TRUE;
80}
bool isLegalChar(const byte *c, eRemoveChars ControlCharacters)
Definition: isLegalChar.c:3
eRemoveChars
Definition: libFireBird.h:2503
@ LFChars
Definition: libFireBird.h:2505
@ ControlChars
Definition: libFireBird.h:2504
@ NonPrintableChars
Definition: libFireBird.h:2507
@ InvalidFileNameChars
Definition: libFireBird.h:2506
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
bool isUTF8Char(const byte *p, byte *BytesPerChar)
Definition: isUTF8Char.c:3