Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!umich!vela!schemers From: schemers@vela.acs.oakland.edu (Roland Schemers III) Newsgroups: comp.lang.c++ Subject: String class (some what long) Summary: new version! Message-ID: <2510@vela.acs.oakland.edu> Date: 12 Aug 90 23:13:06 GMT Reply-To: schemers@vela.acs.oakland.edu (Roland Schemers III) Organization: Oakland University, Rochester MI Lines: 94 Hello! For those of you using my String class, I thought I would mention I have a new release, which is quite improved over the last one. The main changes are with substrings and regular expressions. Since the SubString class is derived from the String class, you can now use any of the String functions safely with a SubString, for example: String s1("ab 12 cd"); s1.at("12") += "34"; // s1=="ab 1234 cd" s1="12 y 34"; s1.at("y").append("z").prepend("x").insert(0,"w"); // s1 =="12 wxyz 34" Also, You can now even input directly into a SubString: s1="hello XXX world"; cin >> s1.substr(6,3) ; // input from standard input to substring XXX type: there // s1 == "hello there world" --- The second major change is in the way the Regex class works. The Regex class is now derived from the StringSearch class, and you can now create your own class which is derived from the StringSearch class. Your class can then be used with any of the String functions that take a StringSearch argument. All you have to do is write the virtual search function. For example: class SSwhitespace : public StringSearch { public: SSwhitespace(){} int search(const String &s, int &matchlen) const ; }; int SSwhitespace::search(const String &s, int &len) const { int p1; StringIterator next(s); char ch; while (next(ch)) if (isspace(ch)) { p1=next.pos(); while (next(ch) && isspace(ch)); len=next.pos()-p1; // set length to length of match return p1; // return start of match } len=0; // set matched length to 0 return -1; // return -1, not found! } const SSwhitespace SSwhite; void main() { String s1("This is a test"); s1.at(SSwhite)=" "; // s1 == "This is a test" } Using this technique you can do away with the Regex class, and simply write your own searching functions. Note that you don't have to derive a class to use the StringSearch class, you can simply declare a StringSearch variable: int whitespace_search(const String &s, int &len) const StringSearch SSwhite(SS_whitespace); This example also shows the use of the new StringIterator class, which creates inline functions that safely step through a String. Classes derived from the StringSearch function could be quite powerful. You could write classes that lookup keywords in a symbol table, that use a hashing function and so on. Any ways, enough of my babbling, the new String class is avaible via anonymous ftp at vela.acs.oakland.edu (35.146.10.2). It is in pub/C++/String1.2.tar.Z, and is about 93K. cheers, Roland -- Roland J. Schemers III Systems Programmer schemers@vela.acs.oakland.edu (Ultrix) Oakland University schemers@argo.acs.oakland.edu (VMS) Rochester, MI 48309-4401 "Get off your LEF and do something!" (313)-370-4323