1 /** @file strutil.h String and text utilities. 2 * 3 * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi> 4 * @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net> 5 * 6 * @par License 7 * GPL: http://www.gnu.org/licenses/gpl.html 8 * 9 * <small>This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by the 11 * Free Software Foundation; either version 2 of the License, or (at your 12 * option) any later version. This program is distributed in the hope that it 13 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 * Public License for more details. You should have received a copy of the GNU 16 * General Public License along with this program; if not, see: 17 * http://www.gnu.org/licenses</small> 18 */ 19 20 #ifndef LIBDENG_STRING_UTIL_H 21 #define LIBDENG_STRING_UTIL_H 22 23 #include "types.h" 24 #include <stdarg.h> 25 26 /// @addtogroup legacyData 27 /// @{ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /** 34 * Prints a formatted string into a fixed-size buffer. At most @c size 35 * characters will be written to the output buffer @c str. The output will 36 * always contain a terminating null character. 37 * 38 * @param str Output buffer. 39 * @param size Size of the output buffer. 40 * @param format Format of the output. 41 * @param ap Variable-size argument list. 42 * 43 * @return Number of characters written to the output buffer if lower than or 44 * equal to @c size, else @c -1. 45 */ 46 DENG_PUBLIC int dd_vsnprintf(char *str, size_t size, char const *format, va_list ap); 47 48 /** 49 * Prints a formatted string into a fixed-size buffer. At most @c size 50 * characters will be written to the output buffer @c str. The output will 51 * always contain a terminating null character. 52 * 53 * @param str Output buffer. 54 * @param size Size of the output buffer. 55 * @param format Format of the output. 56 * 57 * @return Number of characters written to the output buffer 58 * if lower than or equal to @c size, else @c -1. 59 */ 60 DENG_PUBLIC int dd_snprintf(char *str, size_t size, char const *format, ...); 61 62 #ifdef WIN32 63 /** 64 * Windows implementation for the Unix strcasestr() function. 65 */ 66 DENG_PUBLIC char const *strcasestr(char const *text, char const *sub); 67 #endif 68 69 #ifdef UNIX 70 // Some routines not available on the *nix platform. 71 DENG_PUBLIC char *strupr(char *string); 72 DENG_PUBLIC char *strlwr(char *string); 73 #endif // UNIX 74 75 // String Utilities 76 77 DENG_PUBLIC char *M_SkipWhite(const char *str); 78 79 DENG_PUBLIC char *M_FindWhite(const char *str); 80 81 DENG_PUBLIC void M_StripLeft(char* str); 82 83 DENG_PUBLIC void M_StripRight(char* str, size_t len); 84 85 DENG_PUBLIC void M_Strip(char* str, size_t len); 86 87 DENG_PUBLIC char* M_SkipLine(char* str); 88 89 DENG_PUBLIC char* M_StrCat(char* buf, const char* str, size_t bufSize); 90 91 DENG_PUBLIC char* M_StrnCat(char* buf, const char* str, size_t nChars, size_t bufSize); 92 93 /** 94 * Concatenates src to dest as a quoted string. " is escaped to \". 95 * Returns dest. 96 */ 97 DENG_PUBLIC char* M_StrCatQuoted(char* dest, const char* src, size_t len); 98 99 DENG_PUBLIC char* M_LimitedStrCat(char* buf, const char* str, size_t maxWidth, char separator, size_t bufLength); 100 101 /** 102 * Somewhat similar to strtok(). 103 */ 104 DENG_PUBLIC char* M_StrTok(char** cursor, const char *delimiters); 105 106 DENG_PUBLIC char* M_TrimmedFloat(float val); 107 108 DENG_PUBLIC void M_ForceUppercase(char *text); 109 110 /// @return @c true if @a string can be interpreted as a valid integer. 111 DENG_PUBLIC dd_bool M_IsStringValidInt(const char* str); 112 113 /// @return @c true if @a string can be interpreted as a valid byte. 114 DENG_PUBLIC dd_bool M_IsStringValidByte(const char* str); 115 116 /// @return @c true if @a string can be interpreted as a valid floating-point value. 117 DENG_PUBLIC dd_bool M_IsStringValidFloat(const char* str); 118 119 /// @} 120 121 #ifdef __cplusplus 122 } // extern "C" 123 #endif 124 125 #endif // LIBDENG_STRING_UTIL_H 126