File indexing completed on 2024-03-24 17:24:18
0001 /***************************************************************************** 0002 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #include <qtcurve-utils/map.h> 0023 #include <assert.h> 0024 #include <ctype.h> 0025 0026 #define STRINGS "jk", "yz", "OP", "LM", "XY", "FG", "MN", "st", "VW", "qr", \ 0027 "vw", "bc", "xy", "gh", "cd", "mn", "op", "ab", "[\\", "WX", "BC", \ 0028 "CD", "IJ", "QR", "Z[", "uv", "_`", "ij", "hi", "no", "HI", "DE", \ 0029 "YZ", "PQ", "ef", "de", "pq", "tu", "fg", "lm", "JK", "kl", "AB", \ 0030 "KL", "TU", "]^", "ST", "EF", "z{", "RS", "wx", "^_", "rs", "`a", \ 0031 "\\]", "UV", "GH", "NO" 0032 0033 #define CASE_STRINGS "m_n", "tpu", "xty", "h`i", "\\l]", "_]`", "vnw", "_q`", \ 0034 "wyx", "oap", "ppq", "isj", "^v_", "k]l", "y_z", "]s^", "e[f", "w]x", \ 0035 "`pa", "^j_", "nro", "uwv", "[e\\", "cud", "cmd", "rns", "ugv", \ 0036 "fvg", "ewf", "rrs", "^b_", "ltm", "e_f", "cad", "t\\u", "vjw", \ 0037 "t`u", "cid", "q[r", "oqp", "gah", "lhm", "r^s", "ikj", "wex", "agb", \ 0038 "]w^", "p\\q", "awb", "acb", "_y`", "`da", "fjg", "qsr", "]g^", \ 0039 "usv", "kel", "p`q", "qcr", "icj", "tdu", "hpi", "^z_", "vvw", "kal", \ 0040 "ekf", "`ha", "akb", "dhe", "dte", "frg", "kul", "nno", "`\\a", \ 0041 "guh", "ffg", "omp", "qor", "hli", "igj", "oyp", "`ta", "ldm", "ywz", \ 0042 "jnk", "jrk", "\\`]", "njo", "mkn", "wix", "zb{", "ttu", "jzk", \ 0043 "oep", "zr{", "dle", "dpe", "xdy", "uov", "[y\\", "kyl", "zv{", \ 0044 "smt", "wax", "thu", "xpy", "d`e", "gih", "lpm", "h\\i", "x\\y", \ 0045 "[a\\", "fzg", "zz{", "sat", "eof", "[]\\", "hti", "v^w", "syt", \ 0046 "mgn", "y[z", "jfk", "s]t", "kil", "esf", "bnc", "oup", "set", "ycz", \ 0047 "aob", "wux", "pxq", "ygz", "mwn", "z^{", "xhy", "dxe", "i_j", "a[b", \ 0048 "q_r", "\\t]", "^^_", "n^o", "zn{", "sit", "bfc", "mcn", "rfs", \ 0049 "brc", "bjc", "\\d]", "ioj", "f^g", "\\h]", "iwj", "nzo", "u_v", \ 0050 "oip", "sqt", "vfw", "`la", "jbk", "hxi", "llm", "fbg", "phq", "jjk", \ 0051 "gyh", "qkr", "_m`", "nfo", "[i\\", "rvs", "bzc", "ukv", "u[v", \ 0052 "nvo", "_u`", "geh", "nbo", "bbc", "dde", "xly", "bvc", "qwr", "_a`", \ 0053 "ecf", "zj{", "tlu", "]k^", "a_b", "kql", "]c^", "][^", "wmx", "l`m", \ 0054 "^r_", "x`y", "rzs", "qgr", "_e`", "hdi", "\\x]", "\\p]", "ced", \ 0055 "sut", "[m\\", "cqd", "fng", "]_^", "d\\e", "kml", "txu", "m[n", \ 0056 "vzw", "gmh", "zf{", "vbw", "lxm", "rbs", "[q\\", "cyd", "rjs", \ 0057 "^n_", "j^k", "pdq", "vrw", "plq", "yoz", "mon", "b^c", "i[j", \ 0058 "l\\m", "\\\\]", "_i`", "egf", "hhi", "ysz", "gqh", "c]d", "xxy", \ 0059 "msn", "``a", "jvk", "asb", "ucv", "]o^", "ptq", "ykz", "o]p", "`xa", \ 0060 "[u\\", "g]h", "wqx", "^f_" 0061 0062 static int 0063 search_map(const char *str) 0064 { 0065 static const QtCurve::StrMap<> auto_map(STRINGS); 0066 return auto_map.search(str); 0067 } 0068 0069 #ifndef __clang__ 0070 // clang doesn't like template recursion deeper than 256 levels.... 0071 static int 0072 search_case_map(const char *str) 0073 { 0074 static const QtCurve::StrMap<int, false> auto_map(CASE_STRINGS); 0075 return auto_map.search(str); 0076 } 0077 #endif 0078 0079 int 0080 main() 0081 { 0082 const char *real_order[] = {STRINGS}; 0083 char key[4]; 0084 key[3] = 0; 0085 for (char i = 0;i < 127;i++) { 0086 key[0] = i; 0087 for (char j = 0;j < 127;j++) { 0088 key[1] = j; 0089 for (char k = 0;k < 127;k++) { 0090 key[2] = k; 0091 int res = search_map(key); 0092 if (i >= 'A' && i <= 'z' && j == i + 1 && k == 0) { 0093 assert(res != -1 && strcmp(real_order[res], key) == 0); 0094 } else { 0095 assert(res == -1); 0096 } 0097 } 0098 } 0099 } 0100 #ifndef __clang__ 0101 const char *case_real_order[] = {CASE_STRINGS}; 0102 for (char i = 0;i < 127;i++) { 0103 key[0] = i; 0104 for (char j = 0;j < 127;j++) { 0105 key[1] = j; 0106 for (char k = 0;k < 127;k++) { 0107 key[2] = k; 0108 int res = search_case_map(key); 0109 char _i = tolower(i); 0110 char _j = tolower(j); 0111 char _k = tolower(k); 0112 if (_i > 'Z' && _i <= 'z' && _j > 'Z' && _j <= 'z' && 0113 _k == _i + 1 && (_i + _j) % 4 == 0) { 0114 assert(res != -1 && 0115 strcasecmp(case_real_order[res], key) == 0); 0116 } else { 0117 assert(res == -1); 0118 } 0119 } 0120 } 0121 } 0122 #endif 0123 return 0; 0124 }