diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/dicttoolkit/NativeFileList.mk | 1 | ||||
-rw-r--r-- | native/dicttoolkit/src/utils/arguments_parser.cpp | 16 | ||||
-rw-r--r-- | native/dicttoolkit/src/utils/arguments_parser.h | 4 | ||||
-rw-r--r-- | native/dicttoolkit/tests/utils/arguments_parser_test.cpp | 73 | ||||
-rw-r--r-- | native/jni/Android.mk | 3 | ||||
-rw-r--r-- | native/jni/src/utils/char_utils.cpp | 7 |
6 files changed, 97 insertions, 7 deletions
diff --git a/native/dicttoolkit/NativeFileList.mk b/native/dicttoolkit/NativeFileList.mk index d2c8c3a2c..9a547b054 100644 --- a/native/dicttoolkit/NativeFileList.mk +++ b/native/dicttoolkit/NativeFileList.mk @@ -39,5 +39,6 @@ LATIN_IME_DICT_TOOLKIT_TEST_FILES := \ $(addprefix offdevice_intermediate_dict/, \ offdevice_intermediate_dict_test.cpp) \ $(addprefix utils/, \ + arguments_parser_test.cpp \ command_utils_test.cpp \ utf8_utils_test.cpp) diff --git a/native/dicttoolkit/src/utils/arguments_parser.cpp b/native/dicttoolkit/src/utils/arguments_parser.cpp index 039dae35b..52cc7b21d 100644 --- a/native/dicttoolkit/src/utils/arguments_parser.cpp +++ b/native/dicttoolkit/src/utils/arguments_parser.cpp @@ -16,18 +16,32 @@ #include "utils/arguments_parser.h" +#include <unordered_set> + namespace latinime { namespace dicttoolkit { const int ArgumentSpec::UNLIMITED_COUNT = -1; bool ArgumentsParser::validateSpecs() const { + std::unordered_set<std::string> argumentNameSet; for (size_t i = 0; i < mArgumentSpecs.size() ; ++i) { + if (mArgumentSpecs[i].getMinCount() == 0 && mArgumentSpecs[i].getMaxCount() == 0) { + AKLOGE("minCount = maxCount = 0 for %s.", mArgumentSpecs[i].getName().c_str()); + return false; + } if (mArgumentSpecs[i].getMinCount() != mArgumentSpecs[i].getMaxCount() && i != mArgumentSpecs.size() - 1) { - AKLOGE("Variable length argument must be at the end."); + AKLOGE("Variable length argument must be at the end.", + mArgumentSpecs[i].getName().c_str()v ); + return false; + } + if (argumentNameSet.count(mArgumentSpecs[i].getName()) > 0) { + AKLOGE("Multiple arguments have the same name \"%s\".", + mArgumentSpecs[i].getName().c_str()); return false; } + argumentNameSet.insert(mArgumentSpecs[i].getName()); } return true; } diff --git a/native/dicttoolkit/src/utils/arguments_parser.h b/native/dicttoolkit/src/utils/arguments_parser.h index be2dd8749..510a8722b 100644 --- a/native/dicttoolkit/src/utils/arguments_parser.h +++ b/native/dicttoolkit/src/utils/arguments_parser.h @@ -97,8 +97,8 @@ class ArgumentSpec { class ArgumentsParser { public: - ArgumentsParser(std::unordered_map<std::string, OptionSpec> &&optionSpecs, - std::vector<ArgumentSpec> &&argumentSpecs) + ArgumentsParser(const std::unordered_map<std::string, OptionSpec> &&optionSpecs, + const std::vector<ArgumentSpec> &&argumentSpecs) : mOptionSpecs(std::move(optionSpecs)), mArgumentSpecs(std::move(argumentSpecs)) {} const ArgumentsAndOptions parseArguments(const int argc, char **argv) const; diff --git a/native/dicttoolkit/tests/utils/arguments_parser_test.cpp b/native/dicttoolkit/tests/utils/arguments_parser_test.cpp new file mode 100644 index 000000000..e79425b87 --- /dev/null +++ b/native/dicttoolkit/tests/utils/arguments_parser_test.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "utils/arguments_parser.h" + +#include <gtest/gtest.h> + +namespace latinime { +namespace dicttoolkit { +namespace { + +TEST(ArgumentsParserTests, TestValitadeSpecs) { + { + std::unordered_map<std::string, OptionSpec> optionSpecs; + std::vector<ArgumentSpec> argumentSpecs; + EXPECT_TRUE( + ArgumentsParser(std::move(optionSpecs), std::move(argumentSpecs)).validateSpecs()); + } + { + std::unordered_map<std::string, OptionSpec> optionSpecs; + optionSpecs["a"] = OptionSpec::keyValueOption("valueName", "default", "description"); + const std::vector<ArgumentSpec> argumentSpecs = { + ArgumentSpec::singleArgument("name", "description"), + ArgumentSpec::variableLengthArguments("name2", 0 /* minCount */, 1 /* maxCount */, + "description2") + }; + EXPECT_TRUE( + ArgumentsParser(std::move(optionSpecs), std::move(argumentSpecs)).validateSpecs()); + } + { + const std::vector<ArgumentSpec> argumentSpecs = { + ArgumentSpec::variableLengthArguments("name", 0 /* minCount */, 0 /* maxCount */, + "description") + }; + EXPECT_FALSE(ArgumentsParser(std::unordered_map<std::string, OptionSpec>(), + std::move(argumentSpecs)).validateSpecs()); + } + { + const std::vector<ArgumentSpec> argumentSpecs = { + ArgumentSpec::singleArgument("name", "description"), + ArgumentSpec::variableLengthArguments("name", 0 /* minCount */, 1 /* maxCount */, + "description") + }; + EXPECT_FALSE(ArgumentsParser(std::unordered_map<std::string, OptionSpec>(), + std::move(argumentSpecs)).validateSpecs()); + } + { + const std::vector<ArgumentSpec> argumentSpecs = { + ArgumentSpec::variableLengthArguments("name", 0 /* minCount */, 1 /* maxCount */, + "description"), + ArgumentSpec::singleArgument("name2", "description2") + }; + EXPECT_FALSE(ArgumentsParser(std::unordered_map<std::string, OptionSpec>(), + std::move(argumentSpecs)).validateSpecs()); + } +} + +} // namespace +} // namespace dicttoolkit +} // namespace latinime diff --git a/native/jni/Android.mk b/native/jni/Android.mk index 402cb3b67..6003a6f64 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -92,9 +92,6 @@ LOCAL_SDK_VERSION := 14 LOCAL_NDK_STL_VARIANT := c++_static LOCAL_LDFLAGS += -ldl -# TODO: Figure out what we should do with --hash-style=gnu for unbundled builds -LOCAL_LDFLAGS += -Wl,--hash-style=sysv - include $(BUILD_SHARED_LIBRARY) #################### Clean up the tmp vars include $(LOCAL_PATH)/CleanupNativeFileList.mk diff --git a/native/jni/src/utils/char_utils.cpp b/native/jni/src/utils/char_utils.cpp index 3bb9055b2..a43e6dd62 100644 --- a/native/jni/src/utils/char_utils.cpp +++ b/native/jni/src/utils/char_utils.cpp @@ -1117,7 +1117,9 @@ static int compare_pair_capital(const void *a, const void *b) { // TODO: Check if it's really acceptable to consider ΓΈ a diacritical variant of o /* U+0100 */ 0x0041, 0x0061, 0x0041, 0x0061, 0x0041, 0x0061, 0x0043, 0x0063, /* U+0108 */ 0x0043, 0x0063, 0x0043, 0x0063, 0x0043, 0x0063, 0x0044, 0x0064, - /* U+0110 */ 0x0110, 0x0111, 0x0045, 0x0065, 0x0045, 0x0065, 0x0045, 0x0065, + /* U+0110 */ 0x0046, 0x0064, 0x0045, 0x0065, 0x0045, 0x0065, 0x0045, 0x0065, + // U+0110: Manually changed from 0110 to 0046 + // U+0111: Manually changed from 0111 to 0064 /* U+0118 */ 0x0045, 0x0065, 0x0045, 0x0065, 0x0047, 0x0067, 0x0047, 0x0067, /* U+0120 */ 0x0047, 0x0067, 0x0047, 0x0067, 0x0048, 0x0068, 0x0126, 0x0127, /* U+0128 */ 0x0049, 0x0069, 0x0049, 0x0069, 0x0049, 0x0069, 0x0049, 0x0069, @@ -1135,6 +1137,9 @@ static int compare_pair_capital(const void *a, const void *b) { /* U+0170 */ 0x0055, 0x0075, 0x0055, 0x0075, 0x0057, 0x0077, 0x0059, 0x0079, /* U+0178 */ 0x0059, 0x005A, 0x007A, 0x005A, 0x007A, 0x005A, 0x007A, 0x0073, /* U+0180 */ 0x0180, 0x0181, 0x0182, 0x0183, 0x0184, 0x0185, 0x0186, 0x0187, + // TODO: A lot of letters are their own base code points, but for + // some (e.g. U+0180) it doesn't seem right. Ideally each code point should + // be checked individually with all languages it's used in. /* U+0188 */ 0x0188, 0x0189, 0x018A, 0x018B, 0x018C, 0x018D, 0x018E, 0x018F, /* U+0190 */ 0x0190, 0x0191, 0x0192, 0x0193, 0x0194, 0x0195, 0x0196, 0x0197, /* U+0198 */ 0x0198, 0x0199, 0x019A, 0x019B, 0x019C, 0x019D, 0x019E, 0x019F, |