commit 8eb609e38b53f324c1b46521e7ec88227f84461a Author: Daniel Swanson Date: Mon Jun 14 16:38:35 2021 -0500 move shared helpers to lttoolbox many files only had `Apertium` as a namespace because they included `string_utils.h`, but thats in lttoolbox now, so those `using` lines needed to be removed. diff --git a/apertium/Makefile.am b/apertium/Makefile.am index e3cecc2..ef15388 100644 --- a/apertium/Makefile.am +++ b/apertium/Makefile.am @@ -38,7 +38,6 @@ h_sources = a.h \ stream_tagger.h \ streamed_type.h \ string_to_wostream.h \ - string_utils.h \ shell_utils.h \ tag.h \ tagger.h \ @@ -76,8 +75,7 @@ h_sources = a.h \ unigram_tagger.h \ unlocked_cstdio.h \ utils.h \ - xml_reader.h \ - xml_walk_util.h + xml_reader.h cc_sources = a.cc \ align.cc \ @@ -109,7 +107,6 @@ cc_sources = a.cc \ sentence_stream.cc \ stream.cc \ stream_tagger.cc \ - string_utils.cc \ shell_utils.cc \ tag.cc \ tagger.cc \ @@ -139,8 +136,7 @@ cc_sources = a.cc \ trx_reader.cc \ tsx_reader.cc \ unigram_tagger.cc \ - xml_reader.cc \ - xml_walk_util.cc + xml_reader.cc library_includedir = $(includedir)/$(PACKAGE_NAME)-$(VERSION_API)/$(PACKAGE_NAME) library_include_HEADERS = $(h_sources) diff --git a/apertium/align.cc b/apertium/align.cc index 4d7bdb4..68f0bd3 100644 --- a/apertium/align.cc +++ b/apertium/align.cc @@ -15,7 +15,7 @@ #include "align.h" #include "linebreak.h" -#include +#include #include #include diff --git a/apertium/apertium-prelatex.l b/apertium/apertium-prelatex.l index 075581f..4053168 100644 --- a/apertium/apertium-prelatex.l +++ b/apertium/apertium-prelatex.l @@ -10,7 +10,8 @@ #include #include #include -#include +#include +#include extern "C" { #if !defined(__STDC__) diff --git a/apertium/apertium_filter_ambiguity.cc b/apertium/apertium_filter_ambiguity.cc index a456a59..c9c61c3 100644 --- a/apertium/apertium_filter_ambiguity.cc +++ b/apertium/apertium_filter_ambiguity.cc @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include diff --git a/apertium/apertium_interchunk.cc b/apertium/apertium_interchunk.cc index e2dcb9f..b6b6c8b 100644 --- a/apertium/apertium_interchunk.cc +++ b/apertium/apertium_interchunk.cc @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "getopt_long.h" #ifdef _MSC_VER @@ -31,7 +31,6 @@ #include #endif -using namespace Apertium; using namespace std; void message(char *progname) diff --git a/apertium/apertium_postchunk.cc b/apertium/apertium_postchunk.cc index 26204c3..8c3cfe8 100644 --- a/apertium/apertium_postchunk.cc +++ b/apertium/apertium_postchunk.cc @@ -24,13 +24,12 @@ #include #include #include -#include +#include #ifdef _MSC_VER #include #include #endif -using namespace Apertium; using namespace std; void message(char *progname) diff --git a/apertium/apertium_posttransfer.cc b/apertium/apertium_posttransfer.cc index 8b95db8..45e2ad8 100644 --- a/apertium/apertium_posttransfer.cc +++ b/apertium/apertium_posttransfer.cc @@ -25,12 +25,11 @@ #include #include #endif -#include +#include #include #include -using namespace Apertium; using namespace std; void usage(char *progname) diff --git a/apertium/apertium_pretransfer.cc b/apertium/apertium_pretransfer.cc index 25bccc0..f5c07f0 100644 --- a/apertium/apertium_pretransfer.cc +++ b/apertium/apertium_pretransfer.cc @@ -26,10 +26,9 @@ #include #endif #include -#include +#include #include -using namespace Apertium; using namespace std; void usage(char *progname) diff --git a/apertium/apertium_re.cc b/apertium/apertium_re.cc index 6721b01..d64b94f 100644 --- a/apertium/apertium_re.cc +++ b/apertium/apertium_re.cc @@ -18,9 +18,8 @@ #include #include #include -#include +#include -using namespace Apertium; using namespace std; using namespace icu; diff --git a/apertium/apertium_tagger_apply_new_rules.cc b/apertium/apertium_tagger_apply_new_rules.cc index 375c769..93974ac 100644 --- a/apertium/apertium_tagger_apply_new_rules.cc +++ b/apertium/apertium_tagger_apply_new_rules.cc @@ -26,7 +26,7 @@ #include #include #include -#include +#include using namespace Apertium; diff --git a/apertium/apertium_tagger_readwords.cc b/apertium/apertium_tagger_readwords.cc index 01469a0..2e783cc 100644 --- a/apertium/apertium_tagger_readwords.cc +++ b/apertium/apertium_tagger_readwords.cc @@ -24,7 +24,7 @@ #include #include -#include +#include using namespace std; diff --git a/apertium/apertium_tmxbuild.cc b/apertium/apertium_tmxbuild.cc index 55f81b3..a1c475f 100644 --- a/apertium/apertium_tmxbuild.cc +++ b/apertium/apertium_tmxbuild.cc @@ -24,11 +24,10 @@ #include #include -#include +#include #include "apertium_config.h" #include -using namespace Apertium; using namespace std; void usage(char *progname) diff --git a/apertium/apertium_transfer.cc b/apertium/apertium_transfer.cc index e139a37..c3f6d81 100644 --- a/apertium/apertium_transfer.cc +++ b/apertium/apertium_transfer.cc @@ -23,14 +23,13 @@ #include #include #include -#include +#include #include "getopt_long.h" #ifdef _MSC_VER #include #include #endif -using namespace Apertium; using namespace std; void message(char *progname) diff --git a/apertium/collection.cc b/apertium/collection.cc index 995c14a..ab80607 100644 --- a/apertium/collection.cc +++ b/apertium/collection.cc @@ -16,7 +16,7 @@ */ #include #include -#include +#include #include #include diff --git a/apertium/constant_manager.cc b/apertium/constant_manager.cc index 4bcca54..5302171 100644 --- a/apertium/constant_manager.cc +++ b/apertium/constant_manager.cc @@ -16,7 +16,7 @@ */ #include #include -#include +#include #include #include diff --git a/apertium/file_morpho_stream.cc b/apertium/file_morpho_stream.cc index fa09a3c..fc1be66 100644 --- a/apertium/file_morpho_stream.cc +++ b/apertium/file_morpho_stream.cc @@ -21,11 +21,10 @@ */ #include -#include +#include #include "apertium_config.h" #include -using namespace Apertium; FileMorphoStream::FileMorphoStream(const char* ftxt, bool d, TaggerData *t) : ms() { foundEOF = false; diff --git a/apertium/gen_modes.cc b/apertium/gen_modes.cc index 0a4f07f..6dbb78c 100644 --- a/apertium/gen_modes.cc +++ b/apertium/gen_modes.cc @@ -21,7 +21,7 @@ #include #include #include -#include "string_utils.h" +#include #include #include #include @@ -31,7 +31,6 @@ #include #include -using namespace Apertium; using namespace std; void endProgram(char *name) diff --git a/apertium/hmm.cc b/apertium/hmm.cc index 8c5f3c5..3dd9414 100644 --- a/apertium/hmm.cc +++ b/apertium/hmm.cc @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include inline bool p_isnan(double v) { diff --git a/apertium/interchunk.cc b/apertium/interchunk.cc index 4fa927c..2549e33 100644 --- a/apertium/interchunk.cc +++ b/apertium/interchunk.cc @@ -16,12 +16,11 @@ */ #include -#include -#include +#include +#include #include -using namespace Apertium; using namespace std; Interchunk::Interchunk() diff --git a/apertium/interchunk_word.cc b/apertium/interchunk_word.cc index e9dd9dc..14a27b3 100644 --- a/apertium/interchunk_word.cc +++ b/apertium/interchunk_word.cc @@ -17,9 +17,7 @@ #include #include -#include - -using namespace Apertium; +#include void InterchunkWord::copy(InterchunkWord const &o) @@ -86,7 +84,7 @@ InterchunkWord::init(UString const &chunk) } } } - + if(b_end > 0) { this->wblank = chunk.substr(0, b_end); diff --git a/apertium/lswpost.cc b/apertium/lswpost.cc index eb10e91..d93c9bd 100644 --- a/apertium/lswpost.cc +++ b/apertium/lswpost.cc @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include using namespace std; diff --git a/apertium/mtx_reader.cc b/apertium/mtx_reader.cc index e8b9cd0..efb743a 100644 --- a/apertium/mtx_reader.cc +++ b/apertium/mtx_reader.cc @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/apertium/perceptron_spec.cc b/apertium/perceptron_spec.cc index 80304bb..c785899 100644 --- a/apertium/perceptron_spec.cc +++ b/apertium/perceptron_spec.cc @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include diff --git a/apertium/postchunk.cc b/apertium/postchunk.cc index 6d2dd9f..922633f 100644 --- a/apertium/postchunk.cc +++ b/apertium/postchunk.cc @@ -16,12 +16,11 @@ */ #include -#include -#include +#include +#include #include -using namespace Apertium; using namespace std; Postchunk::Postchunk() @@ -882,7 +881,7 @@ Postchunk::unchunk(UString const &chunk, UFILE* output) { int j = ++i; while (chunk[++i] != '>'); - unsigned long value = stoi(chunk.substr(j, i-j)) - 1; + unsigned long value = StringUtils::stoi(chunk.substr(j, i-j)) - 1; if(vectags.size() > value) { write(vectags[value], output); @@ -988,7 +987,7 @@ Postchunk::splitWordsAndBlanks(UString const &chunk, vector &words, if(iswdigit(chunk[i+1])) { // replace tag - unsigned long value = stoi(chunk.c_str()+i+1) - 1; + unsigned long value = StringUtils::stoi(chunk.c_str()+i+1) - 1; // TODO //unsigned long value = wcstoul(chunk.c_str()+i+1, // NULL, 0) - 1; @@ -1079,7 +1078,7 @@ Postchunk::splitWordsAndBlanks(UString const &chunk, vector &words, if(iswdigit(chunk[i+1])) { // replace tag - unsigned long value = stoi(chunk.c_str()+i+1) - 1; + unsigned long value = StringUtils::stoi(chunk.c_str()+i+1) - 1; //unsigned long value = wcstoul(chunk.c_str()+i+1, // NULL, 0) - 1; // TODO: make sure this is equivalent diff --git a/apertium/pretransfer.cc b/apertium/pretransfer.cc index 8f7778b..7322980 100644 --- a/apertium/pretransfer.cc +++ b/apertium/pretransfer.cc @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include diff --git a/apertium/string_utils.cc b/apertium/string_utils.cc deleted file mode 100644 index 2df808d..0000000 --- a/apertium/string_utils.cc +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (C) 2006 Universitat d'Alacant / Universidad de Alicante - * author: Felipe Sánchez-Martínez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -#define snprintf _snprintf -#endif - -//Delete white spaces from the end and the begining of the string -UString -StringUtils::trim(UString const &str) -{ - if(str.empty()) - { - return ""_u; - } - - int begin = 0, end = str.size() - 1; - - while(begin < end && iswspace(str[begin])) - { - begin++; - } - - while(end > begin && iswspace(str[end])) - { - end--; - } - - if(!iswspace(str[end])) - { - end++; - } - - return str.substr(begin, end-begin); -} - -vector -StringUtils::split_UString(UString const &input, UString const &delimiter) -{ - unsigned pos; - int new_pos; - vector result; - UString s; - pos=0; - - while(pos const &v) -{ - UString s; - for(unsigned i=0; i0) - s+=' '; - s.append(v[i]); - } - return s; -} - -UString -StringUtils::substitute(UString const &source, UString const &olds, UString const &news) { - UString s = source; - - unsigned int p=s.find(olds , 0); - while (p!=static_cast(UString::npos)) - { - s.replace(p, olds.length(), news); - p+=news.length(); - p=s.find(olds,p); - } - - return s; -} - -UString -StringUtils::itoa(int n) -{ - UChar str[256]; - u_snprintf(str, 256, "%d", n); - return str; -} - -string -StringUtils::itoa_string(int n) -{ - char str[256]; - snprintf(str, 256, "%d", n); - return str; -} - -UString -StringUtils::ftoa(double f) -{ - UChar str[256]; - u_snprintf(str, 256, "%f", f); - return str; -} - -UString -StringUtils::tolower(UString const &s) -{ - UString l; - l.reserve(s.size()); - size_t i = 0; - UChar32 c; - while (i < s.length()) { - U16_NEXT(s.c_str(), i, s.size(), c); - l += u_tolower(c); - } - return l; -} - -UString -StringUtils::toupper(UString const &s) -{ - UString l; - l.reserve(s.size()); - size_t i = 0; - UChar32 c; - while (i < s.length()) { - U16_NEXT(s.c_str(), i, s.size(), c); - l += u_toupper(c); - } - return l; -} - -UString -StringUtils::getcase(const UString& str) -{ - UString ret = "aa"_u; - if (str.empty()) { - return ret; - } - size_t i = 0; - size_t l = str.size(); - UChar32 c; - U16_NEXT(str.c_str(), i, l, c); - if (u_isupper(c)) { - ret[0] = 'A'; - if (i < l) { - U16_BACK_1(str.c_str(), i, l); // decrements l - U16_GET(str.c_str(), 0, l, str.size(), c); - if (u_isupper(c)) { - ret[1] = 'A'; - } - } - } - return ret; -} - -UString -StringUtils::copycase(const UString& source, const UString& target) -{ - if (source.empty() || target.empty()) { - return target; - } - UString ret; - ret.reserve(target.size()); - size_t i = 0; - size_t l = source.size(); - UChar32 c; - U16_NEXT(source.c_str(), i, l, c); - bool firstupper = u_isupper(c); - bool uppercase = false; - if (firstupper) { - if (i != l) { - U16_BACK_1(source.c_str(), i, l); // decrements l - U16_GET(source.c_str(), 0, l, source.size(), c); - uppercase = u_isupper(c); - } - } - i = 0; - l = target.size(); - if (firstupper) { - U16_NEXT(target.c_str(), i, l, c); - ret += u_toupper(c); - } - if (uppercase) { - while (i < l) { - U16_NEXT(target.c_str(), i, l, c); - ret += u_toupper(c); - } - } else { - while (i < l) { - U16_NEXT(target.c_str(), i, l, c); - ret += u_tolower(c); - } - } - return ret; -} - -bool Apertium::operator==(string const &s1, string const &s2) -{ - return strcmp(s1.c_str(), s2.c_str()) == 0; -} - -bool Apertium::operator==(string const &s1, char const *s2) -{ - return strcmp(s1.c_str(), s2) == 0; -} - -bool Apertium::operator==(char const *s1, string const &s2) -{ - return strcmp(s1, s2.c_str()) == 0; -} - -bool Apertium::operator!=(string const &s1, string const &s2) -{ - return strcmp(s1.c_str(), s2.c_str()) != 0; -} - -bool Apertium::operator!=(string const &s1, char const *s2) -{ - return strcmp(s1.c_str(), s2) != 0; -} - -bool Apertium::operator!=(char const *s1, string const &s2) -{ - return strcmp(s1, s2.c_str()) != 0; -} - -u16iter::u16iter(const UString& s) - : buf(s.c_str()), len(s.size()), i(0), c('\0') -{ - if (!s.empty()) { - U16_GET(buf, 0, 0, len, c); - } -} - -u16iter::u16iter(const u16iter& it) - : buf(it.buf), len(it.len), i(it.i), c(it.c) -{} - -u16iter& -u16iter::operator++() -{ - if (i < len) { - U16_FWD_1(buf, i, len); - if (i < len) { - U16_GET(buf, 0, i, len, c); - } else { - c = '\0'; - } - } - return *this; -} - -u16iter -u16iter::begin() -{ - u16iter ret(""_u); - ret.buf = buf; - ret.len = len; - ret.i = 0; - U16_GET(buf, 0, 0, len, ret.c); - return ret; -} - -u16iter -u16iter::end() -{ - u16iter ret(""_u); - ret.buf = buf; - ret.len = len; - ret.i = len; - ret.c = '\0'; - return ret; -} - -bool -u16iter::operator!=(const u16iter& other) const { - return other.buf != buf || other.i != i; -} - -bool -u16iter::operator==(const u16iter& other) const { - return other.buf == buf && other.i == i; -} - -#include "string_to_wostream.h" diff --git a/apertium/string_utils.h b/apertium/string_utils.h deleted file mode 100644 index 72cde52..0000000 --- a/apertium/string_utils.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2006 Universitat d'Alacant / Universidad de Alicante - * author: Felipe Sánchez-Martínez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ -#ifndef __STRINGUTILS_H_ -#define __STRINGUTILS_H_ - -#include -#include -#include -#include - -using namespace std; - -namespace Apertium -{ - bool operator==(string const &s1, string const &s2); - bool operator==(string const &s1, char const *s2); - bool operator==(char const *s1, string const &s2); - bool operator!=(string const &s1, string const &s2); - bool operator!=(string const &s1, char const *s2); - bool operator!=(char const *s1, string const &s2); -} - -class StringUtils { - public: - - static UString trim(UString const &str); - - static vector split_UString(UString const &input, UString const &delimiter); - - static UString vector2UString(vector const &v); - - //Replace each ocurrence of the string 'olds' by the string 'news' in string 'source' - static UString substitute(const UString &source, const UString &olds, const UString &news); - - static UString itoa(int n); - - static string itoa_string(int n); - - static UString ftoa(double f); - - static UString tolower(UString const &s); - - static UString toupper(UString const &s); - - static UString getcase(const UString& s); - - static UString copycase(const UString& source, const UString& target); -}; - -class u16iter -{ -private: - const UChar* buf; - size_t len; - size_t i; - UChar32 c; -public: - u16iter(const UString& s); - u16iter(const u16iter& it); - - u16iter& operator++(); - u16iter begin(); - u16iter end(); - inline UChar32 operator*() const { return c; } - bool operator!=(const u16iter& other) const; - bool operator==(const u16iter& other) const; -}; - -std::wostream & operator<< (std::wostream & ostr, std::string const & str); - -#endif diff --git a/apertium/tagger_data.cc b/apertium/tagger_data.cc index a333e13..0eb93ec 100644 --- a/apertium/tagger_data.cc +++ b/apertium/tagger_data.cc @@ -17,9 +17,7 @@ #include #include #include -#include - -using namespace Apertium; +#include void TaggerData::copy(TaggerData const &o) diff --git a/apertium/tagger_data_hmm.cc b/apertium/tagger_data_hmm.cc index f81d88f..759ac73 100644 --- a/apertium/tagger_data_hmm.cc +++ b/apertium/tagger_data_hmm.cc @@ -18,7 +18,7 @@ #include #include #include -#include +#include using namespace Apertium; diff --git a/apertium/tagger_data_lsw.cc b/apertium/tagger_data_lsw.cc index ccd068a..d8a521f 100644 --- a/apertium/tagger_data_lsw.cc +++ b/apertium/tagger_data_lsw.cc @@ -18,7 +18,7 @@ #include #include #include -#include +#include using namespace Apertium; diff --git a/apertium/tagger_utils.cc b/apertium/tagger_utils.cc index 0e8738d..3da0415 100644 --- a/apertium/tagger_utils.cc +++ b/apertium/tagger_utils.cc @@ -22,9 +22,7 @@ #include #include #include -#include - -using namespace Apertium; +#include void tagger_utils::fatal_error (UString const &s) { @@ -55,7 +53,7 @@ void tagger_utils::clear_array_vector(vector v[], int l) { int tagger_utils::ntokens_multiword(UString const &s) { - vector tmp = StringUtils::split_UString(s, "_"_u); + vector tmp = StringUtils::split(s, "_"_u); int n = 0; for (auto& it : tmp) { if (!it.empty()) { @@ -66,7 +64,7 @@ int tagger_utils::ntokens_multiword(UString const &s) } int tagger_utils::nguiones_fs(UString const & s) { - vector tmp = StringUtils::split_UString(s, "-"_u); + vector tmp = StringUtils::split(s, "-"_u); int n = 0; for (auto& it : tmp) { if (!it.empty()) { diff --git a/apertium/tagger_word.cc b/apertium/tagger_word.cc index 83f15a6..ff44de4 100644 --- a/apertium/tagger_word.cc +++ b/apertium/tagger_word.cc @@ -15,12 +15,10 @@ * along with this program; if not, see . */ #include -#include +#include #include "apertium_config.h" #include -using namespace Apertium; - bool TaggerWord::generate_marks=false; vector TaggerWord::array_tags; diff --git a/apertium/tmx_aligner_tool.cc b/apertium/tmx_aligner_tool.cc index 90b353a..9dc7e7b 100644 --- a/apertium/tmx_aligner_tool.cc +++ b/apertium/tmx_aligner_tool.cc @@ -10,7 +10,7 @@ * * *************************************************************************/ #include -#include +#include namespace TMXAligner { diff --git a/apertium/tmx_alignment.cc b/apertium/tmx_alignment.cc index 4b891b7..97ae617 100644 --- a/apertium/tmx_alignment.cc +++ b/apertium/tmx_alignment.cc @@ -13,7 +13,7 @@ #include // For SentenceList #include // For FrequencyMap -#include +#include #include #include diff --git a/apertium/tmx_arguments_parser.cc b/apertium/tmx_arguments_parser.cc index 97fe31c..acd00ec 100644 --- a/apertium/tmx_arguments_parser.cc +++ b/apertium/tmx_arguments_parser.cc @@ -10,7 +10,7 @@ * * *************************************************************************/ #include -#include +#include #include #include diff --git a/apertium/tmx_builder.cc b/apertium/tmx_builder.cc index b535b3b..54e0ed8 100644 --- a/apertium/tmx_builder.cc +++ b/apertium/tmx_builder.cc @@ -15,7 +15,7 @@ * along with this program; if not, see . */ #include -#include +#include #include #include @@ -35,7 +35,6 @@ #include #endif -using namespace Apertium; using namespace std; TMXBuilder::TMXBuilder(UString const &l1, UString const &l2): diff --git a/apertium/tmx_translate.cc b/apertium/tmx_translate.cc index 9761553..dd37da5 100644 --- a/apertium/tmx_translate.cc +++ b/apertium/tmx_translate.cc @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/apertium/transfer.cc b/apertium/transfer.cc index 3b71c84..64aad0d 100644 --- a/apertium/transfer.cc +++ b/apertium/transfer.cc @@ -16,12 +16,11 @@ */ #include -#include -#include +#include +#include #include -using namespace Apertium; using namespace std; Transfer::Transfer() diff --git a/apertium/transfer_base.cc b/apertium/transfer_base.cc index 4c8027b..9feb672 100644 --- a/apertium/transfer_base.cc +++ b/apertium/transfer_base.cc @@ -1,10 +1,9 @@ #include -#include -#include +#include +#include #include #include -using namespace Apertium; using namespace std; TransferBase::TransferBase() @@ -50,7 +49,7 @@ TransferBase::read(const char* transferfile, const char* datafile) cerr << "Error: Could not open file '" << datafile << "' for reading." << endl; exit(EXIT_FAILURE); } - + alphabet.read(in); any_char = alphabet(TRXReader::ANY_CHAR); any_tag = alphabet(TRXReader::ANY_TAG); @@ -580,14 +579,7 @@ TransferBase::tags(const UString& str) const UString ret; ret.reserve(str.size()+2); ret += '<'; - for (auto c : u16iter(str)) { - if (c == '.') { - ret += '>'; - ret += '<'; - } else { - ret += c; - } - } + ret.append(StringUtils::substitute(str, "."_u, "><"_u)); ret += '>'; return ret; } @@ -609,4 +601,3 @@ TransferBase::setTrace(bool val) { trace = val; } - diff --git a/apertium/transfer_data.cc b/apertium/transfer_data.cc index d5e2b6c..6e818a3 100644 --- a/apertium/transfer_data.cc +++ b/apertium/transfer_data.cc @@ -19,9 +19,8 @@ #include #include #include -#include +#include -using namespace Apertium; using namespace std; void @@ -158,7 +157,7 @@ TransferData::write(FILE *output) if(s.compare(0, rule_sym_pre.size(), rule_sym_pre) != 0) { continue; } - const int rule_num = stoi(s.substr(rule_sym_pre.size())); + const int rule_num = StringUtils::stoi(s.substr(rule_sym_pre.size())); transducer.setFinal(src, wgt); finals_rules[src] = rule_num; } diff --git a/apertium/transfer_instr.cc b/apertium/transfer_instr.cc index 40d557b..46f719d 100644 --- a/apertium/transfer_instr.cc +++ b/apertium/transfer_instr.cc @@ -15,9 +15,8 @@ * along with this program; if not, see . */ #include -#include +#include -using namespace Apertium; void TransferInstr::copy(TransferInstr const &o) { diff --git a/apertium/transfer_mult.cc b/apertium/transfer_mult.cc index 3f00496..35a69fa 100644 --- a/apertium/transfer_mult.cc +++ b/apertium/transfer_mult.cc @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/apertium/transfer_token.cc b/apertium/transfer_token.cc index b3c0be1..a679f07 100644 --- a/apertium/transfer_token.cc +++ b/apertium/transfer_token.cc @@ -15,9 +15,7 @@ * along with this program; if not, see . */ #include -#include - -using namespace Apertium; +#include void TransferToken::copy(TransferToken const &o) @@ -87,4 +85,3 @@ TransferToken::setContent(UString const &content) { this->content = content; } - diff --git a/apertium/transfer_word.cc b/apertium/transfer_word.cc index fe87da7..a3ce8c7 100644 --- a/apertium/transfer_word.cc +++ b/apertium/transfer_word.cc @@ -17,9 +17,8 @@ #include #include -#include +#include -using namespace Apertium; void TransferWord::copy(TransferWord const &o) { diff --git a/apertium/transferpp.cc b/apertium/transferpp.cc index a947959..278da6b 100644 --- a/apertium/transferpp.cc +++ b/apertium/transferpp.cc @@ -18,10 +18,9 @@ #include #include #include -#include +#include #include -using namespace Apertium; using namespace std; int main(int argc, char *argv[]) diff --git a/apertium/trx_reader.cc b/apertium/trx_reader.cc index 4e1a8c8..24fcc1d 100644 --- a/apertium/trx_reader.cc +++ b/apertium/trx_reader.cc @@ -20,9 +20,7 @@ #include #include -#include - -using namespace Apertium; +#include UString const TRXReader::ANY_TAG = ""_u; UString const TRXReader::ANY_CHAR = ""_u; diff --git a/apertium/tsx_reader.cc b/apertium/tsx_reader.cc index a6c051a..ef20298 100644 --- a/apertium/tsx_reader.cc +++ b/apertium/tsx_reader.cc @@ -17,12 +17,11 @@ #include #include #include -#include +#include #include #include -using namespace Apertium; void TSXReader::copy(TSXReader const &o) { diff --git a/apertium/xml_reader.h b/apertium/xml_reader.h index a1c7028..60d94c7 100644 --- a/apertium/xml_reader.h +++ b/apertium/xml_reader.h @@ -2,7 +2,7 @@ #define _XMLREADER_ #include -#include +#include #include #include #include diff --git a/apertium/xml_walk_util.cc b/apertium/xml_walk_util.cc deleted file mode 100644 index b9e6dde..0000000 --- a/apertium/xml_walk_util.cc +++ /dev/null @@ -1,65 +0,0 @@ -#include - -children::children(xmlNode* node_) - : node(node_), cur(node->children) -{ - while (cur && cur->type != XML_ELEMENT_NODE) { - cur = cur->next; - } -} - -children::children(const children& it) - : node(it.node), cur(it.cur) -{} - -children::~children() -{} // we don't own the pointers, so we don't delete them - -children& -children::operator++() -{ - if (node && cur) { - cur = cur->next; - while (cur && cur->type != XML_ELEMENT_NODE) { - cur = cur->next; - } - } - return *this; -} - -children -children::begin() -{ - return children(node); -} - -children -children::end() -{ - children ret(node); - ret.cur = nullptr; - return ret; -} - -bool -children::operator!=(const children& other) const -{ - return node != other.node || cur != other.cur; -} - -bool -children::operator==(const children& other) const -{ - return node == other.node && cur == other.cur; -} - -UString -getattr(xmlNode* node, const char* attr) -{ - for (xmlAttr* i = node->properties; i != NULL; i = i->next) { - if (!xmlStrcmp(i->name, (const xmlChar*) attr)) { - return to_ustring((const char*) i->children->content); - } - } - return ""_u; -} diff --git a/apertium/xml_walk_util.h b/apertium/xml_walk_util.h deleted file mode 100644 index 13ca6a4..0000000 --- a/apertium/xml_walk_util.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _XML_WALK_UTIL_ -#define _XML_WALK_UTIL_ - -#include - -#include -#include - -class children -{ -private: - xmlNode* node; - xmlNode* cur; -public: - children(xmlNode* node); - children(const children& it); - ~children(); - - children& operator++(); - children begin(); - children end(); - inline xmlNode* operator*() const { return cur; } - bool operator!=(const children& other) const; - bool operator==(const children& other) const; -}; - -UString getattr(xmlNode* node, const char* attr); - -#endif diff --git a/python/setup.py.in b/python/setup.py.in index b5ed70a..7bcd70d 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -21,7 +21,7 @@ def get_sources(): sources = ['apertium_core.i'] cc_sources = [ # interchunk.cc postchunk.cc transfer.cc - 'apertium_re.cc', 'interchunk.cc', 'interchunk_word.cc', 'postchunk.cc', 'string_utils.cc', 'transfer.cc', + 'apertium_re.cc', 'interchunk.cc', 'interchunk_word.cc', 'postchunk.cc', 'transfer.cc', 'transfer_data.cc', 'transfer_instr.cc', 'transfer_mult.cc', 'transfer_token.cc', 'transfer_word.cc', 'trx_reader.cc', 'xml_reader.cc', # 'pretransfer.cc'