mux/src/stringutil.h

Go to the documentation of this file.
00001 // stringutil.h -- string utilities.
00002 //
00003 // $Id: stringutil.h,v 1.43 2006/09/11 23:57:47 sdennis Exp $
00004 //
00005 // MUX 2.4
00006 // Copyright (C) 1998 through 2004 Solid Vertical Domains, Ltd. All
00007 // rights not explicitly given are reserved.
00008 //
00009 #ifndef STRINGUTIL_H
00010 #define STRINGUTIL_H
00011 
00012 extern const bool mux_isprint[256];
00013 extern const bool mux_isdigit[256];
00014 extern const bool mux_ishex[256];
00015 extern const bool mux_isazAZ[256];
00016 extern const bool mux_isalpha[256];
00017 extern const bool mux_isalnum[256];
00018 extern const bool mux_islower[256];
00019 extern const bool mux_isupper[256];
00020 extern const bool mux_isspace[256];
00021 extern bool mux_AttrNameInitialSet[256];
00022 extern bool mux_AttrNameSet[256];
00023 extern const bool mux_ObjectNameSet[256];
00024 extern bool mux_PlayerNameSet[256];
00025 extern const bool mux_issecure[256];
00026 extern const bool mux_isescape[256];
00027 extern const unsigned char mux_hex2dec[256];
00028 extern const unsigned char mux_toupper[256];
00029 extern const unsigned char mux_tolower[256];
00030 extern const unsigned char mux_StripAccents[256];
00031 
00032 #define mux_isprint(x) (mux_isprint[(unsigned char)(x)])
00033 #define mux_isdigit(x) (mux_isdigit[(unsigned char)(x)])
00034 #define mux_ishex(x)   (mux_ishex[(unsigned char)(x)])
00035 #define mux_isazAZ(x)  (mux_isazAZ[(unsigned char)(x)])
00036 #define mux_isalpha(x) (mux_isalpha[(unsigned char)(x)])
00037 #define mux_isalnum(x) (mux_isalnum[(unsigned char)(x)])
00038 #define mux_islower(x) (mux_islower[(unsigned char)(x)])
00039 #define mux_isupper(x) (mux_isupper[(unsigned char)(x)])
00040 #define mux_isspace(x) (mux_isspace[(unsigned char)(x)])
00041 #define mux_hex2dec(x) (mux_hex2dec[(unsigned char)(x)])
00042 #define mux_toupper(x) (mux_toupper[(unsigned char)(x)])
00043 #define mux_tolower(x) (mux_tolower[(unsigned char)(x)])
00044 
00045 #define mux_AttrNameInitialSet(x) (mux_AttrNameInitialSet[(unsigned char)(x)])
00046 #define mux_AttrNameSet(x)        (mux_AttrNameSet[(unsigned char)(x)])
00047 #define mux_ObjectNameSet(x)      (mux_ObjectNameSet[(unsigned char)(x)])
00048 #define mux_PlayerNameSet(x)      (mux_PlayerNameSet[(unsigned char)(x)])
00049 #define mux_issecure(x)           (mux_issecure[(unsigned char)(x)])
00050 #define mux_isescape(x)           (mux_isescape[(unsigned char)(x)])
00051 #define mux_StripAccents(x)       (mux_StripAccents[(unsigned char)(x)])
00052 
00053 int ANSI_lex(int nString, const char *pString, int *nLengthToken0, int *nLengthToken1);
00054 #define TOKEN_TEXT_ANSI 0 // Text sequence + optional ANSI sequence.
00055 #define TOKEN_ANSI      1 // ANSI sequence.
00056 
00057 typedef struct
00058 {
00059     char *pString;
00060     char aControl[256];
00061 } MUX_STRTOK_STATE;
00062 
00063 void mux_strtok_src(MUX_STRTOK_STATE *tts, char *pString);
00064 void mux_strtok_ctl(MUX_STRTOK_STATE *tts, char *pControl);
00065 char *mux_strtok_parseLEN(MUX_STRTOK_STATE *tts, int *pnLen);
00066 char *mux_strtok_parse(MUX_STRTOK_STATE *tts);
00067 char *RemoveSetOfCharacters(char *pString, char *pSetToRemove);
00068 
00069 size_t mux_ltoa(long val, char *buf);
00070 char *mux_ltoa_t(long val);
00071 void safe_ltoa(long val, char *buff, char **bufc);
00072 size_t mux_i64toa(INT64 val, char *buf);
00073 char *mux_i64toa_t(INT64 val);
00074 void safe_i64toa(INT64 val, char *buff, char **bufc);
00075 long mux_atol(const char *pString);
00076 INT64 mux_atoi64(const char *pString);
00077 double mux_atof(char *szString, bool bStrict = true);
00078 char *mux_ftoa(double r, bool bRounded, int frac);
00079 
00080 bool is_integer(char *, int *);
00081 bool is_rational(char *);
00082 bool is_real(char *);
00083 
00084 #pragma pack(1)
00085 typedef struct
00086 {
00087     unsigned char bNormal:1;
00088     unsigned char bBlink:1;
00089     unsigned char bHighlite:1;
00090     unsigned char bInverse:1;
00091     unsigned char bUnder:1;
00092 
00093     unsigned char iForeground:4;
00094     unsigned char iBackground:4;
00095 } ANSI_ColorState;
00096 #pragma pack()
00097 
00098 struct ANSI_In_Context
00099 {
00100     ANSI_ColorState m_acs;
00101     const char     *m_p;
00102     int             m_n;
00103     bool            m_bSawNormal;
00104 };
00105 
00106 struct ANSI_Out_Context
00107 {
00108     int             m_iEndGoal;
00109     ANSI_ColorState m_acs;
00110     bool            m_bDone; // some constraint was met.
00111     char           *m_p;
00112     int             m_n;
00113     int             m_nMax;
00114     int             m_vw;
00115     int             m_vwMax;
00116 };
00117 
00118 #define ANSI_ENDGOAL_NORMAL  0
00119 #define ANSI_ENDGOAL_NOBLEED 1
00120 #define ANSI_ENDGOAL_LEAK    2
00121 
00122 extern void ANSI_String_In_Init(struct ANSI_In_Context *pacIn, const char *szString, int iEndGoal);
00123 extern void ANSI_String_Out_Init(struct ANSI_Out_Context *pacOut, char *pField, int nField, int vwMax, int iEndGoal);
00124 extern void ANSI_String_Skip(struct ANSI_In_Context *pacIn, int maxVisualWidth, int *pnVisualWidth);
00125 extern void ANSI_String_Copy(struct ANSI_Out_Context *pacOut, struct ANSI_In_Context *pacIn, int vwMax);
00126 extern int ANSI_String_Finalize(struct ANSI_Out_Context *pacOut, int *pnVisualWidth);
00127 extern char *ANSI_TruncateAndPad_sbuf(const char *pString, int nMaxVisualWidth, char fill = ' ');
00128 extern int ANSI_TruncateToField(const char *szString, int nField, char *pField, int maxVisual, int *nVisualWidth, int iEndGoal);
00129 extern char *strip_ansi(const char *szString, size_t *pnString = 0);
00130 extern char *strip_accents(const char *szString, size_t *pnString = 0);
00131 extern char *normal_to_white(const char *);
00132 extern char *munge_space(const char *);
00133 extern char *trim_spaces(char *);
00134 extern char *grabto(char **, char);
00135 extern int  string_compare(const char *, const char *);
00136 extern int  string_prefix(const char *, const char *);
00137 extern const char * string_match(const char * ,const char *);
00138 extern char *replace_string(const char *, const char *, const char *);
00139 extern char *replace_tokens
00140 (
00141     const char *s,
00142     const char *pBound,
00143     const char *pListPlace,
00144     const char *pSwitch
00145 );
00146 #if 0
00147 extern int prefix_match(const char *, const char *);
00148 extern char *BufferCloneLen(const char *pBuffer, unsigned int nBuffer);
00149 #endif // 0
00150 extern bool minmatch(char *str, char *target, int min);
00151 extern char *StringCloneLen(const char *str, size_t nStr);
00152 extern char *StringClone(const char *str);
00153 void safe_copy_str(const char *src, char *buff, char **bufp, int max);
00154 void safe_copy_str_lbuf(const char *src, char *buff, char **bufp);
00155 size_t safe_copy_buf(const char *src, size_t nLen, char *buff, char **bufp);
00156 size_t safe_fill(char *buff, char **bufc, char chFile, size_t nSpaces);
00157 extern bool matches_exit_from_list(char *, const char *);
00158 extern char *translate_string(const char *, bool);
00159 extern int mux_stricmp(const char *a, const char *b);
00160 extern int mux_memicmp(const void *p1_arg, const void *p2_arg, size_t n);
00161 extern void mux_strlwr(char *tp);
00162 extern void mux_strupr(char *a);
00163 
00164 typedef struct tag_itl
00165 {
00166     bool bFirst;
00167     char chPrefix;
00168     char chSep;
00169     char *buff;
00170     char **bufc;
00171     size_t nBufferAvailable;
00172 } ITL;
00173 
00174 void ItemToList_Init(ITL *pContext, char *arg_buff, char **arg_bufc,
00175     char arg_chPrefix = 0, char arg_chSep = ' ');
00176 bool ItemToList_AddInteger(ITL *pContext, int i);
00177 bool ItemToList_AddString(ITL *pContext, char *pStr);
00178 bool ItemToList_AddStringLEN(ITL *pContext, size_t nStr, char *pStr);
00179 void ItemToList_Final(ITL *pContext);
00180 
00181 int DCL_CDECL mux_vsnprintf(char *buff, int count, const char *fmt, va_list va);
00182 int GetLineTrunc(char *Buffer, size_t nBuffer, FILE *fp);
00183 
00184 typedef struct
00185 {
00186     int m_d[256];
00187     int m_skip2;
00188 } BMH_State;
00189 
00190 extern void BMH_Prepare(BMH_State *bmhs, int nPat, const char *pPat);
00191 extern int  BMH_Execute(BMH_State *bmhs, int nPat, const char *pPat, int nSrc, const char *pSrc);
00192 extern int  BMH_StringSearch(int nPat, const char *pPat, int nSrc, const char *pSrc);
00193 extern void BMH_PrepareI(BMH_State *bmhs, int nPat, const char *pPat);
00194 extern int  BMH_ExecuteI(BMH_State *bmhs, int nPat, const char *pPat, int nSrc, const char *pSrc);
00195 extern int  BMH_StringSearchI(int nPat, const char *pPat, int nSrc, const char *pSrc);
00196 
00197 struct ArtRuleset
00198 {
00199     ArtRuleset* m_pNextRule;
00200 
00201     void* m_pRegexp;
00202     void *m_pRegexpStudy;
00203     int m_bUseAn;
00204 };
00205 
00206 typedef struct
00207 {
00208     int         iLeadingSign;
00209     int         iString;
00210     const char  *pDigitsA;
00211     size_t      nDigitsA;
00212     const char  *pDigitsB;
00213     size_t      nDigitsB;
00214     int         iExponentSign;
00215     const char  *pDigitsC;
00216     size_t      nDigitsC;
00217     const char  *pMeat;
00218     size_t      nMeat;
00219 
00220 } PARSE_FLOAT_RESULT;
00221 
00222 extern bool ParseFloat(PARSE_FLOAT_RESULT *pfr, const char *str, bool bStrict = true);
00223 
00224 #endif // STRINGUTIL_H

Generated on Mon May 28 04:40:11 2007 for MUX by  doxygen 1.4.7