author | Darkvater |
Tue, 20 Dec 2005 20:52:05 +0000 | |
changeset 2775 | d3ed38a97250 |
parent 2436 | 177cb6a8339f |
child 4200 | a45420ba0c23 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1317
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
3 |
#ifndef STRING_H |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
4 |
#define STRING_H |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
5 |
|
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
6 |
/* |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
7 |
* dst: destination buffer |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
8 |
* src: string to copy/concatenate |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
9 |
* size: size of the destination buffer |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
10 |
* usage: ttd_strlcpy(dst, src, lengthof(dst)); |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
11 |
*/ |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
12 |
void ttd_strlcat(char *dst, const char *src, size_t size); |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
13 |
void ttd_strlcpy(char *dst, const char *src, size_t size); |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
14 |
|
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
15 |
/* |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
16 |
* dst: destination buffer |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
17 |
* src: string to copy |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
18 |
* last: pointer to the last element in the dst array |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
19 |
* if NULL no boundary check is performed |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
20 |
* returns a pointer to the terminating \0 in the destination buffer |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
21 |
* usage: strecpy(dst, src, lastof(dst)); |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
22 |
*/ |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
23 |
char* strecat(char* dst, const char* src, const char* last); |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
24 |
char* strecpy(char* dst, const char* src, const char* last); |
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
diff
changeset
|
25 |
|
2234 | 26 |
char* CDECL str_fmt(const char* str, ...); |
27 |
||
2775
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
28 |
/** Scans the string for valid characters and if it finds invalid ones, |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
29 |
* replaces them with a question mark '?' */ |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
30 |
void str_validate(char *str); |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
31 |
|
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
32 |
/** Only allow valid ascii-function codes. Filter special codes like BELL and |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
33 |
* so on [we need a special filter here later] |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
34 |
* @param key character to be checked |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
35 |
* @return true or false depending if the character is printable/valid or not */ |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
36 |
static inline bool IsValidAsciiChar(byte key) |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
37 |
{ |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
38 |
// XXX This filter stops certain crashes, but may be too restrictive. |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
39 |
return (key >= ' ' && key < 127) || (key >= 160 && |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
40 |
key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF && |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
41 |
key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9); |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
42 |
} |
d3ed38a97250
(svn r3322) - Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received
Darkvater
parents:
2436
diff
changeset
|
43 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2234
diff
changeset
|
44 |
#endif /* STRING_H */ |