diff --git a/plugins/plugins_module.cc b/plugins/plugins_module.cc index 86aaa1b03..af78c2bf8 100644 --- a/plugins/plugins_module.cc +++ b/plugins/plugins_module.cc @@ -3,6 +3,7 @@ // Distributed under the BSD License // +#include #include #include #include @@ -78,7 +79,7 @@ string PluginManager::plugin_name_of(fs::path plugin_file) { } // replace dash with underscore, for the plugin name is part of the module // initializer function name. - boost::replace_all(name, "-", "_"); + std::replace(name.begin(), name.end(), '-', '_'); return name; } diff --git a/src/rime/algo/utilities.cc b/src/rime/algo/utilities.cc index 8000eb1bf..5b032c18a 100644 --- a/src/rime/algo/utilities.cc +++ b/src/rime/algo/utilities.cc @@ -6,35 +6,25 @@ // #include #include -#include #include namespace rime { int CompareVersionString(const string& x, const string& y) { - if (x.empty() && y.empty()) - return 0; - if (x.empty()) - return -1; - if (y.empty()) - return 1; - vector xx, yy; - boost::split(xx, x, boost::is_any_of(".")); - boost::split(yy, y, boost::is_any_of(".")); - size_t i = 0; - for (; i < xx.size() && i < yy.size(); ++i) { - int dx = atoi(xx[i].c_str()); - int dy = atoi(yy[i].c_str()); - if (dx != dy) - return dx - dy; - int c = xx[i].compare(yy[i]); - if (c != 0) - return c; + size_t i = 0, j = 0, m = x.size(), n = y.size(); + while (i < m || j < n) { + int v1 = 0, v2 = 0; + while (i < m && x[i] != '.') + v1 = v1 * 10 + (int)(x[i++] - '0'); + ++i; + while (j < n && y[j] != '.') + v2 = v2 * 10 + (int)(y[j++] - '0'); + ++j; + if (v1 > v2) + return 1; + if (v1 < v2) + return -1; } - if (i < xx.size()) - return 1; - if (i < yy.size()) - return -1; return 0; } diff --git a/src/rime/config/config_data.cc b/src/rime/config/config_data.cc index 995b76e31..7258a460e 100644 --- a/src/rime/config/config_data.cc +++ b/src/rime/config/config_data.cc @@ -5,9 +5,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -96,7 +96,9 @@ bool ConfigData::IsListItemReference(const string& key) { } string ConfigData::FormatListIndex(size_t index) { - return boost::str(boost::format("@%u") % index); + std::ostringstream formatted; + formatted << "@" << index; + return formatted.str(); } static const string kAfter("after"); @@ -286,9 +288,9 @@ an ConvertFromYaml(const YAML::Node& node, void EmitScalar(const string& str_value, YAML::Emitter* emitter) { if (str_value.find_first_of("\r\n") != string::npos) { *emitter << YAML::Literal; - } else if (!boost::algorithm::all(str_value, - boost::algorithm::is_alnum() || - boost::algorithm::is_any_of("_."))) { + } else if (!std::all_of(str_value.cbegin(), str_value.cend(), [](auto ch) { + return std::isalnum(ch) || ch == '_' || ch == '.'; + })) { *emitter << YAML::DoubleQuoted; } *emitter << str_value; diff --git a/src/rime/dict/mapped_file.h b/src/rime/dict/mapped_file.h index 03352f031..9257968c9 100644 --- a/src/rime/dict/mapped_file.h +++ b/src/rime/dict/mapped_file.h @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -81,7 +80,7 @@ struct List { class MappedFileImpl; -class RIME_API MappedFile : boost::noncopyable { +class RIME_API MappedFile { protected: explicit MappedFile(const string& file_name); virtual ~MappedFile(); @@ -106,6 +105,10 @@ class RIME_API MappedFile : boost::noncopyable { char* address() const; public: + // noncpyable + MappedFile(const MappedFile&) = delete; + MappedFile& operator=(const MappedFile&) = delete; + bool Exists() const; bool IsOpen() const; void Close(); diff --git a/src/rime/dict/string_table.cc b/src/rime/dict/string_table.cc index c3b68efed..d439a464d 100644 --- a/src/rime/dict/string_table.cc +++ b/src/rime/dict/string_table.cc @@ -5,15 +5,16 @@ // 2014-07-04 GONG Chen // -#include -#include +#include #include #include namespace rime { StringTable::StringTable(const char* ptr, size_t size) { - trie_.map(ptr, size); + std::stringstream stream; + stream.write(ptr, size); + stream >> trie_; } bool StringTable::HasKey(const string& key) { @@ -106,10 +107,10 @@ void StringTableBuilder::Dump(char* ptr, size_t size) { LOG(ERROR) << "insufficient memory to dump string table."; return; } - namespace io = boost::iostreams; - io::basic_array_sink sink(ptr, size); - io::stream> stream(sink); + + std::stringstream stream; stream << trie_; + stream.read(ptr, size); } } // namespace rime diff --git a/src/rime/dict/user_db.cc b/src/rime/dict/user_db.cc index 5fe789588..e35019eea 100644 --- a/src/rime/dict/user_db.cc +++ b/src/rime/dict/user_db.cc @@ -5,8 +5,8 @@ // 2011-11-02 GONG Chen // #include +#include #include -#include #include #include #include @@ -33,10 +33,12 @@ void UserDbValue::AppendElements(const DictEntry& entry) { } string UserDbValue::Pack() const { - return boost::str(elements.size() <= 1 - ? boost::format("c=%1% d=%2% t=%3%") % commits % dee % tick - : boost::format("c=%1% d=%2% t=%3% e=%4%") % - commits % dee % tick % boost::join(elements, "/")); + std::ostringstream packed; + packed << "c=" << commits << " d=" << dee << " t=" << tick; + if (elements.size() > 1) { + packed << " e=" << boost::join(elements, "/"); + } + return packed.str(); } bool UserDbValue::Unpack(const string& value) { diff --git a/src/rime/gear/shape.cc b/src/rime/gear/shape.cc index 37a078896..b6a16774e 100644 --- a/src/rime/gear/shape.cc +++ b/src/rime/gear/shape.cc @@ -5,7 +5,7 @@ // 2013-07-02 GONG Chen // #include -#include +#include #include #include #include @@ -17,7 +17,8 @@ void ShapeFormatter::Format(string* text) { if (!engine_->context()->get_option("full_shape")) { return; } - if (boost::all(*text, !boost::is_from_range('\x20', '\x7e'))) { + if (std::all_of(text->cbegin(), text->cend(), + [](auto ch) { return (ch >= 0x20 && ch <= 0x7e); })) { return; } std::ostringstream oss; diff --git a/src/rime/key_event.cc b/src/rime/key_event.cc index ae1ecea70..bdfd9a114 100644 --- a/src/rime/key_event.cc +++ b/src/rime/key_event.cc @@ -5,7 +5,7 @@ // 2011-04-20 GONG Chen // #include -#include +#include #include #include @@ -36,15 +36,16 @@ string KeyEvent::repr() const { return modifiers.str() + name; } // no name :-| return its hex value - string value; + std::ostringstream value; + value << "0x" << std::setfill('0'); if (keycode_ <= 0xffff) { - value = boost::str(boost::format("0x%4x") % keycode_); + value << std::setw(4) << std::hex << keycode_; } else if (keycode_ <= 0xffffff) { - value = boost::str(boost::format("0x%6x") % keycode_); + value << std::setw(6) << std::hex << keycode_; } else { return "(unknown)"; // invalid keycode } - return modifiers.str() + value; + return modifiers.str() + value.str(); } bool KeyEvent::Parse(const string& repr) { diff --git a/src/rime_api.cc b/src/rime_api.cc index 23506f1d9..a7a8b260a 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -6,7 +6,6 @@ // #include #include -#include #include #include #include @@ -752,7 +751,9 @@ RIME_API Bool RimeConfigNext(RimeConfigIterator* iterator) { ++p->iter; if (p->iter == p->end) return False; - p->key = boost::str(boost::format("@%1%") % iterator->index); + std::ostringstream key; + key << "@" << iterator->index; + p->key = key.str(); p->path = p->prefix + p->key; iterator->key = p->key.c_str(); iterator->path = p->path.c_str(); diff --git a/test/config_compiler_test.cc b/test/config_compiler_test.cc index 0c83c1fd7..330edd040 100644 --- a/test/config_compiler_test.cc +++ b/test/config_compiler_test.cc @@ -3,7 +3,7 @@ // Distributed under the BSD License // -#include +#include #include #include #include @@ -34,7 +34,9 @@ class RimeConfigCompilerTest : public RimeConfigCompilerTestBase { TEST_F(RimeConfigCompilerTest, IncludeLocalReference) { for (size_t i = 0; i < 4; ++i) { - auto prefix = boost::str(boost::format("include_local_reference/@%u/") % i); + std::ostringstream oss; + oss << "include_local_reference/@" << i << "/"; + const auto& prefix(oss.str()); EXPECT_TRUE(config_->IsNull(prefix + "__include")); string actual; EXPECT_TRUE(config_->GetString(prefix + "terrans/player", &actual));