00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // 00004 // $Id: String.cxx,v 1.1.1.1 2005/04/21 01:15:12 zhangy Exp $ 00005 // 00006 // Description: 00007 // The functions, within this namespace, are needed by BaBar to replace 00008 // those lost in the rw to STL string migration. 00009 // 00010 // Environment: 00011 // Software developed for the BaBar Detector at the SLAC B-Factory. 00012 // 00013 // Author List: 00014 // A. De Silva 00015 // 00016 // Copyright Information: 00017 // 00018 //------------------------------------------------------------------------ 00019 00020 00021 #include "MdcRecoUtil/String.h" 00022 00023 #include <string> 00024 #include <iostream> 00025 00026 int 00027 bes::String::compare_nocase(const std::string& s, const std::string& s2) { 00028 std::string::const_iterator p = s.begin(); 00029 std::string::const_iterator p2 = s2.begin(); 00030 00031 while (p != s.end() && p2 != s2.end() ) { 00032 if (toupper(*p) != toupper(*p2)) 00033 return (toupper(*p) < toupper(*p2)) ? -1 : 1; 00034 ++p; 00035 ++p2; 00036 } 00037 return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1; 00038 } 00039 00040 int 00041 bes::String::find_nocase(const std::string& s, const std::string& s2) { 00042 std::string str1 = s; 00043 transformToUpper(str1); 00044 std::string str2 = s2; 00045 transformToUpper(str2); 00046 return str1.find(str2); 00047 } 00048 00049 std::string 00050 bes::String::toLower(const std::string& str) { 00051 std::string result(str); 00052 transformToLower(result); 00053 return result; 00054 } 00055 00056 std::string 00057 bes::String::toUpper(const std::string& str) { 00058 std::string result(str); 00059 transformToUpper(result); 00060 return result; 00061 } 00062 00063 unsigned int 00064 bes::String::rwHash(const std::string& str){ 00065 const char* data = str.c_str(); 00066 int length = str.size(), total=0; 00067 for ( int i=0; i<length; i++ ) total += data[i]; 00068 return total; 00069 } 00070 00071