| 1 | /* ***** BEGIN LICENSE BLOCK ***** |
| 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 3 | * |
| 4 | * Copyright (C) 2002-2022 Németh László |
| 5 | * |
| 6 | * The contents of this file are subject to the Mozilla Public License Version |
| 7 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 | * the License. You may obtain a copy of the License at |
| 9 | * http://www.mozilla.org/MPL/ |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 | * for the specific language governing rights and limitations under the |
| 14 | * License. |
| 15 | * |
| 16 | * Hunspell is based on MySpell which is Copyright (C) 2002 Kevin Hendricks. |
| 17 | * |
| 18 | * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno, |
| 19 | * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád, |
| 20 | * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter, |
| 21 | * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls, |
| 22 | * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen |
| 23 | * |
| 24 | * Alternatively, the contents of this file may be used under the terms of |
| 25 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 27 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 28 | * of those above. If you wish to allow use of your version of this file only |
| 29 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 30 | * use your version of this file under the terms of the MPL, indicate your |
| 31 | * decision by deleting the provisions above and replace them with the notice |
| 32 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 33 | * the provisions above, a recipient may use your version of this file under |
| 34 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 35 | * |
| 36 | * ***** END LICENSE BLOCK ***** */ |
| 37 | |
| 38 | #ifndef W_CHAR_HXX_ |
| 39 | #define W_CHAR_HXX_ |
| 40 | |
| 41 | #include <string> |
| 42 | |
| 43 | #if __cplusplus >= 202002L |
| 44 | #include <bit> |
| 45 | #else |
| 46 | #include <cstring> |
| 47 | #endif |
| 48 | |
| 49 | #ifndef GCC |
| 50 | struct w_char { |
| 51 | #else |
| 52 | struct __attribute__((packed)) w_char { |
| 53 | #endif |
| 54 | unsigned char l; |
| 55 | unsigned char h; |
| 56 | |
| 57 | operator unsigned short() const |
| 58 | { |
| 59 | #if defined(__i386__) || defined(_M_IX86) || defined(_M_X64) |
| 60 | //use little-endian optimized version |
| 61 | #if __cplusplus >= 202002L |
| 62 | return std::bit_cast<unsigned short>(*this); |
| 63 | #else |
| 64 | unsigned short u; |
| 65 | memcpy(&u, this, sizeof(unsigned short)); |
| 66 | return u; |
| 67 | #endif |
| 68 | |
| 69 | #else |
| 70 | return ((unsigned short)h << 8) | (unsigned short)l; |
| 71 | #endif |
| 72 | } |
| 73 | |
| 74 | friend bool operator<(const w_char a, const w_char b) { |
| 75 | return (unsigned short)a < (unsigned short)b; |
| 76 | } |
| 77 | |
| 78 | friend bool operator==(const w_char a, const w_char b) { |
| 79 | return (unsigned short)a == (unsigned short)b; |
| 80 | } |
| 81 | |
| 82 | friend bool operator!=(const w_char a, const w_char b) { |
| 83 | return !(a == b); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | // two character arrays |
| 88 | struct replentry { |
| 89 | std::string pattern; |
| 90 | std::string outstrings[4]; // med, ini, fin, isol |
| 91 | }; |
| 92 | |
| 93 | #endif |
| 94 | |