[ci] Fix clang-santisers job for GHA change
[xapian.git] / xapian-core / languages / stem.cc
blob7446a0758f96948a2304ea835a4802b5d5ae2710
1 /** @file
2 * @brief Implementation of Xapian::Stem API class.
3 */
4 /* Copyright (C) 2007,2008,2010,2011,2012,2015,2018,2019,2024 Olly Betts
5 * Copyright (C) 2010 Evgeny Sizikov
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <config.h>
24 #include <xapian/stem.h>
26 #include <xapian/error.h>
28 #include "steminternal.h"
30 #include "allsnowballheaders.h"
31 #include "keyword.h"
32 #include "sbl-dispatch.h"
34 #include <string>
35 #include <string_view>
37 using namespace std;
39 namespace Xapian {
41 Stem::Stem(std::string_view language, bool fallback)
43 int l = keyword2(tab, language.data(), language.size());
44 if (l >= 0) {
45 switch (static_cast<sbl_code>(l)) {
46 case ARABIC:
47 internal = new InternalStemArabic;
48 return;
49 case ARMENIAN:
50 internal = new InternalStemArmenian;
51 return;
52 case BASQUE:
53 internal = new InternalStemBasque;
54 return;
55 case CATALAN:
56 internal = new InternalStemCatalan;
57 return;
58 case DANISH:
59 internal = new InternalStemDanish;
60 return;
61 case DUTCH:
62 internal = new InternalStemDutch;
63 return;
64 case EARLYENGLISH:
65 internal = new InternalStemEarlyenglish;
66 return;
67 case ENGLISH:
68 internal = new InternalStemEnglish;
69 return;
70 case FINNISH:
71 internal = new InternalStemFinnish;
72 return;
73 case FRENCH:
74 internal = new InternalStemFrench;
75 return;
76 case GERMAN:
77 internal = new InternalStemGerman;
78 return;
79 case GERMAN2:
80 internal = new InternalStemGerman2;
81 return;
82 case HUNGARIAN:
83 internal = new InternalStemHungarian;
84 return;
85 case INDONESIAN:
86 internal = new InternalStemIndonesian;
87 return;
88 case IRISH:
89 internal = new InternalStemIrish;
90 return;
91 case ITALIAN:
92 internal = new InternalStemItalian;
93 return;
94 case KRAAIJ_POHLMANN:
95 internal = new InternalStemKraaij_pohlmann;
96 return;
97 case LITHUANIAN:
98 internal = new InternalStemLithuanian;
99 return;
100 case LOVINS:
101 internal = new InternalStemLovins;
102 return;
103 case NEPALI:
104 internal = new InternalStemNepali;
105 return;
106 case NORWEGIAN:
107 internal = new InternalStemNorwegian;
108 return;
109 case NONE:
110 return;
111 case PORTUGUESE:
112 internal = new InternalStemPortuguese;
113 return;
114 case PORTER:
115 internal = new InternalStemPorter;
116 return;
117 case RUSSIAN:
118 internal = new InternalStemRussian;
119 return;
120 case ROMANIAN:
121 internal = new InternalStemRomanian;
122 return;
123 case SPANISH:
124 internal = new InternalStemSpanish;
125 return;
126 case SWEDISH:
127 internal = new InternalStemSwedish;
128 return;
129 case TAMIL:
130 internal = new InternalStemTamil;
131 return;
132 case TURKISH:
133 internal = new InternalStemTurkish;
134 return;
137 if (fallback || language.empty())
138 return;
140 string m{"Language code "};
141 m += language;
142 m += " unknown";
143 throw Xapian::InvalidArgumentError(m);
146 string
147 Stem::operator()(const std::string &word) const
149 if (!internal || word.empty()) return word;
150 return internal->operator()(word);
153 string
154 Stem::get_description() const
156 string desc = "Xapian::Stem(";
157 if (internal) {
158 desc += internal->get_description();
159 desc += ')';
160 } else {
161 desc += "none)";
163 return desc;