00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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(";");
00075 assert(a.size() >= 3);
00076 UInt32 c1 = a[0].toUInt32(16);
00077 StringArray a2 = a[2].tokenize(" ");
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
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
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
00127 for (int i = 0; i < sa1.size(); ++i)
00128 {
00129 printStrings(sa1[i], sa2[i]);
00130 }
00131
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