author | Darkvater |
Mon, 31 Jul 2006 22:40:55 +0000 | |
changeset 4204 | 3aa39be759f2 |
parent 4200 | e6ba94085b81 |
child 4209 | f0ecce3cb2b0 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1317
3c90086ff34f
(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 |
#include "stdafx.h" |
3c90086ff34f
(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 |
#include "string.h" |
3c90086ff34f
(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 |
|
2234 | 6 |
#include <stdarg.h> |
4200
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
7 |
#if defined(UNIX) || defined(__OS2__) |
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
8 |
#include <ctype.h> // required for tolower() |
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
9 |
#endif |
2234 | 10 |
|
1317
3c90086ff34f
(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 |
void ttd_strlcat(char *dst, const char *src, size_t size) |
3c90086ff34f
(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 |
{ |
3c90086ff34f
(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 |
assert(size > 0); |
3c90086ff34f
(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 |
for (; size > 0 && *dst != '\0'; --size, ++dst) {} |
3c90086ff34f
(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 |
assert(size > 0); |
3c90086ff34f
(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 |
while (--size > 0 && *src != '\0') *dst++ = *src++; |
3c90086ff34f
(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 |
*dst = '\0'; |
3c90086ff34f
(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 |
} |
3c90086ff34f
(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 |
|
3c90086ff34f
(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 |
|
3c90086ff34f
(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 |
void ttd_strlcpy(char *dst, const char *src, size_t size) |
3c90086ff34f
(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 |
{ |
3c90086ff34f
(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 |
assert(size > 0); |
3c90086ff34f
(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 |
while (--size > 0 && *src != '\0') *dst++ = *src++; |
3c90086ff34f
(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 |
*dst = '\0'; |
3c90086ff34f
(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
|
26 |
} |
3c90086ff34f
(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
|
27 |
|
3c90086ff34f
(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
|
28 |
|
3c90086ff34f
(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
|
29 |
char* strecat(char* dst, const char* src, const char* last) |
3c90086ff34f
(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
|
30 |
{ |
3c90086ff34f
(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
|
31 |
assert(last == NULL || dst <= last); |
3c90086ff34f
(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
|
32 |
for (; *dst != '\0'; ++dst) |
3c90086ff34f
(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
|
33 |
if (dst == last) return dst; |
3c90086ff34f
(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
|
34 |
for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src; |
3c90086ff34f
(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
|
35 |
*dst = '\0'; |
3c90086ff34f
(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
|
36 |
return strecpy(dst, src, last); |
3c90086ff34f
(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
|
37 |
} |
3c90086ff34f
(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
|
38 |
|
3c90086ff34f
(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
|
39 |
|
3c90086ff34f
(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
|
40 |
char* strecpy(char* dst, const char* src, const char* last) |
3c90086ff34f
(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
|
41 |
{ |
3c90086ff34f
(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
|
42 |
assert(last == NULL || dst <= last); |
3c90086ff34f
(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
|
43 |
for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src; |
3c90086ff34f
(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
|
44 |
*dst = '\0'; |
3c90086ff34f
(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
|
45 |
return dst; |
3c90086ff34f
(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
|
46 |
} |
2234 | 47 |
|
48 |
||
49 |
char* CDECL str_fmt(const char* str, ...) |
|
50 |
{ |
|
51 |
char buf[4096]; |
|
52 |
va_list va; |
|
53 |
int len; |
|
54 |
char* p; |
|
55 |
||
56 |
va_start(va, str); |
|
57 |
len = vsprintf(buf, str, va); |
|
58 |
va_end(va); |
|
59 |
p = malloc(len + 1); |
|
60 |
if (p != NULL) memcpy(p, buf, len + 1); |
|
61 |
return p; |
|
62 |
} |
|
2775
a18db0ab5e51
(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:
2234
diff
changeset
|
63 |
|
a18db0ab5e51
(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:
2234
diff
changeset
|
64 |
void str_validate(char *str) |
a18db0ab5e51
(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:
2234
diff
changeset
|
65 |
{ |
a18db0ab5e51
(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:
2234
diff
changeset
|
66 |
for (; *str != '\0'; str++) |
a18db0ab5e51
(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:
2234
diff
changeset
|
67 |
if (!IsValidAsciiChar(*str)) *str = '?'; |
a18db0ab5e51
(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:
2234
diff
changeset
|
68 |
} |
4200
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
69 |
|
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
70 |
void strtolower(char *str) |
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
71 |
{ |
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
72 |
for (; *str != '\0'; str++) *str = tolower(*str); |
e6ba94085b81
(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.
Darkvater
parents:
2775
diff
changeset
|
73 |
} |