Package list mozc / 262156b
Update from the upstream. * Updates for Python3 / MacSDK 10.15 / MSVS 2017 * Some code refactoring Hiroyuki Komatsu 11 months ago
98 changed file(s) with 765 addition(s) and 972 deletion(s). Raw diff Collapse all Expand all
3232 python build_mozc.py runtests -c Debug
3333 ```
3434
35 Experimental: Instead of build_mozc.py, you can try to use Bazel.
36
37 ```
38 bazel build package --config oss_linux
39 ```
40
41 `package` is an alias to build `server:mozc_server` and `gui/tool:mozc_tool`.
42
43
3544 ### Build Mozc library for Android:
3645
3746 Client code for Android apk is deprecated.
4150 The conversion engine for Android is built with Bazel.
4251
4352 ```
44 bazel build android/jni:mozc_lib --config oss_android
53 bazel build package --config oss_android
4554 ```
4655
56 `package` is an alias to build `android/jni:mozc_lib`.
4757
4858 ## Build configurations for Linux desktop
4959 In `python build_mozc.py gyp` step, there are two different styles to customize configurations. One is `GYP_DEFINES` environment variable and the other is commandline option.
3030 # Description:
3131 # Declaration of package_group for visibility managing.
3232
33 load("//:build_defs.bzl", "select_mozc")
3334 load("//tools/build_defs:stubs.bzl", "bzl_library")
3435
3536 package_group(
125126 name = "build_defs_bzl",
126127 srcs = ["build_defs.bzl"],
127128 parse_tests = False,
128 visibility = ["//visibility:private"],
129 visibility = ["//:__subpackages__"],
129130 )
131
132 filegroup(
133 name = "package",
134 srcs = select_mozc(
135 default = [],
136 oss_android = ["//android/jni:mozc_lib"],
137 oss_linux = [
138 "//gui/tool:mozc_tool",
139 "//server:mozc_server",
140 ],
141 ),
142 )
0 package(default_visibility = ["//visibility:public"])
1
2 exports_files(["usage_dict.txt"])
3535 # tag = "v3.6.0.1", # 2018-06-09
3636 # )
3737
38 # Japanese Usage Dictionary
39 new_local_repository(
40 name = "ja_usage_dict",
41 path = "third_party/japanese_usage_dictionary",
42 build_file = "BUILD.ja_usage_dict",
43 )
44
45 # Qt
3846 new_local_repository(
3947 name = "io_qt",
4048 # This path should be updated per the environment.
4040
4141 __author__ = "hidehiko"
4242
43 import cStringIO as StringIO
43 import io
4444 import logging
4545 import optparse
4646 import os
288288 def _ConsumeFloatList(self, s, num):
289289 """Parses num floating values from s."""
290290 result = []
291 for _ in xrange(num):
291 for _ in range(num):
292292 value, s = self._ConsumeFloat(s)
293293 result.append(value)
294294 return result, s
10341034
10351035 # Interface for drawable conversion.
10361036 def ConvertPictureDrawable(self, path):
1037 output = _OutputStream(StringIO.StringIO())
1037 output = _OutputStream(io.BytesIO())
10381038 self._ConvertPictureDrawableInternal(ElementTree.parse(path), output)
10391039 return output.output.getvalue()
10401040
10411041 def ConvertStateListDrawable(self, drawable_source_list):
1042 output = _OutputStream(StringIO.StringIO())
1042 output = _OutputStream(io.BytesIO())
10431043 output.WriteByte(DRAWABLE_STATE_LIST)
10441044 output.WriteByte(len(drawable_source_list))
10451045 for (state_list, path) in drawable_source_list:
3434 # Usage:
3535 # % blaze --blazerc android/blazerc build --config=android_arm android/jni:libmozc.so
3636
37 load(
38 "//:build_defs.bzl",
39 "cc_library_mozc",
40 )
37 load("//:build_defs.bzl", "cc_library_mozc")
4138
4239 cc_library_mozc(
4340 name = "mozc_lib",
4441 srcs = ["mozcjni.cc"],
42 visibility = ["//:__pkg__"],
4543 deps = [
4644 "//base:logging",
4745 "//base:singleton",
514514 'target_name': 'breakpad',
515515 'type': 'none',
516516 'variables': {
517 'pbdir': '<(third_party_dir)/breakpad',
517 'bpdir': '<(third_party_dir)/breakpad',
518518 },
519519 'actions': [{
520520 'action_name': 'build_breakpad',
521521 'inputs': [
522 '<(pbdir)/src/client/mac/Breakpad.xcodeproj/project.pbxproj',
522 '<(bpdir)/src/client/mac/Breakpad.xcodeproj/project.pbxproj',
523523 ],
524524 'outputs': [
525525 '<(mac_breakpad_dir)/Breakpad.framework',
529529 ],
530530 'action': [
531531 '<(python)', '../build_tools/build_breakpad.py',
532 '--pbdir', '<(pbdir)',
532 '--bpdir', '<(bpdir)',
533533 '--outdir', '<(mac_breakpad_dir)',
534534 '--sdk', 'macosx<(mac_sdk)',
535535 '--deployment_target', '<(mac_deployment_target)',
144144 const uint32 lo = Fingerprint32WithSeed(str, kFingerPrintSeed1);
145145 uint64 result = static_cast<uint64>(hi) << 32 | static_cast<uint64>(lo);
146146 if ((hi == 0) && (lo < 2)) {
147 result ^= GG_ULONGLONG(0x130f9bef94a0a928);
147 result ^= 0x130f9bef94a0a928uLL;
148148 }
149149 return result;
150150 }
115115
116116 value_type operator*() { return adapter_(iter_); }
117117
118 // MSVS 2017 requires this definition.
119 // See: https://github.com/tensorflow/tensorflow/issues/15925
120 value_type operator*() const { return adapter_(iter_); }
121
118122 pointer operator->() const { return &(operator*()); }
119123
120124 IteratorAdapter &operator++() {
537537 // return false when an integer overflow happens.
538538 bool AddAndCheckOverflow(uint64 arg1, uint64 arg2, uint64 *output) {
539539 *output = arg1 + arg2;
540 if (arg2 > (kuint64max - arg1)) {
540 if (arg2 > (std::numeric_limits<uint64>::max() - arg1)) {
541541 // overflow happens
542542 return false;
543543 }
548548 // return false when an integer overflow happens.
549549 bool MultiplyAndCheckOverflow(uint64 arg1, uint64 arg2, uint64 *output) {
550550 *output = arg1 * arg2;
551 if (arg1 != 0 && arg2 > (kuint64max / arg1)) {
551 if (arg1 != 0 && arg2 > (std::numeric_limits<uint64>::max() / arg1)) {
552552 // overflow happens
553553 return false;
554554 }
618618
619619 template <>
620620 bool SafeCast(int64 src, int16 *dest) {
621 if (src < static_cast<int64>(kint16min) ||
622 static_cast<int64>(kint16max) < src) {
621 if (src < static_cast<int64>(std::numeric_limits<int16>::min()) ||
622 static_cast<int64>(std::numeric_limits<int16>::max()) < src) {
623623 return false;
624624 }
625625 *dest = static_cast<int16>(src);
628628
629629 template <>
630630 bool SafeCast(int64 src, int32 *dest) {
631 if (src < static_cast<int64>(kint32min) ||
632 static_cast<int64>(kint32max) < src) {
631 if (src < static_cast<int64>(std::numeric_limits<int32>::min()) ||
632 static_cast<int64>(std::numeric_limits<int32>::max()) < src) {
633633 return false;
634634 }
635635 *dest = static_cast<int32>(src);
638638
639639 template <>
640640 bool SafeCast(uint64 src, int64 *dest) {
641 if (src > static_cast<uint64>(kint64max)) {
641 if (src > static_cast<uint64>(std::numeric_limits<int64>::max())) {
642642 return false;
643643 }
644644 *dest = static_cast<int64>(src);
647647
648648 template <>
649649 bool SafeCast(uint64 src, uint16 *dest) {
650 if (src > static_cast<uint64>(kuint16max)) {
650 if (src > static_cast<uint64>(std::numeric_limits<uint16>::max())) {
651651 return false;
652652 }
653653 *dest = static_cast<uint16>(src);
656656
657657 template <>
658658 bool SafeCast(uint64 src, uint32 *dest) {
659 if (src > static_cast<uint64>(kuint32max)) {
659 if (src > static_cast<uint64>(std::numeric_limits<uint32>::max())) {
660660 return false;
661661 }
662662 *dest = static_cast<uint32>(src);
677677 if (src == 0x8000000000000000ul) {
678678 // This is an exceptional case. |src| isn't in the range of int64,
679679 // but |-src| is in the range.
680 *dest = kint64min;
680 *dest = std::numeric_limits<int64>::min();
681681 return true;
682682 }
683683 return false;
965965 // "一十二百" = [1, 10, 2, 100] => error
966966 bool InterpretNumbersInJapaneseWay(const std::vector<uint64> &numbers,
967967 uint64 *output) {
968 uint64 last_base = kuint64max;
968 uint64 last_base = std::numeric_limits<uint64>::max();
969969 auto begin = numbers.begin();
970970 *output = 0;
971971 do {
2828
2929 #include "base/number_util.h"
3030
31 #include <limits>
32
3133 #include "base/port.h"
3234 #include "testing/base/public/googletest.h"
3335 #include "testing/base/public/gunit.h"
7173 EXPECT_EQ(-12345, value);
7274 value = 0x4321;
7375 EXPECT_TRUE(NumberUtil::SafeStrToInt16("-32768", &value));
74 EXPECT_EQ(kint16min, value); // min of 16-bit signed integer
76 EXPECT_EQ(std::numeric_limits<int16>::min(), value);
7577 value = 0x4321;
7678 EXPECT_TRUE(NumberUtil::SafeStrToInt16("32767", &value));
77 EXPECT_EQ(kint16max, value); // max of 16-bit signed integer
79 EXPECT_EQ(std::numeric_limits<int16>::max(), value);
7880 value = 0x4321;
7981 EXPECT_TRUE(NumberUtil::SafeStrToInt16(" 1", &value));
8082 EXPECT_EQ(1, value);
131133 EXPECT_EQ(-12345678, value);
132134 value = 0xDEADBEEF;
133135 EXPECT_TRUE(NumberUtil::SafeStrToInt32("-2147483648", &value));
134 EXPECT_EQ(kint32min, value); // min of 32-bit signed integer
136 EXPECT_EQ(std::numeric_limits<int32>::min(), value);
135137 value = 0xDEADBEEF;
136138 EXPECT_TRUE(NumberUtil::SafeStrToInt32("2147483647", &value));
137 EXPECT_EQ(kint32max, value); // max of 32-bit signed integer
139 EXPECT_EQ(std::numeric_limits<int32>::max(), value);
138140 value = 0xDEADBEEF;
139141 EXPECT_TRUE(NumberUtil::SafeStrToInt32(" 1", &value));
140142 EXPECT_EQ(1, value);
192194 EXPECT_EQ(-12345678, value);
193195 value = 0xDEADBEEF;
194196 EXPECT_TRUE(NumberUtil::SafeStrToInt64("-9223372036854775808", &value));
195 EXPECT_EQ(kint64min, value); // min of 64-bit signed integer
197 EXPECT_EQ(std::numeric_limits<int64>::min(), value);
196198 value = 0xDEADBEEF;
197199 EXPECT_TRUE(NumberUtil::SafeStrToInt64("9223372036854775807", &value));
198 EXPECT_EQ(kint64max, value); // max of 64-bit signed integer
200 EXPECT_EQ(std::numeric_limits<int64>::max(), value);
199201
200202 EXPECT_FALSE(NumberUtil::SafeStrToInt64("-9223372036854775809", // overflow
201203 &value));
7575 #undef MOZC_OS_DEFINED
7676
7777
78 #ifndef _MSC_VER
79 #if !defined(__STDC_FORMAT_MACROS)
80 #define __STDC_FORMAT_MACROS
81 #endif // !__STDC_FORMAT_MACROS
82 #include <inttypes.h>
83 #endif // _MSC_VER
84 #include <stdint.h>
85 #include <sys/types.h>
86 #include <cstddef>
78
79 #ifdef GOOGLE_JAPANESE_INPUT_BUILD
80
81 #include "absl/base/attributes.h"
82 #include "absl/base/integral_types.h"
83 #include "absl/base/macros.h"
84
85 #else // GOOGLE_JAPANESE_INPUT_BUILD
86
87 #include <cstdint>
8788
8889 #include "absl/base/attributes.h"
8990 #include "absl/base/macros.h"
9091
91 #ifdef GOOGLE_JAPANESE_INPUT_BUILD
92 #include "absl/base/integral_types.h"
93 #else // GOOGLE_JAPANESE_INPUT_BUILD
92 // Integral types.
93 typedef std::int8_t int8;
94 typedef std::int16_t int16;
95 typedef std::int32_t int32;
96 typedef std::int64_t int64;
9497
95 // Integral types.
96 typedef signed char int8;
97 typedef short int16; // NOLINT
98 typedef int int32;
99 #ifdef COMPILER_MSVC
100 typedef __int64 int64;
101 #else
102 typedef long long int64; // NOLINT
103 #endif /* COMPILER_MSVC */
104
105 typedef unsigned char uint8;
106 typedef unsigned short uint16; // NOLINT
107 typedef unsigned int uint32;
108 #ifdef COMPILER_MSVC
109 typedef unsigned __int64 uint64;
110 #else
111 typedef unsigned long long uint64; // NOLINT
112 #endif /* COMPILER_MSVC */
98 typedef std::uint8_t uint8;
99 typedef std::uint16_t uint16;
100 typedef std::uint32_t uint32;
101 typedef std::uint64_t uint64;
113102
114103 typedef signed int char32;
115
116 #ifdef COMPILER_MSVC /* if Visual C++ */
117
118 // VC++ long long suffixes
119 #define GG_LONGLONG(x) x##I64
120 #define GG_ULONGLONG(x) x##UI64
121
122 #else /* not Visual C++ */
123
124 #define GG_LONGLONG(x) x##LL
125 #define GG_ULONGLONG(x) x##ULL
126
127 #endif // COMPILER_MSVC
128
129 // INT_MIN, INT_MAX, UINT_MAX family at Google
130 const uint8 kuint8max{0xFF};
131 const uint16 kuint16max{0xFFFF};
132 const uint32 kuint32max{0xFFFFFFFF};
133 const uint64 kuint64max{GG_ULONGLONG(0xFFFFFFFFFFFFFFFF)};
134 const int8 kint8min{~0x7F};
135 const int8 kint8max{0x7F};
136 const int16 kint16min{~0x7FFF};
137 const int16 kint16max{0x7FFF};
138 const int32 kint32min{~0x7FFFFFFF};
139 const int32 kint32max{0x7FFFFFFF};
140 const int64 kint64min{GG_LONGLONG(~0x7FFFFFFFFFFFFFFF)};
141 const int64 kint64max{GG_LONGLONG(0x7FFFFFFFFFFFFFFF)};
142104
143105 #endif // GOOGLE_JAPANESE_INPUT_BUILD
144106
3131 #include <climits>
3232 #include <cstdlib>
3333 #include <cstring>
34 #include <limits>
3435 #include <map>
3536 #include <sstream>
3637 #include <string>
3738
38 #include "base/compiler_specific.h"
3939 #include "base/file_stream.h"
4040 #include "base/file_util.h"
4141 #include "base/logging.h"
19341934 uint64 value;
19351935 } kCorrectPairs[] = {
19361936 {"\x00\x00\x00\x00\x00\x00\x00\x00", 0},
1937 {"\x00\x00\x00\x00\x00\x00\x00\xFF", kuint8max},
1938 {"\x00\x00\x00\x00\x00\x00\xFF\xFF", kuint16max},
1939 {"\x00\x00\x00\x00\xFF\xFF\xFF\xFF", kuint32max},
1940 {"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", kuint64max},
1937 {"\x00\x00\x00\x00\x00\x00\x00\xFF", std::numeric_limits<uint8>::max()},
1938 {"\x00\x00\x00\x00\x00\x00\xFF\xFF", std::numeric_limits<uint16>::max()},
1939 {"\x00\x00\x00\x00\xFF\xFF\xFF\xFF", std::numeric_limits<uint32>::max()},
1940 {"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", std::numeric_limits<uint64>::max()},
19411941 {"\x01\x23\x45\x67\x89\xAB\xCD\xEF", 0x0123456789ABCDEF},
19421942 {"\xFE\xDC\xBA\x98\x76\x54\x32\x10", 0xFEDCBA9876543210},
19431943 };
3232 # so required macros are defined by depending on it.
3333
3434 load("//tools/build_defs:build_cleaner.bzl", "register_extension_info")
35 load("//tools/build_defs:stubs.bzl", "pytype_strict_binary", "pytype_strict_library")
3536 load("//tools/build_rules/android_cc_test:def.bzl", "android_cc_test")
3637
3738 def cc_library_mozc(deps = [], **kwargs):
9192 label_regex_for_dep = "{extension_name}",
9293 )
9394
94 def py_library_mozc(name, srcs, **kwargs):
95 def py_library_mozc(name, srcs, srcs_version = "PY2AND3", **kwargs):
9596 """py_library wrapper generating import-modified python scripts for iOS."""
96 native.py_library(
97 pytype_strict_library(
9798 name = name,
9899 srcs = srcs,
100 srcs_version = srcs_version,
99101 **kwargs
100102 )
101103
104106 label_regex_for_dep = "{extension_name}",
105107 )
106108
107 def py_binary_mozc(name, srcs, python_version = "PY3", **kwargs):
109 def py_binary_mozc(name, srcs, python_version = "PY3", srcs_version = "PY2AND3", **kwargs):
108110 """py_binary wrapper generating import-modified python script for iOS.
109111
110112 To use this rule, corresponding py_library_mozc needs to be defined to
111113 generate iOS sources.
112114 """
113 native.py_binary(
115 pytype_strict_binary(
114116 name = name,
115117 srcs = srcs,
116118 python_version = python_version,
119 srcs_version = srcs_version,
120 test_lib = True,
117121 # This main specifier is required because, without it, py_binary expects
118122 # that the file name of source containing main() is name.py.
119123 main = srcs[0],
476476 gyp_options.extend(['-D', 'target_platform=%s' % target_platform_value])
477477
478478 if IsWindows():
479 gyp_options.extend(['-G', 'msvs_version=2015'])
479 gyp_options.extend(['-G', 'msvs_version=2017'])
480480
481481 if (target_platform == 'Linux' and
482482 '%s/unix/ibus/ibus.gyp' % SRC_DIR in gyp_file_names):
101101 ],
102102 )
103103
104 py_library_mozc(
105 name = "replace_version_lib",
106 srcs = ["replace_version.py"],
107 deps = [":mozc_version_lib"],
108 )
109
110104 py_binary_mozc(
111105 name = "replace_version",
112106 srcs = ["replace_version.py"],
130124 name = "zlib_util",
131125 srcs = ["zlib_util.py"],
132126 visibility = ["//:__subpackages__"],
133 deps = [":zlib_util_main_lib"],
134 )
135
136 py_library(
137 name = "zlib_util_main_lib",
138 srcs = ["zlib_util.py"],
127 deps = [":zlib_util_lib"],
139128 )
140129
141130 py_library_mozc(
3030 """Script building Breakpad for Mozc/Mac.
3131
3232 ././tools/build_breakpad.py
33 --pbdir ./third_party/breakpad --outdir /tmp/breakpad
33 --bpdir ./third_party/breakpad --outdir /tmp/breakpad
3434 """
3535
3636 from __future__ import absolute_import
4545
4646 def ParseOption():
4747 parser = optparse.OptionParser()
48 parser.add_option('--pbdir', default='./third_party/breakpad')
48 parser.add_option('--bpdir', default='./third_party/breakpad')
4949 parser.add_option('--outdir', default='./out_mac/Release/Breakpad')
50 parser.add_option('--sdk', default='macosx10.14')
50 parser.add_option('--sdk', default='macosx10.15')
5151 parser.add_option('--deployment_target', default='10.9')
5252
5353 (opts, _) = parser.parse_args()
9090 Xcodebuild(projdir, 'symupload', 'x86_64', sdk, deployment_target, outdir)
9191
9292
93 def CreateOutDir(pbdir, outdir):
93 def CreateOutDir(bpdir, outdir):
9494 workdir = os.path.join(outdir, 'src')
9595 if not os.path.isdir(workdir):
9696 os.makedirs(workdir)
97 ProcessCall(['rsync', '-avH', os.path.join(pbdir, 'src/'), workdir])
97 ProcessCall(['rsync', '-avH', os.path.join(bpdir, 'src/'), workdir])
9898
9999
100100 def main():
101101 opts = ParseOption()
102 pbdir = os.path.abspath(opts.pbdir)
102 bpdir = os.path.abspath(opts.bpdir)
103103 outdir = os.path.abspath(opts.outdir)
104104
105 CreateOutDir(pbdir, outdir)
105 CreateOutDir(bpdir, outdir)
106106 BuildBreakpad(outdir, opts.sdk, opts.deployment_target)
107107 BuildDumpSyms(outdir, opts.sdk, opts.deployment_target)
108108 BuildSymupload(outdir, opts.sdk, opts.deployment_target)
113113 for word_index in range(0, len(data), 8):
114114 word_chunk = data[word_index:word_index + 8].ljust(8, '\x00')
115115 stream.write('0x%016X, ' % struct.unpack('<Q', six.b(word_chunk)))
116 if (word_index / 8) % 4 == 3:
116 if (word_index // 8) % 4 == 3:
117117 # Line feed for every 4 elements.
118118 stream.write('\n')
119119
120120 template_dict = {}
121121 with open(template_path) as template_file:
122122 for line in template_file:
123 matchobj = re.match(r'(\w+) *= *(.*)', line.strip())
123 matchobj = re.match(r'(\w+) *= *(\w*)', line.strip())
124124 if matchobj:
125125 var = matchobj.group(1)
126126 val = matchobj.group(2)
152152 A replaced string.
153153 """
154154 for unused_prefix, var_name, value in variables:
155 text = text.replace('@%s@' % var_name.upper(), str(value))
155 if var_name:
156 text = text.replace('@%s@' % var_name.upper(), str(value))
156157
157158 return text
158159
260260 py_binary_mozc(
261261 name = "gen_typing_model",
262262 srcs = ["gen_typing_model.py"],
263 python_version = "PY2",
263 python_version = "PY3",
264264 deps = [":gen_typing_model_lib"],
265265 )
266266
702702 py_binary_mozc(
703703 name = "gen_boundary_data",
704704 srcs = ["gen_boundary_data.py"],
705 python_version = "PY2",
705 python_version = "PY3",
706706 visibility = ["//data_manager:__subpackages__"],
707707 deps = [":gen_boundary_data_lib"],
708708 )
3030
3131 #include <algorithm>
3232 #include <climits>
33 #include <limits>
3334 #include <string>
3435 #include <utility>
3536 #include <vector>
221222 ConverterImpl::ConverterImpl()
222223 : pos_matcher_(nullptr),
223224 immutable_converter_(nullptr),
224 general_noun_id_(kuint16max) {}
225 general_noun_id_(std::numeric_limits<uint16>::max()) {}
225226
226227 ConverterImpl::~ConverterImpl() = default;
227228
104104
105105
106106 def GenerateHeader(files):
107 try:
108 print('namespace mozc{')
109 print('struct TestCase {')
110 print(' const bool enabled;')
111 print(' const char *tsv;')
112 print('} kTestData[] = {')
113 for file in files:
107 print('namespace mozc{')
108 print('struct TestCase {')
109 print(' const bool enabled;')
110 print(' const char *tsv;')
111 print('} kTestData[] = {')
112
113 for file in files:
114 try:
114115 for enabled, line in ParseFile(file):
115116 print(' {%s, "%s"},' % (enabled, EscapeString(line)))
116 print(' {false, nullptr},')
117 print('};')
118 print('} // namespace mozc')
119 except:
120 print('cannot open %s' % (file))
121 sys.exit(1)
117 except:
118 print('cannot open %s' % file)
119 sys.exit(1)
120
121 print(' {false, nullptr},')
122 print('};')
123 print('} // namespace mozc')
122124
123125
124126 def main():
2929 #include "converter/segments.h"
3030
3131 #include <algorithm>
32 #include <limits>
3233 #include <sstream> // For DebugString()
3334 #include <string>
3435
114115 size_t content_key_len,
115116 size_t content_value_len,
116117 uint32 *result) {
117 if (key_len > kuint8max || value_len > kuint8max ||
118 content_key_len > kuint8max || content_value_len > kuint8max) {
118 if (key_len > std::numeric_limits<uint8>::max() ||
119 value_len > std::numeric_limits<uint8>::max() ||
120 content_key_len > std::numeric_limits<uint8>::max() ||
121 content_value_len > std::numeric_limits<uint8>::max()) {
119122 return false;
120123 }
121124 *result = (static_cast<uint32>(key_len) << 24) |
3232 py_binary(
3333 name = "filter",
3434 srcs = ["filter.py"],
35 python_version = "PY2",
35 python_version = "PY3",
3636 visibility = [
3737 ],
3838 deps = ["//build_tools:code_generator_util"],
3030 MAJOR = 2
3131
3232 MINOR = 25
33
34 # Number to be increased. This value may be replaced by other tools.
3335 BUILD = 4100
36
37 # Represent the platform and release channel.
3438 REVISION = 100
3539
3640 # This version represents the version of Mozc IME engine (converter, predictor,
112112 py_binary_mozc(
113113 name = "gen_connection_data",
114114 srcs = ["gen_connection_data.py"],
115 python_version = "PY2",
115 python_version = "PY3",
116116 deps = [
117117 ":gen_connection_data_lib",
118118 "//build_tools:code_generator_util",
2828
2929 #include "data_manager/dataset_reader.h"
3030
31 #include <limits>
3132 #include <sstream>
3233 #include <string>
3334
110111 // Metadata size is too large.
111112 data = magic;
112113 data.append("content and metadata");
113 data.append(Util::SerializeUint64(kuint64max));
114 data.append(Util::SerializeUint64(std::numeric_limits<uint64>::max()));
114115 EXPECT_FALSE(DataSetReader::VerifyChecksum(data));
115116 EXPECT_FALSE(r.Init(data, magic));
116117
161162 auto e = md.add_entries();
162163 e->set_name("google");
163164 e->set_offset(content.size());
164 e->set_size(kuint64max); // Too big size
165 e->set_size(std::numeric_limits<uint64>::max()); // Too big size
165166 const string &md_str = md.SerializeAsString();
166167 string image = content;
167168 image.append(md_str);
222222 if cost == INVALID_COST:
223223 cost = INVALID_1BYTE_COST
224224 else:
225 cost /= resolution
225 cost //= resolution
226226 assert cost != INVALID_1BYTE_COST
227227 values.append(cost)
228228
9292 "//data/typing:typing_model_qwerty_mobile-hiragana.tsv",
9393 "//data/typing:typing_model_toggle_flick-hiragana.tsv",
9494 ],
95 usage_dict = "//third_party/japanese_usage_dictionary:usage_dict.txt",
95 usage_dict = "@ja_usage_dict//:usage_dict.txt",
9696 use_1byte_cost = "false",
9797 user_pos_def = "//data/rules:user_pos.def",
9898 variant_rule = "//data/single_kanji:variant_rule.txt",
127127 "//data/typing:typing_model_qwerty_mobile-hiragana.tsv",
128128 "//data/typing:typing_model_toggle_flick-hiragana.tsv",
129129 ],
130 usage_dict = "//third_party/japanese_usage_dictionary:usage_dict.txt",
130 usage_dict = "@ja_usage_dict//:usage_dict.txt",
131131 use_1byte_cost = "false",
132132 user_pos_def = "//data/rules:user_pos.def",
133133 variant_rule = "//data/single_kanji:variant_rule.txt",
573573 py_binary_mozc(
574574 name = "gen_user_pos_data",
575575 srcs = ["gen_user_pos_data.py"],
576 python_version = "PY2",
576 python_version = "PY3",
577577 visibility = ["//:__subpackages__"],
578578 deps = [
579579 ":gen_user_pos_data_lib",
632632 py_binary_mozc(
633633 name = "gen_pos_rewrite_rule",
634634 srcs = ["gen_pos_rewrite_rule.py"],
635 python_version = "PY2",
635 python_version = "PY3",
636636 visibility = ["//:__subpackages__"],
637637 deps = [":gen_pos_rewrite_rule_lib"],
638638 )
731731 py_binary_mozc(
732732 name = "gen_suffix_data",
733733 srcs = ["gen_suffix_data.py"],
734 python_version = "PY2",
734 python_version = "PY3",
735735 visibility = ["//:__subpackages__"],
736736 deps = [
737737 ":gen_suffix_data_lib",
225225 pos_database.Parse(options.id_file, options.special_pos_file)
226226 pos_matcher = pos_util.PosMatcher(pos_database)
227227 pos_matcher.Parse(options.pos_matcher_rule_file)
228 with codecs.open(options.output_pos_matcher_data, 'wb') as stream:
228 with open(options.output_pos_matcher_data, 'wb') as stream:
229229 OutputPosMatcherData(pos_matcher, stream)
230230
231231
3030
3131 #include <algorithm>
3232 #include <cstdlib>
33 #include <limits>
3334 #include <memory>
3435 #include <string>
3536 #include <utility>
8384 // Don't use small cost encoding by default.
8485 original_flags_min_key_length_to_use_small_cost_encoding_ =
8586 FLAGS_min_key_length_to_use_small_cost_encoding;
86 FLAGS_min_key_length_to_use_small_cost_encoding = kint32max;
87 FLAGS_min_key_length_to_use_small_cost_encoding =
88 std::numeric_limits<int32>::max();
8789
8890 request_.Clear();
8991 config::ConfigHandler::GetDefaultConfig(&config_);
5858 "about_dialog_en.qm",
5959 "about_dialog_ja.qm",
6060 "//data/images:product_icon_32bpp-128.png",
61 "//gui/base:tr_en.qm",
62 "//gui/base:tr_ja.qm",
6163 ],
6264 outs = ["qrc_about_dialog.cc"],
6365 qrc_file = "about_dialog.qrc",
3838 #include "base/system_util.h"
3939 #include "base/util.h"
4040 #include "base/version.h"
41 #include "gui/base/util.h"
4142
4243 namespace mozc {
4344 namespace gui {
5657 std::string tmp;
5758 const std::string file_path =
5859 FileUtil::JoinPath(SystemUtil::GetDocumentDirectory(), filenames[i]);
59 Util::StringReplace(*str, filenames[i], file_path, false, &tmp);
60 mozc::Util::StringReplace(*str, filenames[i], file_path, false, &tmp);
6061 *str = tmp;
6162 return true;
6263 }
7374
7475 } // namespace
7576
76 AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), callback_(NULL) {
77 AboutDialog::AboutDialog(QWidget *parent)
78 : QDialog(parent), callback_(nullptr) {
7779 setupUi(this);
7880 setWindowFlags(Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
7981 setWindowModality(Qt::NonModal);
8587 version_info += Version::GetMozcVersion().c_str();
8688 version_info += ")";
8789 version_label->setText(version_info);
90 gui::Util::ReplaceTitle(this);
91 gui::Util::ReplaceLabel(label);
92 gui::Util::ReplaceLabel(label_credits);
93 gui::Util::ReplaceLabel(label_terms);
8894
8995 QPalette palette;
9096 palette.setColor(QPalette::Window, QColor(236, 233, 216));
129135 if (!RunLevel::IsValidClientRunLevel()) {
130136 return;
131137 }
132 if (callback_ != NULL) {
138 if (callback_ != nullptr) {
133139 callback_->linkActivated(link);
134140 } else {
135141 defaultLinkActivated(link);
11 <qresource>
22 <file>about_dialog_ja.qm</file>
33 <file>about_dialog_en.qm</file>
4 <file alias="tr_ja.qm">../base/tr_ja.qm</file>
5 <file alias="tr_en.qm">../base/tr_en.qm</file>
46 <file alias="product_logo.png">../../data/images/product_icon_32bpp-128.png</file>
57 </qresource>
68 </RCC>
5858 </size>
5959 </property>
6060 <property name="windowTitle">
61 <string>About Mozc</string>
61 <string>About [ProductName]</string>
6262 </property>
6363 <widget class="QFrame" name="color_frame">
6464 <property name="geometry">
9494 <x>20</x>
9595 <y>10</y>
9696 <width>471</width>
97 <height>81</height>
97 <height>82</height>
9898 </rect>
9999 </property>
100100 <layout class="QGridLayout" name="gridLayout_3">
121121 </font>
122122 </property>
123123 <property name="text">
124 <string>&lt;html&gt;&lt;body&gt;Mozc is made possible by &lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;open source software&lt;/span&gt;&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;</string>
124 <string>&lt;html&gt;&lt;body&gt;[ProductName] is made possible by &lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;open source software&lt;/span&gt;&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;</string>
125125 </property>
126126 </widget>
127127 </item>
159159 </font>
160160 </property>
161161 <property name="text">
162 <string>&lt;html&gt;&lt;body&gt;Mozc &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;product information&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</string>
162 <string>&lt;html&gt;&lt;body&gt;[ProductName] &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;product information&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</string>
163163 </property>
164164 </widget>
165165 </item>
200200 </font>
201201 </property>
202202 <property name="text">
203 <string>Mozc</string>
203 <string>[ProductName]</string>
204204 </property>
205205 <property name="alignment">
206206 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
44 <name>AboutDialog</name>
55 <message>
66 <location filename="about_dialog.ui" line="32"/>
7 <source>About Mozc</source>
7 <source>About [ProductName]</source>
88 <translation type="unfinished"></translation>
99 </message>
1010 <message>
1414 </message>
1515 <message utf8="true">
1616 <location filename="about_dialog.ui" line="80"/>
17 <source>Copyright © 2019 Google Inc. All rights reserved.</source>
17 <source>Copyright © 2020 Google Inc. All rights reserved.</source>
1818 <translation type="unfinished"></translation>
1919 </message>
2020 <message>
2121 <location filename="about_dialog.ui" line="95"/>
22 <source>&lt;html&gt;&lt;body&gt;Mozc is made possible by &lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;open source software&lt;/span&gt;&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;</source>
22 <source>&lt;html&gt;&lt;body&gt;[ProductName] is made possible by &lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;open source software&lt;/span&gt;&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;</source>
2323 <translation type="unfinished"></translation>
2424 </message>
2525 <message>
2626 <location filename="about_dialog.ui" line="133"/>
27 <source>&lt;html&gt;&lt;body&gt;Mozc &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;product information&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</source>
27 <source>&lt;html&gt;&lt;body&gt;[ProductName] &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;product information&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</source>
2828 <translation type="unfinished"></translation>
2929 </message>
3030 <message>
3131 <location filename="about_dialog.ui" line="174"/>
32 <source>Mozc</source>
32 <source>[ProductName]</source>
3333 <translation type="unfinished"></translation>
3434 </message>
3535 <message>
44 <name>AboutDialog</name>
55 <message>
66 <location filename="about_dialog.ui" line="32"/>
7 <source>About Mozc</source>
8 <translation>Mozcについて</translation>
7 <source>About [ProductName]</source>
8 <translation>[ProductName] について</translation>
99 </message>
1010 <message>
1111 <location filename="about_dialog.ui" line="59"/>
1414 </message>
1515 <message utf8="true">
1616 <location filename="about_dialog.ui" line="80"/>
17 <source>Copyright © 2019 Google Inc. All rights reserved.</source>
17 <source>Copyright © 2020 Google Inc. All rights reserved.</source>
1818 <translation type="unfinished"></translation>
1919 </message>
2020 <message>
2121 <location filename="about_dialog.ui" line="95"/>
22 <source>&lt;html&gt;&lt;body&gt;Mozc is made possible by &lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;open source software&lt;/span&gt;&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;</source>
23 <translation>&lt;html&gt;&lt;body&gt;Mozcは&lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;オープンソースソフトウェア&lt;/span&gt;&lt;/a&gt;を利用しています。&lt;/body&gt;&lt;/html&gt;</translation>
22 <source>&lt;html&gt;&lt;body&gt;[ProductName] is made possible by &lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;open source software&lt;/span&gt;&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;</source>
23 <translation>&lt;html&gt;&lt;body&gt;[ProductName] は&lt;a href=&quot;file://credits_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;オープンソースソフトウェア&lt;/span&gt;&lt;/a&gt;を利用しています。&lt;/body&gt;&lt;/html&gt;</translation>
2424 </message>
2525 <message>
2626 <location filename="about_dialog.ui" line="133"/>
27 <source>&lt;html&gt;&lt;body&gt;Mozc &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;product information&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</source>
28 <translation type="unfinished">&lt;html&gt;&lt;body&gt;Mozc &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;製品情報&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</translation>
27 <source>&lt;html&gt;&lt;body&gt;[ProductName] &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;product information&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</source>
28 <translation type="unfinished">&lt;html&gt;&lt;body&gt; [ProductName] &lt;a href=&quot;https://github.com/google/mozc&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;製品情報&lt;/span&gt;&lt;/a&gt; &lt;a href=&quot;https://github.com/google/mozc/issues&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;issues&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</translation>
2929 </message>
3030 <message>
3131 <source>&lt;html&gt;&lt;body&gt;Google &lt;a href=&quot;file://privacy_en.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;privacy policy&lt;/span&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</source>
3333 </message>
3434 <message>
3535 <location filename="about_dialog.ui" line="174"/>
36 <source>Mozc</source>
37 <translation>Mozc</translation>
36 <source>[ProductName]</source>
37 <translation>[ProductName]</translation>
3838 </message>
3939 <message>
4040 <location filename="about_dialog.ui" line="197"/>
4949 }
5050
5151 mozc::gui::LocaleUtil::InstallTranslationMessageAndFont("about_dialog");
52 mozc::gui::LocaleUtil::InstallTranslationMessageAndFont("tr");
5253 mozc::gui::AboutDialog about_dialog;
5354
5455 about_dialog.show();
6161 srcs = ["window_title_modifier.h"],
6262 outs = ["moc_window_title_modifier.cc"],
6363 )
64
65 exports_files([
66 "tr_en.qm",
67 "tr_ja.qm",
68 ])
6469
6570 qt_rcc_mozc(
6671 name = "qrc_tr",
4949
5050 #include <QtGui/QtGui>
5151 #include <map>
52 #include <memory>
5253 #include <string>
5354
5455 #include "base/logging.h"
55 #include "base/singleton.h"
56 #include "base/util.h"
5756
5857 #ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE
5958 #include "gui/base/window_title_modifier.h"
6362 namespace gui {
6463 namespace {
6564
66 // sicnce Qtranslator and QFont must be available until
67 // application exits, allocate the data with Singleton.
68 class TranslationDataImpl {
69 public:
70 void InstallTranslationMessageAndFont(const char *resource_name);
65 void InstallEventFilter() {
66 #ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE
67 static WindowTitleModifier window_title_modifier;
68 // Install WindowTilteModifier for official dev channel
69 // append a special footer (Dev x.x.x) to the all Windows.
70 qApp->installEventFilter(&window_title_modifier);
71 #endif // MOZC_SHOW_BUILD_NUMBER_ON_TITLE
72 }
7173
72 TranslationDataImpl();
73 ~TranslationDataImpl() {
74 for (std::map<string, QTranslator *>::iterator it = translators_.begin();
75 it != translators_.end(); ++it) {
76 delete it->second;
77 }
78 translators_.clear();
79 }
80
81 private:
82 std::map<string, QTranslator *> translators_;
83 QTranslator default_translator_;
84 QFont font_;
85 #ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE
86 WindowTitleModifier window_title_modifier_;
87 #endif // MOZC_SHOW_BUILD_NUMBER_ON_TITLE
88 };
89
90 TranslationDataImpl::TranslationDataImpl() {
74 void InstallDefaultTranslator() {
9175 // qApplication must be loaded first
9276 CHECK(qApp);
93
94 #ifdef MOZC_SHOW_BUILD_NUMBER_ON_TITLE
95 // Install WindowTilteModifier for official dev channel
96 // append a special footer (Dev x.x.x) to the all Windows.
97 qApp->installEventFilter(&window_title_modifier_);
98 #endif // MOZC_SHOW_BUILD_NUMBER_ON_TITLE
77 static QTranslator translator;
9978
10079 // Load "<translation_path>/qt_<lang>.qm" from a qrc file.
101 bool loaded = default_translator_.load(
80 bool loaded = translator.load(
10281 QLocale::system(), "qt", "_",
10382 QLibraryInfo::location(QLibraryInfo::TranslationsPath), ".qm");
10483 if (!loaded) {
10584 // Load ":/qt_<lang>.qm" from a qrc file.
106 loaded =
107 default_translator_.load(QLocale::system(), "qt", "_", ":/", ".qm");
85 loaded = translator.load(QLocale::system(), "qt", "_", ":/", ".qm");
10886 }
10987
11088 if (loaded) {
111 qApp->installTranslator(&default_translator_);
89 qApp->installTranslator(&translator);
11290 }
11391 }
11492
115 void TranslationDataImpl::InstallTranslationMessageAndFont(
116 const char *resource_name) {
117 if (translators_.find(resource_name) != translators_.end()) {
93 void InstallTranslator(const char *resource_name) {
94 static std::map<string, std::unique_ptr<QTranslator>> translators;
95 if (translators.find(resource_name) != translators.end()) {
11896 return;
11997 }
120 QTranslator *translator = new QTranslator;
121 CHECK(translator);
122 translators_.insert(std::make_pair(resource_name, translator));
98 std::unique_ptr<QTranslator> translator(new QTranslator);
12399
124100 // Load ":/<resource_name>_<lang>.qm" from a qrc file.
125101 if (translator->load(QLocale::system(), resource_name, "_", ":/", ".qm")) {
126 qApp->installTranslator(translator);
102 qApp->installTranslator(translator.get());
103 translators.emplace(resource_name, std::move(translator));
127104 }
128105 }
129106
130107 } // namespace
131108
132109 void LocaleUtil::InstallTranslationMessageAndFont(const char *resource_name) {
133 Singleton<TranslationDataImpl>::get()->InstallTranslationMessageAndFont(
134 resource_name);
110 static bool called = false;
111 if (!called) {
112 called = true;
113 InstallEventFilter();
114 InstallDefaultTranslator();
115 }
116 InstallTranslator(resource_name);
135117 }
136118 } // namespace gui
137119 } // namespace mozc
7272 #include <string>
7373 #include <vector>
7474
75 #include "base/compiler_specific.h"
7675 #include "base/hash.h"
7776 #include "base/logging.h"
7877 #include "base/mmap.h"
129128 explicit ScopedIFEDictionary(IFEDictionary *dic) : dic_(dic) {}
130129
131130 ~ScopedIFEDictionary() {
132 if (dic_ != NULL) {
131 if (dic_ != nullptr) {
133132 dic_->Close();
134133 dic_->Release();
135134 }
153152 result_(E_FAIL),
154153 size_(0),
155154 index_(0) {
156 if (dic_.get() == NULL) {
157 LOG(ERROR) << "IFEDictionaryFactory returned NULL";
155 if (dic_.get() == nullptr) {
156 LOG(ERROR) << "IFEDictionaryFactory returned nullptr";
158157 return;
159158 }
160159
161160 // open user dictionary
162 HRESULT result = dic_->Open(NULL, NULL);
161 HRESULT result = dic_->Open(nullptr, nullptr);
163162 if (S_OK != result) {
164163 LOG(ERROR) << "Cannot open user dictionary: " << result_;
165164 return;
166165 }
167166
168 POSTBL *pos_table = NULL;
167 POSTBL *pos_table = nullptr;
169168 int pos_size = 0;
170169 result_ = dic_->GetPosTable(&pos_table, &pos_size);
171 if (S_OK != result_ || pos_table == NULL || pos_size == 0) {
170 if (S_OK != result_ || pos_table == nullptr || pos_size == 0) {
172171 LOG(ERROR) << "Cannot get POS table: " << result;
173172 result_ = E_FAIL;
174173 return;
186185 // Don't use auto-registered words, since Mozc may not be able to
187186 // handle auto_registered words correctly, and user is basically
188187 // unaware of auto-registered words.
189 result_ = dic_->GetWords(NULL, NULL, NULL, IFED_POS_ALL, IFED_SELECT_ALL,
190 IFED_REG_USER, // | FED_REG_AUTO
191 reinterpret_cast<UCHAR *>(&buf_[0]),
192 kBufferSize * sizeof(IMEWRD), &size_);
188 result_ =
189 dic_->GetWords(nullptr, nullptr, nullptr, IFED_POS_ALL, IFED_SELECT_ALL,
190 IFED_REG_USER, // | FED_REG_AUTO
191 reinterpret_cast<UCHAR *>(&buf_[0]),
192 kBufferSize * sizeof(IMEWRD), &size_);
193193 }
194194
195195 bool IsAvailable() const {
204204 return false;
205205 }
206206
207 if (entry == NULL) {
208 LOG(ERROR) << "Entry is NULL";
207 if (entry == nullptr) {
208 LOG(ERROR) << "Entry is nullptr";
209209 return false;
210210 }
211211 entry->Clear();
212212
213213 if (index_ < size_) {
214 if (buf_[index_].pwchReading == NULL ||
215 buf_[index_].pwchDisplay == NULL) {
214 if (buf_[index_].pwchReading == nullptr ||
215 buf_[index_].pwchDisplay == nullptr) {
216216 ++index_;
217 LOG(ERROR) << "pwchDisplay or pwchReading is NULL";
217 LOG(ERROR) << "pwchDisplay or pwchReading is nullptr";
218218 return true;
219219 }
220220
234234 entry->pos = it->second;
235235
236236 // set comment
237 if (buf_[index_].pvComment != NULL) {
237 if (buf_[index_].pvComment != nullptr) {
238238 if (buf_[index_].uct == IFED_UCT_STRING_SJIS) {
239239 EncodingUtil::SJISToUTF8(
240240 reinterpret_cast<const char *>(buf_[index_].pvComment),
127127
128128 UserDictionaryStorage::UserDictionary *dic =
129129 storage_->GetUserDictionary(dic_id);
130 if (dic == NULL) {
131 LOG(ERROR) << "GetUserDictionary returned NULL";
130 if (dic == nullptr) {
131 LOG(ERROR) << "GetUserDictionary returned nullptr";
132132 return false;
133133 }
134134
5959 mozc::ScopedHandle handle(
6060 ::CreateFileW(wfilename.c_str(), GENERIC_READ,
6161 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
62 NULL, OPEN_EXISTING, 0, NULL));
63 if (NULL == handle.get()) {
62 nullptr, OPEN_EXISTING, 0, nullptr));
63 if (nullptr == handle.get()) {
6464 LOG(ERROR) << "cannot open: " << lock_name << " " << ::GetLastError();
6565 return false;
6666 }
6767
68 const DWORD size = ::GetFileSize(handle.get(), NULL);
68 const DWORD size = ::GetFileSize(handle.get(), nullptr);
6969 if (-1 == static_cast<int>(size)) {
7070 LOG(ERROR) << "GetFileSize failed:" << ::GetLastError();
7171 return false;
8080 std::unique_ptr<char[]> buf(new char[size]);
8181
8282 DWORD read_size = 0;
83 if (!::ReadFile(handle.get(), buf.get(), size, &read_size, NULL)) {
83 if (!::ReadFile(handle.get(), buf.get(), size, &read_size, nullptr)) {
8484 LOG(ERROR) << "ReadFile failed: " << ::GetLastError();
8585 return false;
8686 }
3535
3636 QString TableUtil::SafeGetItemText(const QTableWidget *table_widget, int row,
3737 int column) {
38 if (table_widget == NULL) {
38 if (table_widget == nullptr) {
3939 return QString();
4040 }
41 // If |row| and/or |column| is out of range, we will get NULL anyway.
41 // If |row| and/or |column| is out of range, we will get nullptr anyway.
4242 const QTableWidgetItem *item = table_widget->item(row, column);
43 if (item == NULL) {
43 if (item == nullptr) {
4444 return QString();
4545 }
4646 return item->text();
5252 #ifdef __APPLE__
5353 app->setFont(QFont("Hiragino Sans"));
5454 #endif // __APPLE__
55
5556 return app;
5657 }
5758
6566 return name;
6667 }
6768
69 // static
70 void Util::ReplaceLabel(QLabel *label) {
71 label->setText(ReplaceString(label->text()));
72 }
73
74 // static
75 void Util::ReplaceTitle(QWidget *widget) {
76 widget->setWindowTitle(Util::ReplaceString(widget->windowTitle()));
77 }
78
79 // static
80 QString Util::ReplaceString(const QString &str) {
81 QString replaced(str);
82 return replaced.replace("[ProductName]", Util::ProductName());
83 }
84
6885 } // namespace gui
6986 } // namespace mozc
3131
3232 #include <QtCore/QString>
3333 #include <QtWidgets/QApplication>
34 #include <QtWidgets/QLabel>
3435 #include <memory>
3536
3637 namespace mozc {
4445 // Returns the product name.
4546 static const QString ProductName();
4647
48 // Replace placeholders in the label.
49 static void ReplaceLabel(QLabel *label);
50
51 // Replace placeholders in the widget.
52 static void ReplaceTitle(QWidget *widget);
53
54 // Replace placeholders in the string.
55 static QString ReplaceString(const QString &str);
56
4757 private:
4858 Util() = delete;
4959 virtual ~Util() = delete;
6565 hr = link.CoCreateInstance(CLSID_ShellLink);
6666 if (FAILED(hr)) {
6767 DLOG(INFO) << "Failed to instantiate CLSID_ShellLink. hr = " << hr;
68 return NULL;
68 return nullptr;
6969 }
7070
7171 {
7474 hr = link->SetPath(mozc_tool_path_wide.c_str());
7575 if (FAILED(hr)) {
7676 DLOG(ERROR) << "SetPath failed. hr = " << hr;
77 return NULL;
77 return nullptr;
7878 }
7979 }
8080
8484 hr = link->SetArguments(argument_wide.c_str());
8585 if (FAILED(hr)) {
8686 DLOG(ERROR) << "SetArguments failed. hr = " << hr;
87 return NULL;
87 return nullptr;
8888 }
8989 }
9090
9191 CComQIPtr<IPropertyStore> property_store(link);
92 if (property_store == NULL) {
92 if (property_store == nullptr) {
9393 DLOG(ERROR) << "QueryInterface failed.";
94 return NULL;
94 return nullptr;
9595 }
9696
9797 {
101101 hr = ::InitPropVariantFromString(item_title_wide.c_str(), &prop_variant);
102102 if (FAILED(hr)) {
103103 DLOG(ERROR) << "QueryInterface failed. hr = " << hr;
104 return NULL;
104 return nullptr;
105105 }
106106 hr = property_store->SetValue(PKEY_Title, prop_variant);
107107 ::PropVariantClear(&prop_variant);
109109
110110 if (FAILED(hr)) {
111111 DLOG(ERROR) << "SetValue failed. hr = " << hr;
112 return NULL;
112 return nullptr;
113113 }
114114
115115 hr = property_store->Commit();
116116 if (FAILED(hr)) {
117117 DLOG(ERROR) << "Commit failed. hr = " << hr;
118 return NULL;
118 return nullptr;
119119 }
120120
121121 return link;
160160 link =
161161 InitializeShellLinkItem(kLinks[i].argument, kLinks[i].title_english);
162162 }
163 if (link != NULL) {
163 if (link != nullptr) {
164164 object_collection->AddObject(link);
165165 }
166166 }
167167
168168 CComQIPtr<IObjectArray> object_array(object_collection);
169 if (object_array == NULL) {
169 if (object_array == nullptr) {
170170 DLOG(ERROR) << "QueryInterface failed.";
171171 return false;
172172 }
303303 wchar_t data[4] = {};
304304 ULONG num_chars = arraysize(data);
305305 result = key.QueryStringValue(kIMEHotKeyEntryValue, data, &num_chars);
306 // Returned |num_char| includes NULL character.
306 // Returned |num_char| includes nullptr character.
307307
308308 // This is only the condition when this function
309309 // can return |true|
362362 #ifdef OS_WIN
363363 HRESULT hr = S_OK;
364364
365 hr =
366 ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
365 hr = ::CoInitializeEx(nullptr,
366 COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
367367 if (FAILED(hr)) {
368368 DLOG(INFO) << "CoInitializeEx failed. hr = " << hr;
369369 return;
3939 namespace gui {
4040 bool WindowTitleModifier::eventFilter(QObject *obj, QEvent *event) {
4141 QWidget *w = QApplication::activeWindow();
42 if (w != NULL && obj != NULL && w == obj &&
43 QEvent::WindowActivate == event->type() &&
44 w->windowTitle().indexOf(prefix_) == -1) {
45 w->setWindowTitle(w->windowTitle() + prefix_ +
46 Version::GetMozcVersion().c_str() + suffix_);
42 if (w == nullptr || obj != w || event->type() != QEvent::WindowActivate) {
43 return QObject::eventFilter(obj, event);
44 }
45
46 const QString prefix = " (Dev ";
47 const QString& title = w->windowTitle();
48 // The window title can be empty, even if it is specified.
49 // See: https://doc.qt.io/qt-5/qmessagebox.html#setWindowTitle
50 if (!title.isEmpty() && title.indexOf(prefix) == -1) {
51 const QString version = prefix + Version::GetMozcVersion().c_str() + ")";
52 w->setWindowTitle(title + version);
4753 }
4854
4955 return QObject::eventFilter(obj, event);
5056 }
5157
52 WindowTitleModifier::WindowTitleModifier() : prefix_(" (Dev "), suffix_(")") {}
53
54 WindowTitleModifier::~WindowTitleModifier() {}
55
5658 } // namespace gui
5759 } // namespace mozc
3939 Q_OBJECT;
4040
4141 public:
42 WindowTitleModifier();
43 ~WindowTitleModifier();
42 WindowTitleModifier() = default;
43 ~WindowTitleModifier() override = default;
4444
4545 protected:
4646 bool eventFilter(QObject *obj, QEvent *event);
47
48 private:
49 const QString prefix_;
50 const QString suffix_;
5147 };
5248 } // namespace gui
5349 } // namespace mozc
4848 class CharacterFormEditor : public QTableWidget {
4949 Q_OBJECT
5050 public:
51 explicit CharacterFormEditor(QWidget *parent = NULL);
51 explicit CharacterFormEditor(QWidget *parent = nullptr);
5252 virtual ~CharacterFormEditor();
5353
5454 void Load(const config::Config &config);
5858 const QModelIndex &index) const {
5959 QString str = index.model()->data(index, Qt::EditRole).toString();
6060 QComboBox *comboBox = static_cast<QComboBox *>(editor);
61 if (comboBox == NULL) {
61 if (comboBox == nullptr) {
6262 return;
6363 }
6464 comboBox->setCurrentIndex(comboBox->findText(str));
6767 void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
6868 const QModelIndex &index) const {
6969 QComboBox *comboBox = static_cast<QComboBox *>(editor);
70 if (comboBox == NULL || model == NULL) {
70 if (comboBox == nullptr || model == nullptr) {
7171 return;
7272 }
7373 model->setData(index, comboBox->currentText(), Qt::EditRole);
7676 void ComboBoxDelegate::updateEditorGeometry(QWidget *editor,
7777 const QStyleOptionViewItem &option,
7878 const QModelIndex &index) const {
79 if (editor == NULL) {
79 if (editor == nullptr) {
8080 return;
8181 }
8282 editor->setGeometry(option.rect);
4343 class ComboBoxDelegate : public QItemDelegate {
4444 Q_OBJECT
4545 public:
46 explicit ComboBoxDelegate(QObject *parent = NULL);
46 explicit ComboBoxDelegate(QObject *parent = nullptr);
4747 virtual ~ComboBoxDelegate();
4848
4949 void SetItemList(const QStringList &item_list);
753753 keymap::KeyMapManager::GetKeyMapFileName(itr->second);
754754 std::unique_ptr<std::istream> ifs(
755755 ConfigFileStream::LegacyOpen(keymap_file));
756 CHECK(ifs.get() != NULL); // should never happen
756 CHECK(ifs.get() != nullptr); // should never happen
757757 std::stringstream buffer;
758758 buffer << ifs->rdbuf();
759759 current_keymap_table = buffer.str();
152152
153153 // Choose next or prev item.
154154 QTableWidgetItem *item = editorTableWidget->item(rows.back() + 1, column);
155 if (item == NULL) {
155 if (item == nullptr) {
156156 item = editorTableWidget->item(rows.back() - 1, column);
157157 }
158158
159159 // select item
160 if (item != NULL) {
160 if (item != nullptr) {
161161 editorTableWidget->setCurrentItem(item);
162162 }
163163
187187 editorTableWidget->setItem(row, i, new QTableWidgetItem(""));
188188 }
189189 QTableWidgetItem *item = editorTableWidget->item(row, 0);
190 if (item != NULL) {
190 if (item != nullptr) {
191191 editorTableWidget->setCurrentItem(item);
192192 editorTableWidget->scrollToItem(item, QAbstractItemView::PositionAtCenter);
193193 editorTableWidget->editItem(item);
208208
209209 void GenericTableEditorDialog::InsertItem() {
210210 QTableWidgetItem *current = editorTableWidget->currentItem();
211 if (current == NULL) {
211 if (current == nullptr) {
212212 QMessageBox::warning(this, windowTitle(), tr("No entry is selected"));
213213 return;
214214 }
296296
297297 void GenericTableEditorDialog::OnContextMenuRequested(const QPoint &pos) {
298298 QTableWidgetItem *item = editorTableWidget->itemAt(pos);
299 if (item == NULL) {
299 if (item == nullptr) {
300300 return;
301301 }
302302
303303 QMenu *menu = new QMenu(this);
304 QAction *edit_action = NULL;
304 QAction *edit_action = nullptr;
305305 const QList<QTableWidgetItem *> selected_items =
306306 editorTableWidget->selectedItems();
307307 if (selected_items.count() == 1) {
311311 QAction *delete_action = menu->addAction(tr("Remove entry"));
312312 QAction *selected_action = menu->exec(QCursor::pos());
313313
314 if (edit_action != NULL && selected_action == edit_action) {
314 if (edit_action != nullptr && selected_action == edit_action) {
315315 editorTableWidget->editItem(selected_items[0]);
316316 } else if (selected_action == rename_action) {
317317 AddNewItem();
322322
323323 void GenericTableEditorDialog::UpdateOKButton(bool status) {
324324 QPushButton *button = editorButtonBox->button(QDialogButtonBox::Ok);
325 if (button != NULL) {
325 if (button != nullptr) {
326326 button->setEnabled(status);
327327 }
328328 }
487487
488488 QPushButton *ok_button =
489489 KeyBindingEditorbuttonBox->button(QDialogButtonBox::Ok);
490 CHECK(ok_button != NULL);
490 CHECK(ok_button != nullptr);
491491
492492 filter_.reset(new KeyBindingFilter(KeyBindingLineEdit, ok_button));
493493 KeyBindingLineEdit->installEventFilter(filter_.get());
7777 const QString str = index.model()->data(index, Qt::EditRole).toString();
7878 KeyBindingEditorTriggerButton *button =
7979 static_cast<KeyBindingEditorTriggerButton *>(editor);
80 if (button == NULL) {
80 if (button == nullptr) {
8181 return;
8282 }
8383 button->setText(str);
8989 const QModelIndex &index) const {
9090 KeyBindingEditorTriggerButton *button =
9191 static_cast<KeyBindingEditorTriggerButton *>(editor);
92 if (model == NULL || button == NULL) {
92 if (model == nullptr || button == nullptr) {
9393 return;
9494 }
9595 model->setData(index, button->mutable_editor()->GetBinding(), Qt::EditRole);
9898 void KeyBindingEditorDelegate::updateEditorGeometry(
9999 QWidget *editor, const QStyleOptionViewItem &option,
100100 const QModelIndex &index) const {
101 if (editor == NULL) {
101 if (editor == nullptr) {
102102 return;
103103 }
104104 editor->setGeometry(option.rect);
109109 KeyBindingEditorTriggerButton *button =
110110 static_cast<KeyBindingEditorTriggerButton *>(
111111 editor->mutable_trigger_parent());
112 if (button == NULL) {
112 if (button == nullptr) {
113113 return;
114114 }
115115 emit commitData(button);
121121 KeyBindingEditorTriggerButton *button =
122122 static_cast<KeyBindingEditorTriggerButton *>(
123123 editor->mutable_trigger_parent());
124 if (button == NULL) {
124 if (button == nullptr) {
125125 return;
126126 }
127127 emit closeEditor(button);
4141 class KeyBindingEditorDelegate : public QItemDelegate {
4242 Q_OBJECT
4343 public:
44 explicit KeyBindingEditorDelegate(QObject *parent = NULL);
44 explicit KeyBindingEditorDelegate(QObject *parent = nullptr);
4545 virtual ~KeyBindingEditorDelegate();
4646
4747 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
317317 KeyMapEditorDialog::~KeyMapEditorDialog() {}
318318
319319 bool KeyMapEditorDialog::LoadFromStream(std::istream *is) {
320 if (is == NULL) {
320 if (is == nullptr) {
321321 return false;
322322 }
323323
498498 keymap::KeyMapManager::GetKeyMapFileName(kKeyMaps[import_index]);
499499 std::unique_ptr<std::istream> ifs(
500500 ConfigFileStream::LegacyOpen(keymap_file));
501 CHECK(ifs.get() != NULL); // should never happen
501 CHECK(ifs.get() != nullptr); // should never happen
502502 CHECK(LoadFromStream(ifs.get()));
503503 }
504504 } else if (action == actions_[EXPORT_TO_FILE_INDEX]) {
9090 std::string RomanTableEditorDialog::GetDefaultRomanTable() {
9191 std::unique_ptr<std::istream> ifs(
9292 ConfigFileStream::LegacyOpen(kRomanTableFile));
93 CHECK(ifs.get() != NULL); // should never happen
93 CHECK(ifs.get() != nullptr); // should never happen
9494 std::string line, result;
9595 std::vector<std::string> fields;
9696 while (getline(*ifs.get(), line)) {
170170 bool RomanTableEditorDialog::LoadDefaultRomanTable() {
171171 std::unique_ptr<std::istream> ifs(
172172 ConfigFileStream::LegacyOpen(kRomanTableFile));
173 CHECK(ifs.get() != NULL); // should never happen
173 CHECK(ifs.get() != nullptr); // should never happen
174174 CHECK(LoadFromStream(ifs.get()));
175175 return true;
176176 }
4848 // Message
4949 QObject::tr("Invalid confirmation dialog. "
5050 "You specified less arguments."),
51 QMessageBox::Yes | QMessageBox::No, NULL,
51 QMessageBox::Yes | QMessageBox::No, nullptr,
5252 Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
5353
5454 if (FLAGS_confirmation_type == "update") {
5858 "(Note: some features will not be available "
5959 "until you log out and log back in.)"));
6060 QAbstractButton *yes_button = message_box.button(QMessageBox::Yes);
61 if (yes_button != NULL) {
61 if (yes_button != nullptr) {
6262 yes_button->setText(QObject::tr("Activate now"));
6363 }
6464 QAbstractButton *no_button = message_box.button(QMessageBox::No);
65 if (no_button != NULL) {
65 if (no_button != nullptr) {
6666 no_button->setText(QObject::tr("Wait until logout"));
6767 }
6868 } else if (FLAGS_confirmation_type == "log_out") {
7070 QObject::tr("Mozc has been updated. "
7171 "Please log out and back in to enable the new version."));
7272 QAbstractButton *yes_button = message_box.button(QMessageBox::Yes);
73 if (yes_button != NULL) {
73 if (yes_button != nullptr) {
7474 yes_button->setText(QObject::tr("Log out"));
7575 }
7676 QAbstractButton *no_button = message_box.button(QMessageBox::No);
77 if (no_button != NULL) {
77 if (no_button != nullptr) {
7878 no_button->setText(QObject::tr("Remind me in 1 hour"));
7979 }
8080 }
5252 alternate_index = 1;
5353 } else {
5454 QTableWidgetItem *last_item = item(rowCount() - 1, 0);
55 if (last_item == NULL) {
55 if (last_item == nullptr) {
5656 return;
5757 }
5858 rect = visualItemRect(last_item);
7777
7878 // When empty area is double-clicked, emit a signal
7979 #ifdef __APPLE__
80 if (NULL == itemAt(event->pos())) {
80 if (nullptr == itemAt(event->pos())) {
8181 emit emptyAreaClicked();
8282 }
8383 #endif // __APPLE__
6363 #include "dictionary/user_dictionary_util.h"
6464 #include "gui/base/encoding_util.h"
6565 #include "gui/base/msime_user_dictionary_importer.h"
66 #include "gui/base/util.h"
6667 #include "gui/config_dialog/combobox_delegate.h"
6768 #include "gui/dictionary_tool/find_dialog.h"
6869 #include "gui/dictionary_tool/import_dialog.h"
231232
232233 // strip UTF8 BOM
233234 if (first_line_ && encoding_type_ == UserDictionaryImporter::UTF8) {
234 Util::StripUTF8BOM(line);
235 }
236
237 Util::ChopReturns(line);
235 mozc::Util::StripUTF8BOM(line);
236 }
237
238 mozc::Util::ChopReturns(line);
238239
239240 first_line_ = false;
240241 return true;
286287 parent);
287288 break;
288289 default:
289 return NULL;
290 }
291
292 return NULL;
290 return nullptr;
291 }
292
293 return nullptr;
293294 }
294295 } // namespace
295296
296297 DictionaryTool::DictionaryTool(QWidget *parent)
297298 : QMainWindow(parent),
298 import_dialog_(NULL),
299 find_dialog_(NULL),
299 import_dialog_(nullptr),
300 find_dialog_(nullptr),
300301 session_(new UserDictionarySession(
301302 UserDictionaryUtil::GetUserDictionaryFileName())),
302303 current_dic_id_(0),
303304 modified_(false),
304305 monitoring_user_edit_(false),
305 window_title_(tr("Mozc")),
306 window_title_(gui::Util::ProductName()),
306307 dic_menu_(new QMenu),
307 new_action_(NULL),
308 rename_action_(NULL),
309 delete_action_(NULL),
310 find_action_(NULL),
311 import_create_action_(NULL),
312 import_append_action_(NULL),
313 export_action_(NULL),
314 import_default_ime_action_(NULL),
308 new_action_(nullptr),
309 rename_action_(nullptr),
310 delete_action_(nullptr),
311 find_action_(nullptr),
312 import_create_action_(nullptr),
313 import_append_action_(nullptr),
314 export_action_(nullptr),
315 import_default_ime_action_(nullptr),
315316 client_(client::ClientFactory::NewClient()),
316317 is_available_(true),
317318 max_entry_size_(mozc::UserDictionaryStorage::max_entry_size()),
580581 SyncToStorage();
581582
582583 DictionaryInfo dic_info = current_dictionary();
583 if (dic_info.item == NULL) {
584 if (dic_info.item == nullptr) {
584585 current_dic_id_ = 0;
585586 StopMonitoringUserEdit();
586587 dic_content_->clearContents();
604605 UserDictionary *dic =
605606 session_->mutable_storage()->GetUserDictionary(dic_info.id);
606607
607 if (dic == NULL) {
608 if (dic == nullptr) {
608609 LOG(ERROR) << "Failed to load the dictionary: " << dic_info.id;
609610 ReportError();
610611 return;
680681
681682 void DictionaryTool::DeleteDictionary() {
682683 DictionaryInfo dic_info = current_dictionary();
683 if (dic_info.item == NULL) {
684 if (dic_info.item == nullptr) {
684685 QMessageBox::information(this, window_title_,
685686 tr("No dictionary is selected."));
686687 return;
709710
710711 void DictionaryTool::RenameDictionary() {
711712 DictionaryInfo dic_info = current_dictionary();
712 if (dic_info.item == NULL) {
713 if (dic_info.item == nullptr) {
713714 QMessageBox::information(this, window_title_,
714715 tr("No dictionary is selected."));
715716 return;
757758
758759 void DictionaryTool::ImportAndAppendDictionary() {
759760 DictionaryInfo dic_info = current_dictionary();
760 if (dic_info.item == NULL) {
761 if (dic_info.item == nullptr) {
761762 LOG(WARNING) << "No dictionary to import is selected";
762763 QMessageBox::information(this, window_title_,
763764 tr("No dictionary is selected."));
798799 "unsupported file format.\n\n"
799800 "Please check the file format. "
800801 "ATOK11 or older format is not supported by "
801 "Mozc."));
802 "%1.").arg(gui::Util::ProductName()));
802803 break;
803804 case UserDictionaryImporter::IMPORT_TOO_MANY_WORDS:
804805 QMessageBox::information(
848849
849850 UserDictionary *dic = session_->mutable_storage()->GetUserDictionary(dic_id);
850851
851 if (dic == NULL) {
852 if (dic == nullptr) {
852853 LOG(ERROR) << "Cannot find dictionary id: " << dic_id;
853854 ReportError();
854855 return;
866867 // Open dictionary
867868 std::unique_ptr<UserDictionaryImporter::TextLineIteratorInterface> iter(
868869 CreateTextLineIterator(encoding_type, file_name, this));
869 if (iter.get() == NULL) {
870 LOG(ERROR) << "CreateTextLineIterator returns NULL";
870 if (iter == nullptr) {
871 LOG(ERROR) << "CreateTextLineIterator returns nullptr";
871872 return;
872873 }
873874
905906 }
906907
907908 DictionaryInfo dic_info = current_dictionary();
908 if (dic_info.item == NULL) {
909 if (dic_info.item == nullptr) {
909910 LOG(WARNING) << "No dictionary to import is selected";
910911 QMessageBox::information(this, window_title_,
911912 tr("No dictionary is selected."));
954955
955956 void DictionaryTool::ExportDictionary() {
956957 DictionaryInfo dic_info = current_dictionary();
957 if (dic_info.item == NULL) {
958 if (dic_info.item == nullptr) {
958959 LOG(WARNING) << "No dictionary to export is selected";
959960 QMessageBox::information(this, window_title_,
960961 tr("No dictionary is selected."));
10391040 QList<QListWidgetItem *> selected_dicts = dic_list_->selectedItems();
10401041 if (selected_dicts.isEmpty()) {
10411042 LOG(WARNING) << "No current dictionary.";
1042 return NULL;
1043 return nullptr;
10431044 }
10441045 if (selected_dicts.size() > 1) {
10451046 LOG(WARNING) << "Multiple items are selected.";
11101111 }
11111112
11121113 void DictionaryTool::MoveTo(int dictionary_row) {
1113 UserDictionary *target_dict = NULL;
1114 UserDictionary *target_dict = nullptr;
11141115 {
11151116 const QListWidgetItem *selected_dict = GetFirstSelectedDictionary();
1116 if (selected_dict == NULL) {
1117 if (selected_dict == nullptr) {
11171118 return;
11181119 }
11191120 QListWidgetItem *target_dict_item = dic_list_->item(dictionary_row);
12491250 QTableWidgetItem *item = dic_content_->itemAt(pos);
12501251 // When the mouse pointer is not on an item of the table widget, we
12511252 // don't show context menu.
1252 if (item == NULL) {
1253 if (item == nullptr) {
12531254 return;
12541255 }
12551256
12791280 change_dictionary_actions.reserve(dic_list_->count() - 1);
12801281 {
12811282 const QListWidgetItem *selected_dict = GetFirstSelectedDictionary();
1282 if (selected_dict != NULL) {
1283 if (selected_dict != nullptr) {
12831284 for (size_t i = 0; i < dic_list_->count(); ++i) {
12841285 QListWidgetItem *item = dic_list_->item(i);
12851286 DCHECK(item);
13371338
13381339 void DictionaryTool::OnContextMenuRequestedForList(const QPoint &pos) {
13391340 QListWidgetItem *item = dic_list_->itemAt(pos);
1340 if (item == NULL) {
1341 if (item == nullptr) {
13411342 return;
13421343 }
13431344
13491350 QAction *export_action = menu->addAction(tr("Export this dictionary..."));
13501351 QAction *selected_action = menu->exec(QCursor::pos());
13511352
1352 if ((rename_action != NULL) && (selected_action == rename_action)) {
1353 if ((rename_action != nullptr) && (selected_action == rename_action)) {
13531354 RenameDictionary();
1354 } else if ((delete_action != NULL) && (selected_action == delete_action)) {
1355 } else if ((delete_action != nullptr) && (selected_action == delete_action)) {
13551356 DeleteDictionary();
1356 } else if ((import_action != NULL) && (selected_action == import_action)) {
1357 } else if ((import_action != nullptr) && (selected_action == import_action)) {
13571358 ImportAndAppendDictionary();
1358 } else if ((export_action != NULL) && (selected_action == export_action)) {
1359 } else if ((export_action != nullptr) && (selected_action == export_action)) {
13591360 ExportDictionary();
13601361 }
13611362 }
13621363
13631364 DictionaryTool::DictionaryInfo DictionaryTool::current_dictionary() const {
1364 DictionaryInfo retval = {-1, 0, NULL};
1365 DictionaryInfo retval = {-1, 0, nullptr};
13651366
13661367 QListWidgetItem *selected_dict = GetFirstSelectedDictionary();
1367 if (selected_dict == NULL) {
1368 if (selected_dict == nullptr) {
13681369 return retval;
13691370 }
13701371
13821383 UserDictionary *dic =
13831384 session_->mutable_storage()->GetUserDictionary(current_dic_id_);
13841385
1385 if (dic == NULL) {
1386 if (dic == nullptr) {
13861387 LOG(ERROR) << "No save dictionary: " << current_dic_id_;
13871388 return;
13881389 }
15741575 delete_word_button_->setEnabled(dic_content_->rowCount() > 0);
15751576
15761577 const DictionaryInfo dic_info = current_dictionary();
1577 if (dic_info.item != NULL) {
1578 if (dic_info.item != nullptr) {
15781579 statusbar_message_ = QString(tr("%1: %2 entries"))
15791580 .arg(dic_info.item->text())
15801581 .arg(dic_content_->rowCount());
175175 void GetSortedSelectedRows(std::vector<int> *rows) const;
176176
177177 // Returns a pointer to the first selected dictionary.
178 // Returns NULL if no dictionary is selected.
178 // Returns nullptr if no dictionary is selected.
179179 QListWidgetItem *GetFirstSelectedDictionary() const;
180180
181181 ImportDialog *import_dialog_;
285285 <location filename="dictionary_tool.cc" line="786"/>
286286 <source>You have imported a file in an invalid or unsupported file format.
287287
288 Please check the file format. ATOK11 or older format is not supported by Mozc.</source>
288 Please check the file format. ATOK11 or older format is not supported by %1.</source>
289289 <translation></translation>
290290 </message>
291291 <message>
198198 <location filename="dictionary_tool.cc" line="786"/>
199199 <source>You have imported a file in an invalid or unsupported file format.
200200
201 Please check the file format. ATOK11 or older format is not supported by Mozc.</source>
202 <translation>指定されたファイルは Mozcでサポートされていないフォーマットで保存されています。
201 Please check the file format. ATOK11 or older format is not supported by %1.</source>
202 <translation>指定されたファイルは %1 でサポートされていないフォーマットで保存されています。
203203
204204 インポート対象のファイルフォーマットを確認してください。
205205
4444 FindDialog::FindDialog(QWidget *parent, QTableWidget *table)
4545 : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
4646 table_(table),
47 last_item_(NULL) {
47 last_item_(nullptr) {
4848 setupUi(this);
4949 setModal(false);
5050
6666 QuerylineEdit->selectAll();
6767 }
6868 FindForwardpushButton->setDefault(true);
69 last_item_ = NULL;
69 last_item_ = nullptr;
7070 UpdateUIStatus();
7171 }
7272
7373 void FindDialog::closeEvent(QCloseEvent *event) {
7474 table_->setStyleSheet("");
75 last_item_ = NULL;
75 last_item_ = nullptr;
7676 }
7777
7878 void FindDialog::UpdateUIStatus() {
8282 }
8383
8484 bool FindDialog::Match(const QString &query, int row, int column) {
85 if (last_item_ != NULL && last_item_ == table_->item(row, column)) {
85 if (last_item_ != nullptr && last_item_ == table_->item(row, column)) {
8686 return false;
8787 }
8888 const QString &value = table_->item(row, column)->text();
145145 table_->setCurrentItem(item);
146146 table_->scrollToItem(item);
147147 } else {
148 last_item_ = NULL;
148 last_item_ = nullptr;
149149 QMessageBox::information(this, this->windowTitle(),
150150 tr("Cannot find pattern %1").arg(query));
151151 }
8282 static_cast<int>(UserDictionaryImporter::UTF8));
8383
8484 QPushButton *button = buttonbox_->button(QDialogButtonBox::Ok);
85 if (button != NULL) {
85 if (button != nullptr) {
8686 button->setText(tr("Import"));
8787 }
8888
141141
142142 void ImportDialog::OnFormValueChanged() {
143143 QPushButton *button = buttonbox_->button(QDialogButtonBox::Ok);
144 if (button != NULL) {
144 if (button != nullptr) {
145145 button->setEnabled(IsAcceptButtonEnabled());
146146 }
147147 }
4646 // to set WindowStaysOnTopHint
4747 QMessageBox message_box(
4848 QMessageBox::Critical, QObject::tr("Mozc Fatal Error"),
49 message, QMessageBox::Ok, NULL,
49 message, QMessageBox::Ok, nullptr,
5050 Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
5151 DeleyedMessageDialogHandler handler(&message_box);
5252 handler.Exec();
6363 const int kDisableInterval = 3000;
6464 QTimer::singleShot(kDisableInterval, this, SLOT(EnableOkButton()));
6565 QAbstractButton *button = message_box_->button(QMessageBox::Ok);
66 if (button != NULL) {
66 if (button != nullptr) {
6767 button->setEnabled(false);
6868 }
6969 message_box_->exec();
7171
7272 void DeleyedMessageDialogHandler::EnableOkButton() {
7373 QAbstractButton *button = message_box_->button(QMessageBox::Ok);
74 if (button != NULL) {
74 if (button != nullptr) {
7575 button->setEnabled(true);
7676 }
7777 }
8888 cc_qt_binary_mozc(
8989 name = "mozc_tool",
9090 srcs = ["mozc_tool_main.cc"],
91 visibility = ["//:__pkg__"],
9192 deps = [
9293 ":mozc_tool_lib",
9394 "//base:init_mozc",
7575 #if defined(OS_WIN)
7676 std::wstring wenvname;
7777 mozc::Util::UTF8ToWide(envname, &wenvname);
78 const DWORD buffer_size = ::GetEnvironmentVariable(wenvname.c_str(), NULL, 0);
78 const DWORD buffer_size =
79 ::GetEnvironmentVariable(wenvname.c_str(), nullptr, 0);
7980 if (buffer_size == 0) {
8081 return "";
8182 }
225226
226227 QAbstractButton *button =
227228 WordRegisterDialogbuttonBox->button(QDialogButtonBox::Ok);
228 if (button != NULL) {
229 if (button != nullptr) {
229230 button->setEnabled(enabled);
230231 }
231232 }
406407
407408 // Get default value from Clipboard
408409 void WordRegisterDialog::SetDefaultEntryFromClipboard() {
409 if (QApplication::clipboard() == NULL) {
410 if (QApplication::clipboard() == nullptr) {
410411 return;
411412 }
412413 CopyCurrentSelectionToClipboard();
418419 void WordRegisterDialog::CopyCurrentSelectionToClipboard() {
419420 #ifdef OS_WIN
420421 const HWND foreground_window = ::GetForegroundWindow();
421 if (foreground_window == NULL) {
422 if (foreground_window == nullptr) {
422423 LOG(ERROR) << "GetForegroundWindow() failed: " << ::GetLastError();
423424 return;
424425 }
425426
426 const DWORD thread_id = ::GetWindowThreadProcessId(foreground_window, NULL);
427 const DWORD thread_id =
428 ::GetWindowThreadProcessId(foreground_window, nullptr);
427429
428430 if (!::AttachThreadInput(::GetCurrentThreadId(), thread_id, TRUE)) {
429431 LOG(ERROR) << "AttachThreadInput failed: " << ::GetLastError();
434436
435437 ::AttachThreadInput(::GetCurrentThreadId(), thread_id, FALSE);
436438
437 if (focus_window == NULL || !::IsWindow(focus_window)) {
439 if (focus_window == nullptr || !::IsWindow(focus_window)) {
438440 LOG(WARNING) << "No focus window";
439441 return;
440442 }
477479 #ifdef OS_WIN
478480 // TODO(taku): implement it for other platform.
479481 HIMC himc = ::ImmGetContext(reinterpret_cast<HWND>(winId()));
480 if (himc != NULL) {
482 if (himc != nullptr) {
481483 ::ImmSetOpenStatus(himc, TRUE);
482484 }
483485 #endif // OS_WIN
4545 'compiler_host_version_int%': '0', # (major_ver) * 100 + (minor_ver)
4646
4747 # Versioning stuff for Mac.
48 'mac_sdk%': '10.14',
48 'mac_sdk%': '10.15',
4949 'mac_deployment_target%': '10.9',
5050
5151 # Flag to specify if the build target is for simulator or not.
5353 'compiler_host': 'msvs',
5454 'compiler_host_version_int': 1900, # Visual C++ 2015 or higher
5555 }],
56 ['MSVS_VERSION=="2017"', {
57 'compiler_target': 'msvs',
58 'compiler_target_version_int': 1910, # Visual C++ 2017 or higher
59 'compiler_host': 'msvs',
60 'compiler_host_version_int': 1910, # Visual C++ 2017 or higher
61 }],
5662 ],
5763 'msvc_disabled_warnings': [
5864 # 'expression' : signed/unsigned mismatch
3939
4040 #endif // GOOGLE_JAPANESE_INPUT_BUILD
4141
42 #include "base/compiler_specific.h"
4342 #include "base/logging.h"
4443 #include "base/port.h"
4544 #include "base/singleton.h"
2828
2929 #include "net/json_util.h"
3030
31 #include <limits>
3132 #include <string>
3233 #include <vector>
3334
246247 EXPECT_PROTO_EQ(msg, new_msg);
247248 }
248249
249 TEST(JsonUtilTest, ConvertItemTest){
250 TEST(JsonUtilTest, ConvertItemTest) {
250251 #define TEST_CONVERT_ITEM(proto_setter, proto_value, json_name, json_value) \
251252 { \
252253 TestMsg msg; \
262263 FillRequiredFields(&msg); \
263264 EXPECT_PROTO_EQ(msg, new_msg); \
264265 }
265 TEST_CONVERT_ITEM(
266 set_double_value,
267 1.0, "double_value", 1.0) TEST_CONVERT_ITEM(set_float_value, 2.0,
268 "float_value", 2.0) TEST_CONVERT_ITEM(set_int32_value,
269 3,
270 "int32_value", Json::Int(3)) TEST_CONVERT_ITEM(set_int32_value,
271 -3,
272 "int32_value", Json::Int(-3)) TEST_CONVERT_ITEM(set_int32_value,
273 kint32min,
274 "int32_value", Json::Int(kint32min)) TEST_CONVERT_ITEM(set_int32_value,
275 kint32max,
276 "int32_value",
277 Json::Int(
278 kint32max)) TEST_CONVERT_ITEM(set_int64_value,
279 4,
280 "int64_value",
281 "4") TEST_CONVERT_ITEM(set_int64_value,
282 -4,
283 "int64_value",
284 "-4") TEST_CONVERT_ITEM(set_int64_value,
285 kint64min,
286 "int64_value",
287 "-9223372036854775808") TEST_CONVERT_ITEM(set_int64_value,
288 kint64max,
289 "int64_value",
290 "9223372036854775807") TEST_CONVERT_ITEM(set_uint32_value,
291 5,
292 "uint32_value",
293 Json::UInt(
294 5)) TEST_CONVERT_ITEM(set_uint32_value,
295 kuint32max,
296 "uint32_value",
297 Json::
298 UInt(
299 kuint32max)) TEST_CONVERT_ITEM(set_uint64_value,
300 6,
301 "uint64_value",
302 "6") TEST_CONVERT_ITEM(set_uint64_value,
303 kuint64max,
304 "uint64_value",
305 "18446744073709551615") TEST_CONVERT_ITEM(set_sint32_value,
306 7,
307 "sint32_value",
308 Json::Int(7)) TEST_CONVERT_ITEM(set_sint32_value,
309 -7,
310 "sint32_value", Json::Int(-7)) TEST_CONVERT_ITEM(set_sint32_value,
311 kint32min,
312 "sint32_value",
313 Json::Int(
314 kint32min)) TEST_CONVERT_ITEM(set_sint32_value,
315 kint32max,
316 "sint32_value",
317 Json::
318 Int(kint32max)) TEST_CONVERT_ITEM(set_sint64_value,
319 8,
320 "sint64_value",
321 "8") TEST_CONVERT_ITEM(set_sint64_value,
322 -8,
323 "sint64_value",
324 "-8") TEST_CONVERT_ITEM(set_sint64_value,
325 kint64min,
326 "sint64_value",
327 "-9223372036854775808") TEST_CONVERT_ITEM(set_sint64_value,
328 kint64max,
329 "sint64_value",
330 "9223372036854775807") TEST_CONVERT_ITEM(set_fixed32_value,
331 9,
332 "fixed32_value", Json::UInt(9)) TEST_CONVERT_ITEM(set_fixed32_value,
333 kuint32max,
334 "fixed32_value",
335 Json::
336 UInt(kuint32max)) TEST_CONVERT_ITEM(set_fixed64_value,
337 10,
338 "fixed64_value",
339 "10") TEST_CONVERT_ITEM(set_fixed64_value,
340 kuint64max,
341 "fixed64_value",
342 "18446744073709551615") TEST_CONVERT_ITEM(set_sfixed32_value,
343 11,
344 "sfixed32_value",
345 Json::Int(
346 11)) TEST_CONVERT_ITEM(set_sfixed32_value,
347 -11,
348 "sfixed32_value",
349 Json::
350 Int(-11)) TEST_CONVERT_ITEM(set_sfixed32_value,
351 kint32min,
352 "sfixed32_value",
353 Json::
354 Int(kint32min)) TEST_CONVERT_ITEM(set_sfixed32_value,
355 kint32max,
356 "sfixed32_value",
357 Json::Int(kint32max)) TEST_CONVERT_ITEM(set_sfixed64_value,
358 12,
359 "sfixed64_value",
360 "12") TEST_CONVERT_ITEM(set_sfixed64_value,
361 -12,
362 "sfixed64_value",
363 "-12") TEST_CONVERT_ITEM(set_sfixed64_value,
364 kint64min,
365 "sfixed64_value",
366 "-9223372036854775808") TEST_CONVERT_ITEM(set_sfixed64_value,
367 kint64max,
368 "sfixed64_value",
369 "9223372036854775807") TEST_CONVERT_ITEM(set_bool_value,
370 true,
371 "bool_value",
372 true) TEST_CONVERT_ITEM(set_bool_value,
373 false,
374 "bool_value", false) TEST_CONVERT_ITEM(set_string_value,
375 "string",
376 "string_value",
377 "string") TEST_CONVERT_ITEM(set_bytes_value,
378 "bytes",
379 "bytes_value",
380 "bytes") TEST_CONVERT_ITEM(set_enum_value,
381 ENUM_A,
382 "enum_value",
383 "ENUM_A") TEST_CONVERT_ITEM(set_innerenum_value, TestMsg::ENUM_1,
384 "innerenum_value",
385 "ENUM_1")
386
387 TEST_CONVERT_ITEM(set_required_double_value,
388 1.0, "required_double_value", 1.0) TEST_CONVERT_ITEM(set_required_float_value,
389 2.0,
390 "required_float_value",
391 2.0)
392 TEST_CONVERT_ITEM(set_required_int32_value,
393 3, "required_int32_value", Json::Int(3)) TEST_CONVERT_ITEM(set_required_int32_value,
394 -3,
395 "required_int32_value",
396 Json::Int(
397 -3))
398 TEST_CONVERT_ITEM(
399 set_required_int32_value,
400 kint32min, "required_int32_value", Json::Int(kint32min))
401 TEST_CONVERT_ITEM(
402 set_required_int32_value,
403 kint32max, "required_int32_value", Json::Int(kint32max))
404 TEST_CONVERT_ITEM(
405 set_required_int64_value,
406 4, "required_int64_value",
407 "4") TEST_CONVERT_ITEM(set_required_int64_value, -4,
408 "required_int64_value",
409 "-4")
410 TEST_CONVERT_ITEM(
411 set_required_int64_value,
412 kint64min,
413 "required_int64_value",
414 "-9223372036854775808")
415 TEST_CONVERT_ITEM(
416 set_required_int64_value,
417 kint64max,
418 "required_int64_value",
419 "9223372036854775807")
420 TEST_CONVERT_ITEM(set_required_uint32_value,
421 5, "required_uint32_value",
422 Json::
423 UInt(5)) TEST_CONVERT_ITEM(set_required_uint32_value,
424 kuint32max,
425 "required_uint32_value",
426 Json::
427 UInt(
428 kuint32max))
429 TEST_CONVERT_ITEM(
430 set_required_uint64_value,
431 6, "required_uint64_value",
432 "6") TEST_CONVERT_ITEM(set_required_uint64_value,
433 kuint64max,
434 "required_"
435 "uint64_"
436 "value",
437 "18446744073"
438 "709551615")
439 TEST_CONVERT_ITEM(
440 set_required_sint32_value, 7,
441 "required_sint32_value",
442 Json::Int(7))
443 TEST_CONVERT_ITEM(set_required_sint32_value,
444 -7,
445 "required_"
446 "sint32_"
447 "value",
448 Json::Int(-7))
449 TEST_CONVERT_ITEM(set_required_sint32_value,
450 kint32min,
451 "required"
452 "_sint32_"
453 "value",
454 Json::Int(
455 kint32min))
456 TEST_CONVERT_ITEM(
457 set_required_sint32_value,
458 kint32max,
459 "required_sint32_"
460 "value",
461 Json::Int(
462 kint32max))
463 TEST_CONVERT_ITEM(
464 set_required_sint64_value,
465 8,
466 "required_"
467 "sint64_value",
468 "8")
469 TEST_CONVERT_ITEM(
470 set_required_sint64_value,
471 -8,
472 "required_"
473 "sint64_"
474 "value",
475 "-8")
476 TEST_CONVERT_ITEM(
477 set_required_sint64_value,
478 kint64min,
479 "requir"
480 "ed_"
481 "sint64"
482 "_valu"
483 "e",
484 "-92233"
485 "720368"
486 "547758"
487 "08") TEST_CONVERT_ITEM(set_required_sint64_value,
488 kint64max,
489 "required_sint64_value",
490 "9223372036854775807") TEST_CONVERT_ITEM(set_required_fixed32_value,
491 9,
492 "required_fixed32_value", Json::UInt(9)) TEST_CONVERT_ITEM(set_required_fixed32_value, kuint32max,
493 "required_fixed32_value",
494 Json::UInt(kuint32max)) TEST_CONVERT_ITEM(set_required_fixed64_value,
495 10,
496 "required_fixed64_value",
497 "10") TEST_CONVERT_ITEM(set_required_fixed64_value, kuint64max,
498 "required_fixed64_value",
499 "18446744073709551615") TEST_CONVERT_ITEM(set_required_sfixed32_value,
500 11,
501 "required_sfixed32_value", Json::Int(11))
502 TEST_CONVERT_ITEM(
503 set_required_sfixed32_value,
504 -11,
505 "re"
506 "qu"
507 "ir"
508 "ed"
509 "_s"
510 "fi"
511 "xe"
512 "d3"
513 "2_"
514 "va"
515 "lu"
516 "e",
517 Json::Int(
518 -11))
519 TEST_CONVERT_ITEM(
520 set_required_sfixed32_value,
521 kint32min,
522 "required_sfixed32_value",
523 Json::Int(
524 kint32min))
525 TEST_CONVERT_ITEM(set_required_sfixed32_value,
526 kint32max,
527 "required_sfixed32_value",
528 Json::Int(kint32max)) TEST_CONVERT_ITEM(set_required_sfixed64_value,
529 12,
530 "required_sfixed64_value",
531 "12") TEST_CONVERT_ITEM(set_required_sfixed64_value,
532 -12,
533 "required_sfixed64_value",
534 "-12") TEST_CONVERT_ITEM(set_required_sfixed64_value,
535 kint64min,
536 "required_sfixed64_value",
537 "-9223372036854775808") TEST_CONVERT_ITEM(set_required_sfixed64_value,
538 kint64max,
539 "required_sfixed64_value",
540 "9223372036854775807") TEST_CONVERT_ITEM(set_required_bool_value,
541 true,
542 "required_bool_value",
543 true) TEST_CONVERT_ITEM(set_required_bool_value,
544 false,
545 "required_bool_value",
546 false)
547 TEST_CONVERT_ITEM(
548 set_required_string_value,
549 "string",
550 "required_string_value",
551 "string")
552 TEST_CONVERT_ITEM(
553 set_required_bytes_value,
554 "bytes",
555 "required_bytes_value",
556 "bytes")
557 TEST_CONVERT_ITEM(
558 set_required_enum_value,
559 ENUM_A,
560 "required_enum_value",
561 "ENUM_A")
562 TEST_CONVERT_ITEM(
563 set_required_innerenum_value,
564 TestMsg::
565 ENUM_1,
566 "required_innerenum_value",
567 "ENUM_1")
266 TEST_CONVERT_ITEM(set_double_value, 1.0, "double_value", 1.0);
267 TEST_CONVERT_ITEM(set_float_value, 2.0, "float_value", 2.0);
268 TEST_CONVERT_ITEM(set_int32_value, 3, "int32_value", Json::Int(3));
269 TEST_CONVERT_ITEM(set_int32_value, -3, "int32_value", Json::Int(-3));
270 TEST_CONVERT_ITEM(set_int32_value, std::numeric_limits<int32>::min(),
271 "int32_value",
272 Json::Int(std::numeric_limits<int32>::min()));
273 TEST_CONVERT_ITEM(set_int32_value, std::numeric_limits<int32>::max(),
274 "int32_value",
275 Json::Int(std::numeric_limits<int32>::max()));
276 TEST_CONVERT_ITEM(set_int64_value, 4, "int64_value", "4");
277 TEST_CONVERT_ITEM(set_int64_value, -4, "int64_value", "-4");
278 TEST_CONVERT_ITEM(set_int64_value, std::numeric_limits<int64>::min(),
279 "int64_value", "-9223372036854775808");
280 TEST_CONVERT_ITEM(set_int64_value, std::numeric_limits<int64>::max(),
281 "int64_value", "9223372036854775807");
282 TEST_CONVERT_ITEM(set_uint32_value, 5, "uint32_value", Json::UInt(5));
283 TEST_CONVERT_ITEM(set_uint32_value, std::numeric_limits<uint32>::max(),
284 "uint32_value",
285 Json::UInt(std::numeric_limits<uint32>::max()));
286 TEST_CONVERT_ITEM(set_uint64_value, 6, "uint64_value", "6");
287 TEST_CONVERT_ITEM(set_uint64_value, std::numeric_limits<uint64>::max(),
288 "uint64_value", "18446744073709551615");
289 TEST_CONVERT_ITEM(set_sint32_value, 7, "sint32_value", Json::Int(7));
290 TEST_CONVERT_ITEM(set_sint32_value, -7, "sint32_value", Json::Int(-7));
291 TEST_CONVERT_ITEM(set_sint32_value, std::numeric_limits<int32>::min(),
292 "sint32_value",
293 Json::Int(std::numeric_limits<int32>::min()));
294 TEST_CONVERT_ITEM(set_sint32_value, std::numeric_limits<int32>::max(),
295 "sint32_value",
296 Json::Int(std::numeric_limits<int32>::max()));
297 TEST_CONVERT_ITEM(set_sint64_value, 8, "sint64_value", "8");
298 TEST_CONVERT_ITEM(set_sint64_value, -8, "sint64_value", "-8");
299 TEST_CONVERT_ITEM(set_sint64_value, std::numeric_limits<int64>::min(),
300 "sint64_value", "-9223372036854775808");
301 TEST_CONVERT_ITEM(set_sint64_value, std::numeric_limits<int64>::max(),
302 "sint64_value", "9223372036854775807");
303 TEST_CONVERT_ITEM(set_fixed32_value, 9, "fixed32_value", Json::UInt(9));
304 TEST_CONVERT_ITEM(set_fixed32_value, std::numeric_limits<uint32>::max(),
305 "fixed32_value",
306 Json::UInt(std::numeric_limits<uint32>::max()));
307 TEST_CONVERT_ITEM(set_fixed64_value, 10, "fixed64_value", "10");
308 TEST_CONVERT_ITEM(set_fixed64_value, std::numeric_limits<uint64>::max(),
309 "fixed64_value", "18446744073709551615");
310 TEST_CONVERT_ITEM(set_sfixed32_value, 11, "sfixed32_value", Json::Int(11));
311 TEST_CONVERT_ITEM(set_sfixed32_value, -11, "sfixed32_value", Json::Int(-11));
312 TEST_CONVERT_ITEM(set_sfixed32_value, std::numeric_limits<int32>::min(),
313 "sfixed32_value",
314 Json::Int(std::numeric_limits<int32>::min()));
315 TEST_CONVERT_ITEM(set_sfixed32_value, std::numeric_limits<int32>::max(),
316 "sfixed32_value",
317 Json::Int(std::numeric_limits<int32>::max()));
318 TEST_CONVERT_ITEM(set_sfixed64_value, 12, "sfixed64_value", "12");
319 TEST_CONVERT_ITEM(set_sfixed64_value, -12, "sfixed64_value", "-12");
320 TEST_CONVERT_ITEM(set_sfixed64_value, std::numeric_limits<int64>::min(),
321 "sfixed64_value", "-9223372036854775808");
322 TEST_CONVERT_ITEM(set_sfixed64_value, std::numeric_limits<int64>::max(),
323 "sfixed64_value", "9223372036854775807");
324 TEST_CONVERT_ITEM(set_bool_value, true, "bool_value", true);
325 TEST_CONVERT_ITEM(set_bool_value, false, "bool_value", false);
326 TEST_CONVERT_ITEM(set_string_value, "string", "string_value", "string");
327 TEST_CONVERT_ITEM(set_bytes_value, "bytes", "bytes_value", "bytes");
328 TEST_CONVERT_ITEM(set_enum_value, ENUM_A, "enum_value", "ENUM_A");
329 TEST_CONVERT_ITEM(set_innerenum_value, TestMsg::ENUM_1, "innerenum_value",
330 "ENUM_1");
331
332 TEST_CONVERT_ITEM(set_required_double_value, 1.0, "required_double_value",
333 1.0);
334 TEST_CONVERT_ITEM(set_required_float_value, 2.0, "required_float_value", 2.0);
335 TEST_CONVERT_ITEM(set_required_int32_value, 3, "required_int32_value",
336 Json::Int(3));
337 TEST_CONVERT_ITEM(set_required_int32_value, -3, "required_int32_value",
338 Json::Int(-3));
339 TEST_CONVERT_ITEM(set_required_int32_value, std::numeric_limits<int32>::min(),
340 "required_int32_value",
341 Json::Int(std::numeric_limits<int32>::min()));
342 TEST_CONVERT_ITEM(set_required_int32_value, std::numeric_limits<int32>::max(),
343 "required_int32_value",
344 Json::Int(std::numeric_limits<int32>::max()));
345 TEST_CONVERT_ITEM(set_required_int64_value, 4, "required_int64_value", "4");
346 TEST_CONVERT_ITEM(set_required_int64_value, -4, "required_int64_value", "-4");
347 TEST_CONVERT_ITEM(set_required_int64_value, std::numeric_limits<int64>::min(),
348 "required_int64_value", "-9223372036854775808");
349 TEST_CONVERT_ITEM(set_required_int64_value, std::numeric_limits<int64>::max(),
350 "required_int64_value", "9223372036854775807");
351 TEST_CONVERT_ITEM(set_required_uint32_value, 5, "required_uint32_value",
352 Json::UInt(5));
353 TEST_CONVERT_ITEM(set_required_uint32_value,
354 std::numeric_limits<uint32>::max(), "required_uint32_value",
355 Json::UInt(std::numeric_limits<uint32>::max()));
356 TEST_CONVERT_ITEM(set_required_uint64_value, 6, "required_uint64_value", "6");
357 TEST_CONVERT_ITEM(set_required_uint64_value,
358 std::numeric_limits<uint64>::max(), "required_uint64_value",
359 "18446744073709551615");
360 TEST_CONVERT_ITEM(set_required_sint32_value, 7, "required_sint32_value",
361 Json::Int(7));
362 TEST_CONVERT_ITEM(set_required_sint32_value, -7, "required_sint32_value",
363 Json::Int(-7));
364 TEST_CONVERT_ITEM(set_required_sint32_value,
365 std::numeric_limits<int32>::min(), "required_sint32_value",
366 Json::Int(std::numeric_limits<int32>::min()));
367 TEST_CONVERT_ITEM(set_required_sint32_value,
368 std::numeric_limits<int32>::max(), "required_sint32_value",
369 Json::Int(std::numeric_limits<int32>::max()));
370 TEST_CONVERT_ITEM(set_required_sint64_value, 8, "required_sint64_value", "8");
371 TEST_CONVERT_ITEM(set_required_sint64_value, -8, "required_sint64_value",
372 "-8");
373 TEST_CONVERT_ITEM(set_required_sint64_value,
374 std::numeric_limits<int64>::min(), "required_sint64_value",
375 "-9223372036854775808");
376 TEST_CONVERT_ITEM(set_required_sint64_value,
377 std::numeric_limits<int64>::max(), "required_sint64_value",
378 "9223372036854775807");
379 TEST_CONVERT_ITEM(set_required_fixed32_value, 9, "required_fixed32_value",
380 Json::UInt(9));
381 TEST_CONVERT_ITEM(
382 set_required_fixed32_value, std::numeric_limits<uint32>::max(),
383 "required_fixed32_value", Json::UInt(std::numeric_limits<uint32>::max()));
384 TEST_CONVERT_ITEM(set_required_fixed64_value, 10, "required_fixed64_value",
385 "10");
386 TEST_CONVERT_ITEM(set_required_fixed64_value,
387 std::numeric_limits<uint64>::max(),
388 "required_fixed64_value", "18446744073709551615");
389 TEST_CONVERT_ITEM(set_required_sfixed32_value, 11, "required_sfixed32_value",
390 Json::Int(11));
391 TEST_CONVERT_ITEM(set_required_sfixed32_value, -11, "required_sfixed32_value",
392 Json::Int(-11));
393 TEST_CONVERT_ITEM(
394 set_required_sfixed32_value, std::numeric_limits<int32>::min(),
395 "required_sfixed32_value", Json::Int(std::numeric_limits<int32>::min()));
396 TEST_CONVERT_ITEM(
397 set_required_sfixed32_value, std::numeric_limits<int32>::max(),
398 "required_sfixed32_value", Json::Int(std::numeric_limits<int32>::max()));
399 TEST_CONVERT_ITEM(set_required_sfixed64_value, 12, "required_sfixed64_value",
400 "12");
401 TEST_CONVERT_ITEM(set_required_sfixed64_value, -12, "required_sfixed64_value",
402 "-12");
403 TEST_CONVERT_ITEM(set_required_sfixed64_value,
404 std::numeric_limits<int64>::min(),
405 "required_sfixed64_value", "-9223372036854775808");
406 TEST_CONVERT_ITEM(set_required_sfixed64_value,
407 std::numeric_limits<int64>::max(),
408 "required_sfixed64_value", "9223372036854775807");
409 TEST_CONVERT_ITEM(set_required_bool_value, true, "required_bool_value", true);
410 TEST_CONVERT_ITEM(set_required_bool_value, false, "required_bool_value",
411 false);
412 TEST_CONVERT_ITEM(set_required_string_value, "string",
413 "required_string_value", "string");
414 TEST_CONVERT_ITEM(set_required_bytes_value, "bytes", "required_bytes_value",
415 "bytes");
416 TEST_CONVERT_ITEM(set_required_enum_value, ENUM_A, "required_enum_value",
417 "ENUM_A");
418 TEST_CONVERT_ITEM(set_required_innerenum_value, TestMsg::ENUM_1,
419 "required_innerenum_value", "ENUM_1");
568420 #undef TEST_CONVERT_ITEM
569421 }
570422
571 TEST(JsonUtilTest, ConvertRepeatedItemTest){
423 TEST(JsonUtilTest, ConvertRepeatedItemTest) {
572424 #define TEST_CONVERT_REPEATED_ITEM(proto_adder, proto_value1, proto_value2, \
573425 proto_value3, json_name, json_value1, \
574426 json_value2, json_value3) \
590442 FillRequiredFields(&msg); \
591443 EXPECT_PROTO_EQ(msg, new_msg); \
592444 }
593 TEST_CONVERT_REPEATED_ITEM(add_repeated_double_value, 1.0, 2.0, 3.0,
594 "repeated_double_value", 1.0, 2.0, 3.0)
595 TEST_CONVERT_REPEATED_ITEM(
596 add_repeated_float_value, 1.0, 2.0,
597 3.0, "repeated_float_value", 1.0, 2.0, 3.0) TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value,
598 1,
599 2, 3,
600 "repeated_int32_value", Json::Int(1), Json::Int(2), Json::Int(3)) TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value, kint32min,
601 kint32min,
602 kint32min,
603 "repeated_int32_value", Json::Int(kint32min), Json::Int(kint32min), Json::Int(kint32min)) TEST_CONVERT_REPEATED_ITEM(add_repeated_int32_value,
604 kint32max,
605 kint32max,
606 kint32max,
607 "repeated_int32_value", Json::Int(kint32max), Json::Int(kint32max),
608 Json::
609 Int(kint32max)) TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value,
610 1,
611 2,
612 3,
613 "repeated_int64_value",
614 "1",
615 "2",
616 "3") TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value,
617 kint64min,
618 kint64min,
619 kint64min,
620 "repeated_int64_value",
621 "-9223372036854775808",
622 "-9223372036854775808",
623 "-9223372036854775808") TEST_CONVERT_REPEATED_ITEM(add_repeated_int64_value,
624 kint64max, kint64max, kint64max,
625 "repeated_int64_value",
626 "9223372036854775807",
627 "9223372036854775807",
628 "9223372036854775807") TEST_CONVERT_REPEATED_ITEM(add_repeated_uint32_value,
629 1,
630 2,
631 3,
632 "repeated_uint32_value", Json::UInt(1),
633 Json::UInt(2), Json::UInt(3)) TEST_CONVERT_REPEATED_ITEM(add_repeated_uint32_value,
634 kuint32max,
635 kuint32max,
636 kuint32max,
637 "repeated_uint32_value",
638 Json::UInt(kuint32max), Json::UInt(kuint32max),
639 Json::UInt(
640 kuint32max)) TEST_CONVERT_REPEATED_ITEM(add_repeated_uint64_value,
641 1,
642 2,
643 3,
644 "repeated_uint64_value",
645 "1",
646 "2",
647 "3") TEST_CONVERT_REPEATED_ITEM(add_repeated_uint64_value,
648 kuint64max,
649 kuint64max,
650 kuint64max,
651 "repeated_uint64_value",
652 "18446744073709551615",
653 "18446744073709551615",
654 "18446744073709551615") TEST_CONVERT_REPEATED_ITEM(add_repeated_sint32_value,
655 1,
656 2,
657 3,
658 "repeated_sint32_value", Json::Int(1), Json::Int(2),
659 Json::
660 Int(3))
661 TEST_CONVERT_REPEATED_ITEM(
662 add_repeated_sint32_value,
663 kint32min, kint32min, kint32min, "repeated_sint32_value",
664 Json::Int(kint32min),
665 Json::Int(kint32min),
666 Json::Int(kint32min))
667 TEST_CONVERT_REPEATED_ITEM(
668 add_repeated_sint32_value,
669 kint32max, kint32max, kint32max,
670 "repeated_sint32_value", Json::Int(kint32max),
671 Json::Int(kint32max), Json::Int(kint32max))
672 TEST_CONVERT_REPEATED_ITEM(
673 add_repeated_sint64_value,
674 1, 2, 3, "repeated_sint64_value", "1",
675 "2", "3") TEST_CONVERT_REPEATED_ITEM(add_repeated_sint64_value,
676 kint64min,
677 kint64min,
678 kint64min,
679 "repeated_sint64_"
680 "value",
681 "-9223372036854775"
682 "808",
683 "-9223372036854775"
684 "808",
685 "-9223372036854775"
686 "808")
687 TEST_CONVERT_REPEATED_ITEM(
688 add_repeated_sint64_value,
689 kint64max, kint64max, kint64max,
690 "repeated_sint64_value", "9223372036854775807",
691 "9223372036854775807", "9223372036854775807")
692 TEST_CONVERT_REPEATED_ITEM(
693 add_repeated_fixed32_value,
694 1, 2, 3, "repeated_fixed32_value",
695 Json::UInt(1), Json::UInt(2),
696 Json::UInt(3))
697 TEST_CONVERT_REPEATED_ITEM(
698 add_repeated_fixed32_value,
699 kuint32max,
700 kuint32max,
701 kuint32max,
702 "repeated_fixed32_value",
703 Json::UInt(kuint32max),
704 Json::UInt(kuint32max),
705 Json::UInt(
706 kuint32max)) TEST_CONVERT_REPEATED_ITEM(add_repeated_fixed64_value, 1,
707 2,
708 3,
709 "repeated_fixed64_value",
710