Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ustring.cc

Go to the documentation of this file.
00001 /* ===========================================================================
00002  *        Filename:  ustring.cc
00003  *     Description:  Unified string class
00004  * 
00005  *         Version:  $Rev: 3 $
00006  *         Changed:  $Date: 2005-03-02 14:30:37 -0800 (Mi, 02 Mär 2005) $
00007  *         Licence:  GPL (read COPYING file for details)
00008  * 
00009  *          Author:  Erich Schubert (eS), erich@debian.org
00010  *                   Institut für Informatik, LMU München
00011  * ======================================================================== */
00012 
00013 #include "ustring.h"
00014 #include "config.h"
00015 
00016 using namespace std;
00017 using namespace __gnu_cxx;
00018 
00019 namespace SSD {
00020 
00021         ustring::ustring(const char* s) {
00022                 const char* string=s;
00023                 if (!s) {
00024                         cstr = NULL;
00025                         return;
00026                 }
00027 
00028 #ifndef KEEP_WHITESPACE
00029                 /* skip all whitespace */
00030                 while(isspace(*string)) { string++; }
00031                 /* empty strings are also NULL */
00032 #endif
00033                 if (!*string) {
00034                         cstr = NULL;
00035                         return;
00036                 }
00037 
00038                 /* unify text string */
00039                 hash_map< const char*, const char*, hash<char*>, eq_str>::iterator iter = store.find(string);
00040                 if (iter == store.end()) {
00041                         /* duplicate string */
00042                         cstr = strdup(string);
00043                         /* insert into hashmap */
00044                         store[cstr]=cstr;
00045                 } else
00046                         /* return same string as before */
00047                         cstr = iter->second;
00048                 return;
00049         }
00050 
00051         ustring::ustring(const xmlChar* s) {
00052                 const char* string=(const char*) s;
00053                 if (!s) {
00054                         cstr = NULL;
00055                         return;
00056                 }
00057 
00058 #ifndef KEEP_WHITESPACE
00059                 /* skip all whitespace */
00060                 while(isspace(*string)) { string++; }
00061                 /* empty strings are also NULL */
00062 #endif
00063                 if (!*string) {
00064                         cstr = NULL;
00065                         return;
00066                 }
00067 
00068                 /* unify text string */
00069                 hash_map< const char*, const char*, hash<char*>, eq_str>::iterator iter = store.find(string);
00070                 if (iter == store.end()) {
00071                         /* duplicate string */
00072                         cstr = strdup(string);
00073                         /* insert into hashmap */
00074                         store[cstr]=cstr;
00075                 } else
00076                         /* return same string as before */
00077                         cstr = iter->second;
00078                 return;
00079         }
00080 
00081         std::ostream &operator<<(std::ostream &out, const ustring& str) {
00082                 if (str.cstr) out << str.cstr;
00083                 return out;
00084         }
00085 
00086         hash_map< const char*, const char*, hash<char*>, eq_str> ustring::store;
00087 }

Generated on Thu Aug 4 17:57:12 2005 for SSDDiff by  doxygen 1.4.3-20050530