OW_GenCaseFoldingCompareTests.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-2004 Vintela, Inc All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00035 #include "OW_String.hpp"
00036 #include "OW_Array.hpp"
00037 #include "OW_StringStream.hpp"
00038 #include "OW_UTF8Utils.hpp"
00039 #include <fstream>
00040 #include <iostream>
00041 #include <assert.h>
00042 
00043 using namespace std;
00044 using namespace OpenWBEM;
00045 
00046 StringArray sa1;
00047 StringArray sa2;
00048 
00049 void printStrings(const String& str1, const String& str2)
00050 {
00051    cout << "\tunitAssert(UTF8Utils::compareToIgnoreCase(\"";
00052    for (int i = 0; i < str1.length(); ++i)
00053    {
00054       cout << hex << "\\x" << (int)(unsigned char)str1[i];
00055    }
00056    cout << "\", \"";
00057    for (int i = 0; i < str2.length(); ++i)
00058    {
00059       cout << hex << "\\x" << (int)(unsigned char)str2[i];
00060    }
00061    cout << "\") == 0)\n";
00062 }
00063 
00064 
00065 
00066 struct processLine
00067 {
00068    void operator()(const String& s) const
00069    {
00070       if (s.empty() || !isxdigit(s[0]))
00071          return;
00072 
00073       StringArray a = s.tokenize(";"); // split up fields
00074       assert(a.size() >= 3);
00075       UInt32 c1 = a[0].toUInt32(16);
00076       StringArray a2 = a[2].tokenize(" "); // split up chars are separated by spaces
00077       Array<UInt32> c2chars(a2.size());
00078       for (size_t i = 0; i < a2.size(); ++i)
00079       {
00080          c2chars[i] = a2[i].toUInt32(16);
00081       }
00082       String str1 = UTF8Utils::UCS4toUTF8(c1);
00083       String str2;
00084       for (size_t i = 0; i < c2chars.size(); ++i)
00085       {
00086          str2 += UTF8Utils::UCS4toUTF8(c2chars[i]);
00087       }
00088 
00089       sa1.push_back(str1);
00090       sa2.push_back(str2);
00091       sa1.push_back(str2);
00092       sa2.push_back(str1);
00093    }
00094 };
00095 
00096 int main(int argc, char** argv)
00097 {
00098    if (argc != 2)
00099    {
00100       cerr << "must pass filename (to CaseFolding.txt)" << endl;
00101       return 1;
00102    }
00103 
00104    ifstream in(argv[1]);
00105    if (!in)
00106    {
00107       cerr << "could not open " << argv[1] << endl;
00108       return 1;
00109    }
00110 
00111    // add transitions for equal matches
00112    for (int i = 1; i < 256; ++i)
00113    {
00114       String s = String(char(i));
00115       sa1.push_back(s);
00116       sa2.push_back(s);
00117    }
00118 
00119    // read in a process the input file
00120    OStringStream ss;
00121    ss << in.rdbuf();
00122    String s = ss.toString();
00123    StringArray sa = s.tokenize("\n");
00124    for_each(sa.begin(), sa.end(), processLine());
00125    // do 1-1 comparisons
00126    for (int i = 0; i < sa1.size(); ++i)
00127    {
00128       printStrings(sa1[i], sa2[i]);
00129    }
00130    // do 10-10 comparisons
00131    for (int i = 0; i < sa1.size();)
00132    {
00133       String s1, s2;
00134       for (int j = 0; j < 10 && i < sa1.size(); ++j, ++i)
00135       {
00136          s1 += sa1[i];
00137          s2 += sa2[i];
00138       }
00139       printStrings(s1, s2);
00140    }
00141 }
00142 

Generated on Thu Feb 9 08:47:59 2006 for openwbem by  doxygen 1.4.6