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

GenCaseFoldingCompareTests.cpp

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

Generated on Mon Sep 12 23:56:34 2005 for blocxx by  doxygen 1.4.4