2000-02-25 10:15:17 +00:00
|
|
|
// This may look like C code, but it is really -*- C++ -*-
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// The Goldware Library
|
|
|
|
// Copyright (C) 1990-1999 Odinn Sorensen
|
|
|
|
// Copyright (C) 1999-2000 Alexander S. Aganichev
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this program; if not, write to the Free
|
|
|
|
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
// MA 02111-1307, USA
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// $Id$
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// String manipulation functions.
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
2000-03-23 17:19:54 +00:00
|
|
|
#ifndef __gstrall_h
|
|
|
|
#define __gstrall_h
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// Required headers
|
|
|
|
|
2000-03-23 17:19:54 +00:00
|
|
|
#include <string>
|
2007-01-08 09:48:18 +00:00
|
|
|
#include <vector>
|
2009-04-04 09:51:04 +00:00
|
|
|
#include <stdlib.h>
|
2000-02-25 10:15:17 +00:00
|
|
|
#include <gctype.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <gdefs.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if defined(__EMX__)
|
2010-04-29 22:29:11 +00:00
|
|
|
//old EMX 0.9d code
|
|
|
|
//#include <sys/nls.h>
|
|
|
|
//#define strupr(s) (char *)_nls_strupr((uint8_t *)(s))
|
|
|
|
//#define strlwr(s) (char *)_nls_strlwr((uint8_t *)(s))
|
|
|
|
//old EMX 0.9d code
|
2000-02-25 10:15:17 +00:00
|
|
|
#elif defined(__GNUC__)
|
2006-01-27 13:04:36 +00:00
|
|
|
#if defined(__QNXNTO__) || defined(__SUNOS__)
|
2003-04-16 08:43:49 +00:00
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
#define stricmp strcasecmp
|
|
|
|
#define strnicmp strncasecmp
|
|
|
|
char* strupr(char* s);
|
|
|
|
char* strlwr(char* s);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-01-08 09:48:18 +00:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef std::vector<std::string> gstrarray;
|
|
|
|
|
|
|
|
|
2000-02-25 10:15:17 +00:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// Function prototypes
|
|
|
|
|
|
|
|
bool strblank(const char* str);
|
2007-01-08 09:48:18 +00:00
|
|
|
size_t strchg(char *str, char oldch, char newch);
|
|
|
|
size_t strchg(std::string &str, char oldch, char newch);
|
2000-02-25 10:15:17 +00:00
|
|
|
char* stridela(const char* substr, char* str);
|
|
|
|
int strnicmpw(const char* str1, const char* str2, int len);
|
|
|
|
const char* striinc(const char* str1, const char* str2);
|
|
|
|
char* strins(const char* instr, char* str, int st_pos);
|
2005-10-12 05:15:00 +00:00
|
|
|
char* strisrep(char* str, const char* search, const char* replace);
|
2000-02-25 10:15:17 +00:00
|
|
|
char* strischg(char* str, const char* find, const char* replace);
|
2006-02-20 21:44:10 +00:00
|
|
|
void strischg(std::string &str, const char* find, const char* replace);
|
2000-02-25 10:15:17 +00:00
|
|
|
char* strrjust(char* str);
|
|
|
|
char* strschg(char* str, const char* find, const char* replace);
|
|
|
|
char* strsetsz(char* str, int newsize);
|
|
|
|
char* strshl(char* str, int count);
|
|
|
|
char* strshr(char* str, int count);
|
|
|
|
char* strsrep(char* str, const char* search, const char* replace);
|
|
|
|
char* strltrim(char* str);
|
|
|
|
char* strtrim(char* str);
|
2007-01-08 09:48:18 +00:00
|
|
|
std::string &strtrim(std::string &str);
|
|
|
|
std::string &strltrim(std::string &str);
|
2000-02-25 10:15:17 +00:00
|
|
|
char* struplow(char* str);
|
|
|
|
|
|
|
|
char* longdotstr(long num); // Convert a long to a dotted string: xxx.xxx.xxx.xxx
|
|
|
|
char* longdotstr(char* str, long num); // Convert a long to a dotted string: xxx.xxx.xxx.xxx
|
|
|
|
char* StripQuotes(char* str);
|
|
|
|
|
|
|
|
// Safe versions of strcpy, strcat, sequencial strcat...
|
2006-04-21 19:57:30 +00:00
|
|
|
TCHAR *strxcpy(TCHAR *d, const TCHAR *s, size_t n);
|
2010-03-28 17:21:39 +00:00
|
|
|
// strxcpy: copy not more n-1 bytes of "s" into "d", insert '\0' into end of string.
|
|
|
|
// return d
|
2000-02-25 10:15:17 +00:00
|
|
|
char* strxcat(char *dest, const char *src, size_t max);
|
|
|
|
char* strxmerge(char *dest, size_t max, ...);
|
|
|
|
|
|
|
|
char* strc2p(char* str);
|
|
|
|
char* strnp2c(char* str, int n);
|
|
|
|
char* strnp2cc(char* dest, const char* str, int n);
|
|
|
|
char* strp2c(char* str);
|
|
|
|
|
2001-01-27 11:52:13 +00:00
|
|
|
const char* strlword(const char* str, const char *separator=NULL);
|
|
|
|
const char* strrword(const char* str, const char *separator=NULL);
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
char* strrevname(char* reversedname, const char* name);
|
|
|
|
char* strunrevname(char* unreversedname, const char* name);
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// Inliners
|
|
|
|
|
|
|
|
#define STRNP2C(str) strnp2c(str, sizeof(str)-1)
|
|
|
|
|
|
|
|
inline char* strbtrim(char* st) { return strtrim(strltrim(st)); }
|
|
|
|
|
2006-05-14 18:37:26 +00:00
|
|
|
inline bool streql (const TCHAR *str1, const TCHAR *str2) { return (0 == strcmp (str1, str2)); }
|
|
|
|
inline bool strieql (const TCHAR *str1, const TCHAR *str2) { return (0 == stricmp (str1, str2)); }
|
|
|
|
inline bool strneql (const TCHAR *str1, const TCHAR *str2, int n) { return (0 == strncmp (str1, str2, n)); }
|
|
|
|
inline bool strnieql(const TCHAR *str1, const TCHAR *str2, int n) { return (0 == strnicmp(str1, str2, n)); }
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
inline const char* strskip_to(const char* p, char* s) { return p+strcspn(p, s); }
|
|
|
|
inline char* strskip_to(char* p, char* s) { return p+strcspn(p, s); }
|
|
|
|
|
|
|
|
inline const char* strskip_to(const char* p, char c) { while((*p != c) and *p) p++; return p; }
|
|
|
|
inline char* strskip_to(char* p, char c) { while((*p != c) and *p) p++; return p; }
|
|
|
|
|
|
|
|
inline const char* strskip_txt(const char* p) { while(*p and not isspace(*p)) p++; return p; }
|
|
|
|
inline char* strskip_txt(char* p) { while(*p and not isspace(*p)) p++; return p; }
|
|
|
|
|
|
|
|
inline const char* strskip_wht(const char* p) { while(*p and isspace(*p)) p++; return p; }
|
|
|
|
inline char* strskip_wht(char* p) { while(*p and isspace(*p)) p++; return p; }
|
|
|
|
|
|
|
|
inline const char* strskip_digits(const char* p) { return p+strspn(p, "0123456789"); }
|
|
|
|
inline char* strskip_digits(char* p) { return p+strspn(p, "0123456789"); }
|
|
|
|
|
2009-08-13 13:28:16 +00:00
|
|
|
#if defined(_MSC_VER) || (defined(__GNUC__) && (defined(__WIN32__) || defined(__SUNOS__))) || defined(__WATCOMC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
2000-02-25 10:15:17 +00:00
|
|
|
inline char * stpcpy(char* dest, const char* src) {
|
|
|
|
while ((*dest++ = *src++) != NUL) {}
|
|
|
|
return --dest;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef isoctal
|
|
|
|
#define isoctal(c) (((c) >= '0') and ((c) <= '7'))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char* strcvtc(char* s);
|
|
|
|
|
2006-05-13 16:15:35 +00:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define PRINTF_DECLARE_BUFFER(b) b, ARRAYSIZE(b), __FILE__, __LINE__
|
|
|
|
int gsprintf(TCHAR* buffer, size_t sizeOfBuffer, const TCHAR* __file, int __line, const TCHAR* format, ...);
|
|
|
|
|
2007-01-19 17:38:41 +00:00
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string &FormatString(std::string &format, const char *token, const char *replace);
|
|
|
|
std::string &FormatString(std::string &format, const char *token, size_t replace);
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// String tokenizer class
|
|
|
|
|
2007-01-08 09:48:18 +00:00
|
|
|
void tokenize(gstrarray &array, const TCHAR* str, const TCHAR *delim = NULL);
|
|
|
|
|
2006-04-21 19:57:30 +00:00
|
|
|
class GTok
|
|
|
|
{
|
2000-02-25 10:15:17 +00:00
|
|
|
protected:
|
2006-04-21 19:57:30 +00:00
|
|
|
const TCHAR *separator;
|
|
|
|
TCHAR *token;
|
|
|
|
#if defined(_tcstok_s)
|
|
|
|
TCHAR *next_token;
|
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
public:
|
2006-04-21 19:57:30 +00:00
|
|
|
GTok(TCHAR *sep = NULL);
|
|
|
|
|
|
|
|
#if defined(_tcstok_s)
|
|
|
|
TCHAR *First(TCHAR *buf) { token = _tcstok_s(buf, separator, &next_token); return token; }
|
|
|
|
TCHAR *Next() { token = _tcstok_s(NULL, separator, &next_token); return token; }
|
|
|
|
#else
|
2006-05-14 18:37:26 +00:00
|
|
|
TCHAR *First(TCHAR *buf) { token = strtok(buf, separator); return token; }
|
|
|
|
TCHAR *Next() { token = strtok(NULL, separator); return token; }
|
2006-04-21 19:57:30 +00:00
|
|
|
#endif
|
|
|
|
TCHAR *Token() { return token; }
|
2000-02-25 10:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|