tron@2186: /* $Id$ */ tron@2186: tron@1317: #ifndef STRING_H tron@1317: #define STRING_H tron@1317: tron@1317: /* tron@1317: * dst: destination buffer tron@1317: * src: string to copy/concatenate tron@1317: * size: size of the destination buffer tron@1317: * usage: ttd_strlcpy(dst, src, lengthof(dst)); tron@1317: */ tron@1317: void ttd_strlcat(char *dst, const char *src, size_t size); tron@1317: void ttd_strlcpy(char *dst, const char *src, size_t size); tron@1317: tron@1317: /* tron@1317: * dst: destination buffer tron@1317: * src: string to copy tron@1317: * last: pointer to the last element in the dst array tron@1317: * if NULL no boundary check is performed tron@1317: * returns a pointer to the terminating \0 in the destination buffer tron@1317: * usage: strecpy(dst, src, lastof(dst)); tron@1317: */ tron@1317: char* strecat(char* dst, const char* src, const char* last); tron@1317: char* strecpy(char* dst, const char* src, const char* last); tron@1317: tron@2234: char* CDECL str_fmt(const char* str, ...); tron@2234: Darkvater@2775: /** Scans the string for valid characters and if it finds invalid ones, Darkvater@2775: * replaces them with a question mark '?' */ Darkvater@2775: void str_validate(char *str); Darkvater@2775: Darkvater@2775: /** Only allow valid ascii-function codes. Filter special codes like BELL and Darkvater@2775: * so on [we need a special filter here later] Darkvater@2775: * @param key character to be checked Darkvater@2775: * @return true or false depending if the character is printable/valid or not */ Darkvater@2775: static inline bool IsValidAsciiChar(byte key) Darkvater@2775: { Darkvater@2775: // XXX This filter stops certain crashes, but may be too restrictive. Darkvater@2775: return (key >= ' ' && key < 127) || (key >= 160 && Darkvater@2775: key != 0xAA && key != 0xAC && key != 0xAD && key != 0xAF && Darkvater@2775: key != 0xB5 && key != 0xB6 && key != 0xB7 && key != 0xB9); Darkvater@2775: } Darkvater@2775: Darkvater@2436: #endif /* STRING_H */