// @ZBS { // *MODULE_OWNER_NAME zstr // } #ifndef ZSTR_H #define ZSTR_H // This is a simplistic implementation of Perl-like variables // highly useful for quick string processing of files or other text. struct ZStrVar { ZStrVar *next; char *s; // Always holds a private copy therefore must be removed on destruct ZStrVar( char *_s=(char*)0, int len=-1 ); ~ZStrVar(); operator int(); operator short(); operator char(); operator float(); operator double(); operator char *(); ZStrVar *get(int x); char *getStr(int i); // Return the ith string or empty; int is(int i,char *compare); // Compare the ith string to compare, return 1 on same int getAsInt(int x); int defined() { return s != (char*)0; } void set( char *_s, int len=-1 ); }; ZStrVar *zStrSplitByRegExpPtr( void *_regExp, char *text ); // Like Perl Split, takes an RegExp * as the first parameter // type cast here as a void * to avoid header dependency ZStrVar *zStrSplit( char *regExp, char *text ); // Like Perl split, takes the regular expression as a string void zStrHashSplit( char *text, class ZHashTable *hashTable ); // splits the text into keyword value pairs and jams into the specified hashtable // eg: "name='Zack Booth' email='oink@oink.com'" // This is smart enough to deal with both single and double quotes as well as nested quotes // eg: "name='Zack\'s Room' email=\"\\\"Why Yes he said\\\"\""; char *zStrJoin( char *seperator, ZStrVar *head ); // Like perl join int zStrCount( ZStrVar *head ); // How many elements are in the linked list void zStrDelete( ZStrVar *head ); // delete an entire ZStrVar chain char *zStrEscapeQuote( char *text ); // escape any quotes with back-slashes. Allocates a 2x buffer are returns it void zStrChomp( char *str ); // Like Perl chomp, removes trailing CRs and LFs #endif