5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "TestUtils.hpp"
22 |
23 | namespace opencc {
24 |
25 | class ConfigTestBase : public ::testing::Test {
26 | protected:
27 | ConfigTestBase()
28 | : CONFIG_TEST_PATH(CMAKE_SOURCE_DIR
29 | "/test/config_test/config_test.json") {}
30 |
31 | const string CONFIG_TEST_PATH;
32 | };
33 |
34 | } // namespace opencc
35 |
--------------------------------------------------------------------------------
/docs/src/Docs.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactMarkdown from 'react-markdown'
3 | import readmeContent from './readmecontent'
4 | import SyntaxHighlighter from 'react-syntax-highlighter';
5 |
6 | class Docs extends React.Component {
7 | constructor(props) {
8 | super(props)
9 |
10 | this.state = {
11 | content: readmeContent,
12 | }
13 | }
14 |
15 | componentWillReceiveProps(newProps) {
16 | if (newProps.converter) {
17 | this.setState({
18 | content: newProps.converter.convert(this.state.content),
19 | })
20 | }
21 | }
22 |
23 | render() {
24 | const { content } = this.state
25 | return (
26 |
27 | {
31 | return
32 | {props.value}
33 |
34 | }
35 | }}
36 | />
37 |
38 | )
39 | }
40 | }
41 |
42 | export default Docs
43 |
--------------------------------------------------------------------------------
/wasm/docs/src/Docs.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactMarkdown from 'react-markdown'
3 | import readmeContent from './readmecontent'
4 | import SyntaxHighlighter from 'react-syntax-highlighter';
5 |
6 | class Docs extends React.Component {
7 | constructor(props) {
8 | super(props)
9 |
10 | this.state = {
11 | content: readmeContent,
12 | }
13 | }
14 |
15 | componentWillReceiveProps(newProps) {
16 | if (newProps.converter) {
17 | this.setState({
18 | content: newProps.converter.convert(this.state.content),
19 | })
20 | }
21 | }
22 |
23 | render() {
24 | const { content } = this.state
25 | return (
26 |
27 | {
31 | return
32 | {props.value}
33 |
34 | }
35 | }}
36 | />
37 |
38 | )
39 | }
40 | }
41 |
42 | export default Docs
43 |
--------------------------------------------------------------------------------
/wasm/scripts/concat.js:
--------------------------------------------------------------------------------
1 | // NOTE: There are ploblems with chrome, uglifyjs, and embind
2 | // so that we concat wasm files directly.
3 | const fs = require('fs')
4 | const path = require('path')
5 | const { writeFile } = require('./merge_config')
6 |
7 | const JS_FILE_NAME = 'opencc-asm.js'
8 |
9 | async function getFileContent(filePath) {
10 | return new Promise((resolve, reject) => {
11 | fs.readFile(filePath, {
12 | encoding: 'utf8',
13 | }, (err, content) => {
14 | if (err) {
15 | reject(err)
16 | return
17 | }
18 | resolve(content)
19 | })
20 | })
21 | }
22 |
23 | async function main() {
24 | const targetFile = path.resolve(__dirname, `../dist/${JS_FILE_NAME}`)
25 | const asmContent = await getFileContent(path.resolve(__dirname, `../generated/${JS_FILE_NAME}`))
26 | const content = await getFileContent(targetFile)
27 |
28 | return writeFile(targetFile, `${content};\n// WASCM_CONTENT\n ${asmContent};`)
29 | }
30 |
31 | module.exports = {
32 | concatFile: main,
33 | JS_FILE_NAME,
34 | }
35 |
36 | if (module === require.main) {
37 | main()
38 | }
39 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: "{build}"
2 | skip_branch_with_pr: true
3 | skip_tags: true
4 | build: off
5 |
6 | environment:
7 | matrix:
8 | - nodejs_version: stable
9 | - nodejs_version: 7
10 | - nodejs_version: 6
11 | - nodejs_version: 5
12 |
13 | platform:
14 | - x64
15 | - x86
16 |
17 | # Install scripts. (runs after repo cloning)
18 | install:
19 | # install Node.js
20 | - ps: Install-Product node $env:nodejs_version $env:platform
21 | # Get the latest stable version of npm
22 | - npm -g i npm@latest
23 | # install modules
24 | - appveyor-retry call npm install --build-from-source
25 |
26 | # to run your custom scripts instead of automatic tests
27 | test_script:
28 | - IF %nodejs_version%==stable cmake -H. -Bbuild -G"Visual Studio 12"
29 | - IF %nodejs_version%==stable cmake --build build --config Release --target install
30 | - npm test
31 |
32 | # pushing entire folder as a zip archive
33 | artifacts:
34 | - path: build/src/tools/Release
35 | name: OpenCC
36 | type: zip
37 |
38 | # to run your custom scripts instead of provider deployments
39 | deploy_script:
40 | - npm run deploy
41 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/xcode/Config/DebugProject.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // DebugProject.xcconfig
3 | //
4 | // These are Debug Configuration project settings for the gtest framework and
5 | // examples. It is set in the "Based On:" dropdown in the "Project" info
6 | // dialog.
7 | // This file is based on the Xcode Configuration files in:
8 | // http://code.google.com/p/google-toolbox-for-mac/
9 | //
10 |
11 | #include "General.xcconfig"
12 |
13 | // No optimization
14 | GCC_OPTIMIZATION_LEVEL = 0
15 |
16 | // Deployment postprocessing is what triggers Xcode to strip, turn it off
17 | DEPLOYMENT_POSTPROCESSING = NO
18 |
19 | // Dead code stripping off
20 | DEAD_CODE_STRIPPING = NO
21 |
22 | // Debug symbols should be on obviously
23 | GCC_GENERATE_DEBUGGING_SYMBOLS = YES
24 |
25 | // Define the DEBUG macro in all debug builds
26 | OTHER_CFLAGS = $(OTHER_CFLAGS) -DDEBUG=1
27 |
28 | // These are turned off to avoid STL incompatibilities with client code
29 | // // Turns on special C++ STL checks to "encourage" good STL use
30 | // GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) _GLIBCXX_DEBUG_PEDANTIC _GLIBCXX_DEBUG _GLIBCPP_CONCEPT_CHECKS
31 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/xcode/Config/ReleaseProject.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // ReleaseProject.xcconfig
3 | //
4 | // These are Release Configuration project settings for the gtest framework
5 | // and examples. It is set in the "Based On:" dropdown in the "Project" info
6 | // dialog.
7 | // This file is based on the Xcode Configuration files in:
8 | // http://code.google.com/p/google-toolbox-for-mac/
9 | //
10 |
11 | #include "General.xcconfig"
12 |
13 | // subconfig/Release.xcconfig
14 |
15 | // Optimize for space and size (Apple recommendation)
16 | GCC_OPTIMIZATION_LEVEL = s
17 |
18 | // Deploment postprocessing is what triggers Xcode to strip
19 | DEPLOYMENT_POSTPROCESSING = YES
20 |
21 | // No symbols
22 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO
23 |
24 | // Dead code strip does not affect ObjC code but can help for C
25 | DEAD_CODE_STRIPPING = YES
26 |
27 | // NDEBUG is used by things like assert.h, so define it for general compat.
28 | // ASSERT going away in release tends to create unused vars.
29 | OTHER_CFLAGS = $(OTHER_CFLAGS) -DNDEBUG=1 -Wno-unused-variable
30 |
31 | // When we strip we want to strip all symbols in release, but save externals.
32 | STRIP_STYLE = all
33 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/xcode/Resources/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.google.${PRODUCT_NAME}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | GTEST_VERSIONINFO_LONG
21 | CFBundleShortVersionString
22 | GTEST_VERSIONINFO_SHORT
23 | CFBundleGetInfoString
24 | ${PRODUCT_NAME} GTEST_VERSIONINFO_LONG, ${GTEST_VERSIONINFO_ABOUT}
25 | NSHumanReadableCopyright
26 | ${GTEST_VERSIONINFO_ABOUT}
27 | CSResourcesFileMapped
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/Config.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 |
23 | namespace opencc {
24 | /**
25 | * Configuration loader
26 | * @ingroup opencc_cpp_api
27 | */
28 | class OPENCC_EXPORT Config {
29 | public:
30 | Config();
31 |
32 | virtual ~Config();
33 |
34 | ConverterPtr NewFromString(const string& json, const string& configDirectory);
35 |
36 | ConverterPtr NewFromFile(const string& fileName);
37 |
38 | private:
39 | void* internal;
40 | };
41 | }
42 |
--------------------------------------------------------------------------------
/src/DictEntry.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "DictEntry.hpp"
20 |
21 | using namespace opencc;
22 |
23 | string MultiValueDictEntry::ToString() const {
24 | // TODO escape space
25 | size_t i = 0;
26 | size_t length = Values().size();
27 | std::ostringstream buffer;
28 | buffer << Key() << '\t';
29 | for (const char* value : Values()) {
30 | buffer << value;
31 | if (i < length - 1) {
32 | buffer << ' ';
33 | }
34 | i++;
35 | }
36 | return buffer.str();
37 | }
--------------------------------------------------------------------------------
/wasm/webpack.config.js:
--------------------------------------------------------------------------------
1 | // Webpack build for browsers only.
2 | // NOTE: There are ploblems with chrome, uglifyjs, and embind
3 | // so that we concat wasm files directly.
4 | const webpack = require('webpack');
5 | const path = require('path');
6 | const { JS_FILE_NAME } = require('./scripts/generate')
7 |
8 | module.exports = {
9 | mode: 'production',
10 | resolve: {
11 | alias: {
12 | Module: path.resolve(__dirname, './src/Module'),
13 | },
14 | },
15 | entry: path.resolve(__dirname, './src/index.js'),
16 | output: {
17 | filename: JS_FILE_NAME,
18 | path: path.resolve(__dirname, './dist'),
19 | },
20 | externals: [
21 | 'fs',
22 | function(context, request, callback) {
23 | if (/opencc-asm/.test(request)){
24 | return callback(null, 'commonjs ' + request);
25 | }
26 | callback();
27 | }
28 | ],
29 | module: {
30 | rules: [
31 | {
32 | test: /\.js$/,
33 | exclude: ['node_modules'],
34 | use: {
35 | loader: 'babel-loader',
36 | options: {
37 | presets: ['babel-preset-env'],
38 | },
39 | },
40 | },
41 | ],
42 | },
43 | };
44 |
--------------------------------------------------------------------------------
/deps/rapidjson-0.11/filestream.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_FILESTREAM_H_
2 | #define RAPIDJSON_FILESTREAM_H_
3 |
4 | #include
5 |
6 | namespace rapidjson {
7 |
8 | //! Wrapper of C file stream for input or output.
9 | /*!
10 | This simple wrapper does not check the validity of the stream.
11 | \implements Stream
12 | */
13 | class FileStream {
14 | public:
15 | typedef char Ch; //!< Character type. Only support char.
16 |
17 | FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); }
18 | char Peek() const { return current_; }
19 | char Take() { char c = current_; Read(); return c; }
20 | size_t Tell() const { return count_; }
21 | void Put(char c) { fputc(c, fp_); }
22 |
23 | // Not implemented
24 | char* PutBegin() { return 0; }
25 | size_t PutEnd(char*) { return 0; }
26 |
27 | private:
28 | void Read() {
29 | RAPIDJSON_ASSERT(fp_ != 0);
30 | int c = fgetc(fp_);
31 | if (c != EOF) {
32 | current_ = (char)c;
33 | count_++;
34 | }
35 | else
36 | current_ = '\0';
37 | }
38 |
39 | FILE* fp_;
40 | char current_;
41 | size_t count_;
42 | };
43 |
44 | } // namespace rapidjson
45 |
46 | #endif // RAPIDJSON_FILESTREAM_H_
47 |
--------------------------------------------------------------------------------
/src/ConversionChain.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "ConversionChain.hpp"
20 | #include "Segments.hpp"
21 |
22 | using namespace opencc;
23 |
24 | ConversionChain::ConversionChain(const list _conversions)
25 | : conversions(_conversions) {}
26 |
27 | SegmentsPtr ConversionChain::Convert(const SegmentsPtr& input) const {
28 | SegmentsPtr output = input;
29 | for (auto conversion : conversions) {
30 | output = conversion->Convert(output);
31 | }
32 | return output;
33 | }
34 |
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/COPYING:
--------------------------------------------------------------------------------
1 |
2 |
3 | Copyright (c) 2003 Michael E. Smoot
4 |
5 | Permission is hereby granted, free of charge, to any person
6 | obtaining a copy of this software and associated documentation
7 | files (the "Software"), to deal in the Software without restriction,
8 | including without limitation the rights to use, copy, modify, merge,
9 | publish, distribute, sublicense, and/or sell copies of the Software,
10 | and to permit persons to whom the Software is furnished to do so,
11 | subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 |
25 |
26 |
--------------------------------------------------------------------------------
/docs/dict/TWPhrasesName.txt:
--------------------------------------------------------------------------------
1 | 乍得 查德
2 | 也門 葉門
3 | 仙童半導體 快捷半導體
4 | 伯利茲 貝里斯
5 | 佛得角 維德角
6 | 傅里葉 傅立葉
7 | 克羅地亞 克羅埃西亞
8 | 列支敦士登 列支敦斯登
9 | 利比里亞 賴比瑞亞
10 | 加納 迦納
11 | 加蓬 加彭
12 | 博茨瓦納 波札那
13 | 卡塔爾 卡達
14 | 危地馬拉 瓜地馬拉
15 | 厄瓜多爾 厄瓜多
16 | 厄立特里亞 厄利垂亞
17 | 吉布堤 吉布地
18 | 哈薩克斯坦 哈薩克
19 | 哥斯達黎加 哥斯大黎加
20 | 圖瓦盧 吐瓦魯
21 | 土庫曼斯坦 土庫曼
22 | 圭亞那 蓋亞那
23 | 坦桑尼亞 坦尚尼亞
24 | 埃塞俄比亞 衣索比亞
25 | 基里巴斯 吉里巴斯
26 | 塔吉克斯坦 塔吉克
27 | 塞拉利昂 獅子山
28 | 塞浦路斯 塞普勒斯
29 | 塞舌爾 塞席爾
30 | 多米尼加 多明尼加
31 | 安提瓜和巴布達 安地卡及巴布達
32 | 尼日利亞 奈及利亞
33 | 尼日爾 尼日
34 | 岡比亞 甘比亞
35 | 巴巴多斯 巴貝多
36 | 巴布亞新幾內亞 巴布亞紐幾內亞
37 | 布基納法索 布吉納法索
38 | 布隆迪 蒲隆地
39 | 帕勞 帛琉
40 | 幾內亞比紹 幾內亞比索
41 | 意大利 義大利
42 | 所羅門羣島 索羅門羣島
43 | 文萊 汶萊
44 | 斯威士蘭 史瓦濟蘭
45 | 斯洛文尼亞 斯洛維尼亞
46 | 新西蘭 紐西蘭
47 | 格林納達 格瑞那達
48 | 格魯吉亞 喬治亞
49 | 歐拉 尤拉
50 | 毛里塔尼亞 茅利塔尼亞
51 | 毛里求斯 模里西斯
52 | 沙特阿拉伯 沙烏地阿拉伯
53 | 波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納
54 | 津巴布韋 辛巴威
55 | 洪都拉斯 宏都拉斯
56 | 溫納圖萬 那杜
57 | 烏茲別克斯坦 烏茲別克
58 | 特立尼達和多巴哥 千里達及托巴哥
59 | 瑙魯 諾魯
60 | 瓦努阿圖 萬那杜
61 | 盧旺達 盧安達
62 | 科摩羅 葛摩
63 | 科特迪瓦 象牙海岸
64 | 突尼斯 突尼西亞
65 | 索馬里 索馬利亞
66 | 老撾 寮國
67 | 聖基茨和尼維斯 聖克里斯多福及尼維斯
68 | 聖文森特和格林納丁斯 聖文森及格瑞那丁
69 | 聖盧西亞 聖露西亞
70 | 聖馬力諾 聖馬利諾
71 | 肯尼亞 肯亞
72 | 莫桑比克 莫三比克
73 | 萊索托 賴索托
74 | 萬象 永珍
75 | 蘇里南 蘇利南
76 | 貝寧 貝南
77 | 贊比亞 尚比亞
78 | 阿塞拜疆 亞塞拜然
79 | 阿拉伯聯合酋長國 阿拉伯聯合大公國
80 | 香農 夏農
81 | 馬爾代夫 馬爾地夫
82 | 馬里共和國 馬利共和國
83 |
--------------------------------------------------------------------------------
/data/dictionary/TWPhrasesName.txt:
--------------------------------------------------------------------------------
1 | 乍得 查德
2 | 也門 葉門
3 | 仙童半導體 快捷半導體
4 | 伯利茲 貝里斯
5 | 佛得角 維德角
6 | 傅里葉 傅立葉
7 | 克羅地亞 克羅埃西亞
8 | 列支敦士登 列支敦斯登
9 | 利比里亞 賴比瑞亞
10 | 加納 迦納
11 | 加蓬 加彭
12 | 博茨瓦納 波札那
13 | 卡塔爾 卡達
14 | 危地馬拉 瓜地馬拉
15 | 厄瓜多爾 厄瓜多
16 | 厄立特里亞 厄利垂亞
17 | 吉布堤 吉布地
18 | 哈薩克斯坦 哈薩克
19 | 哥斯達黎加 哥斯大黎加
20 | 圖瓦盧 吐瓦魯
21 | 土庫曼斯坦 土庫曼
22 | 圭亞那 蓋亞那
23 | 坦桑尼亞 坦尚尼亞
24 | 埃塞俄比亞 衣索比亞
25 | 基里巴斯 吉里巴斯
26 | 塔吉克斯坦 塔吉克
27 | 塞拉利昂 獅子山
28 | 塞浦路斯 塞普勒斯
29 | 塞舌爾 塞席爾
30 | 多米尼加 多明尼加
31 | 安提瓜和巴布達 安地卡及巴布達
32 | 尼日利亞 奈及利亞
33 | 尼日爾 尼日
34 | 岡比亞 甘比亞
35 | 巴巴多斯 巴貝多
36 | 巴布亞新幾內亞 巴布亞紐幾內亞
37 | 布基納法索 布吉納法索
38 | 布隆迪 蒲隆地
39 | 帕勞 帛琉
40 | 幾內亞比紹 幾內亞比索
41 | 意大利 義大利
42 | 所羅門羣島 索羅門羣島
43 | 文萊 汶萊
44 | 斯威士蘭 史瓦濟蘭
45 | 斯洛文尼亞 斯洛維尼亞
46 | 新西蘭 紐西蘭
47 | 格林納達 格瑞那達
48 | 格魯吉亞 喬治亞
49 | 歐拉 尤拉
50 | 毛里塔尼亞 茅利塔尼亞
51 | 毛里求斯 模里西斯
52 | 沙特阿拉伯 沙烏地阿拉伯
53 | 波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納
54 | 津巴布韋 辛巴威
55 | 洪都拉斯 宏都拉斯
56 | 溫納圖萬 那杜
57 | 烏茲別克斯坦 烏茲別克
58 | 特立尼達和多巴哥 千里達及托巴哥
59 | 瑙魯 諾魯
60 | 瓦努阿圖 萬那杜
61 | 盧旺達 盧安達
62 | 科摩羅 葛摩
63 | 科特迪瓦 象牙海岸
64 | 突尼斯 突尼西亞
65 | 索馬里 索馬利亞
66 | 老撾 寮國
67 | 聖基茨和尼維斯 聖克里斯多福及尼維斯
68 | 聖文森特和格林納丁斯 聖文森及格瑞那丁
69 | 聖盧西亞 聖露西亞
70 | 聖馬力諾 聖馬利諾
71 | 肯尼亞 肯亞
72 | 莫桑比克 莫三比克
73 | 萊索托 賴索托
74 | 萬象 永珍
75 | 蘇里南 蘇利南
76 | 貝寧 貝南
77 | 贊比亞 尚比亞
78 | 阿塞拜疆 亞塞拜然
79 | 阿拉伯聯合酋長國 阿拉伯聯合大公國
80 | 香農 夏農
81 | 馬爾代夫 馬爾地夫
82 | 馬里共和國 馬利共和國
83 |
--------------------------------------------------------------------------------
/wasm/dist/dict/TWPhrasesName.txt:
--------------------------------------------------------------------------------
1 | 乍得 查德
2 | 也門 葉門
3 | 仙童半導體 快捷半導體
4 | 伯利茲 貝里斯
5 | 佛得角 維德角
6 | 傅里葉 傅立葉
7 | 克羅地亞 克羅埃西亞
8 | 列支敦士登 列支敦斯登
9 | 利比里亞 賴比瑞亞
10 | 加納 迦納
11 | 加蓬 加彭
12 | 博茨瓦納 波札那
13 | 卡塔爾 卡達
14 | 危地馬拉 瓜地馬拉
15 | 厄瓜多爾 厄瓜多
16 | 厄立特里亞 厄利垂亞
17 | 吉布堤 吉布地
18 | 哈薩克斯坦 哈薩克
19 | 哥斯達黎加 哥斯大黎加
20 | 圖瓦盧 吐瓦魯
21 | 土庫曼斯坦 土庫曼
22 | 圭亞那 蓋亞那
23 | 坦桑尼亞 坦尚尼亞
24 | 埃塞俄比亞 衣索比亞
25 | 基里巴斯 吉里巴斯
26 | 塔吉克斯坦 塔吉克
27 | 塞拉利昂 獅子山
28 | 塞浦路斯 塞普勒斯
29 | 塞舌爾 塞席爾
30 | 多米尼加 多明尼加
31 | 安提瓜和巴布達 安地卡及巴布達
32 | 尼日利亞 奈及利亞
33 | 尼日爾 尼日
34 | 岡比亞 甘比亞
35 | 巴巴多斯 巴貝多
36 | 巴布亞新幾內亞 巴布亞紐幾內亞
37 | 布基納法索 布吉納法索
38 | 布隆迪 蒲隆地
39 | 帕勞 帛琉
40 | 幾內亞比紹 幾內亞比索
41 | 意大利 義大利
42 | 所羅門羣島 索羅門羣島
43 | 文萊 汶萊
44 | 斯威士蘭 史瓦濟蘭
45 | 斯洛文尼亞 斯洛維尼亞
46 | 新西蘭 紐西蘭
47 | 格林納達 格瑞那達
48 | 格魯吉亞 喬治亞
49 | 歐拉 尤拉
50 | 毛里塔尼亞 茅利塔尼亞
51 | 毛里求斯 模里西斯
52 | 沙特阿拉伯 沙烏地阿拉伯
53 | 波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納
54 | 津巴布韋 辛巴威
55 | 洪都拉斯 宏都拉斯
56 | 溫納圖萬 那杜
57 | 烏茲別克斯坦 烏茲別克
58 | 特立尼達和多巴哥 千里達及托巴哥
59 | 瑙魯 諾魯
60 | 瓦努阿圖 萬那杜
61 | 盧旺達 盧安達
62 | 科摩羅 葛摩
63 | 科特迪瓦 象牙海岸
64 | 突尼斯 突尼西亞
65 | 索馬里 索馬利亞
66 | 老撾 寮國
67 | 聖基茨和尼維斯 聖克里斯多福及尼維斯
68 | 聖文森特和格林納丁斯 聖文森及格瑞那丁
69 | 聖盧西亞 聖露西亞
70 | 聖馬力諾 聖馬利諾
71 | 肯尼亞 肯亞
72 | 莫桑比克 莫三比克
73 | 萊索托 賴索托
74 | 萬象 永珍
75 | 蘇里南 蘇利南
76 | 貝寧 貝南
77 | 贊比亞 尚比亞
78 | 阿塞拜疆 亞塞拜然
79 | 阿拉伯聯合酋長國 阿拉伯聯合大公國
80 | 香農 夏農
81 | 馬爾代夫 馬爾地夫
82 | 馬里共和國 馬利共和國
83 |
--------------------------------------------------------------------------------
/wasm/docs/dict/TWPhrasesName.txt:
--------------------------------------------------------------------------------
1 | 乍得 查德
2 | 也門 葉門
3 | 仙童半導體 快捷半導體
4 | 伯利茲 貝里斯
5 | 佛得角 維德角
6 | 傅里葉 傅立葉
7 | 克羅地亞 克羅埃西亞
8 | 列支敦士登 列支敦斯登
9 | 利比里亞 賴比瑞亞
10 | 加納 迦納
11 | 加蓬 加彭
12 | 博茨瓦納 波札那
13 | 卡塔爾 卡達
14 | 危地馬拉 瓜地馬拉
15 | 厄瓜多爾 厄瓜多
16 | 厄立特里亞 厄利垂亞
17 | 吉布堤 吉布地
18 | 哈薩克斯坦 哈薩克
19 | 哥斯達黎加 哥斯大黎加
20 | 圖瓦盧 吐瓦魯
21 | 土庫曼斯坦 土庫曼
22 | 圭亞那 蓋亞那
23 | 坦桑尼亞 坦尚尼亞
24 | 埃塞俄比亞 衣索比亞
25 | 基里巴斯 吉里巴斯
26 | 塔吉克斯坦 塔吉克
27 | 塞拉利昂 獅子山
28 | 塞浦路斯 塞普勒斯
29 | 塞舌爾 塞席爾
30 | 多米尼加 多明尼加
31 | 安提瓜和巴布達 安地卡及巴布達
32 | 尼日利亞 奈及利亞
33 | 尼日爾 尼日
34 | 岡比亞 甘比亞
35 | 巴巴多斯 巴貝多
36 | 巴布亞新幾內亞 巴布亞紐幾內亞
37 | 布基納法索 布吉納法索
38 | 布隆迪 蒲隆地
39 | 帕勞 帛琉
40 | 幾內亞比紹 幾內亞比索
41 | 意大利 義大利
42 | 所羅門羣島 索羅門羣島
43 | 文萊 汶萊
44 | 斯威士蘭 史瓦濟蘭
45 | 斯洛文尼亞 斯洛維尼亞
46 | 新西蘭 紐西蘭
47 | 格林納達 格瑞那達
48 | 格魯吉亞 喬治亞
49 | 歐拉 尤拉
50 | 毛里塔尼亞 茅利塔尼亞
51 | 毛里求斯 模里西斯
52 | 沙特阿拉伯 沙烏地阿拉伯
53 | 波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納
54 | 津巴布韋 辛巴威
55 | 洪都拉斯 宏都拉斯
56 | 溫納圖萬 那杜
57 | 烏茲別克斯坦 烏茲別克
58 | 特立尼達和多巴哥 千里達及托巴哥
59 | 瑙魯 諾魯
60 | 瓦努阿圖 萬那杜
61 | 盧旺達 盧安達
62 | 科摩羅 葛摩
63 | 科特迪瓦 象牙海岸
64 | 突尼斯 突尼西亞
65 | 索馬里 索馬利亞
66 | 老撾 寮國
67 | 聖基茨和尼維斯 聖克里斯多福及尼維斯
68 | 聖文森特和格林納丁斯 聖文森及格瑞那丁
69 | 聖盧西亞 聖露西亞
70 | 聖馬力諾 聖馬利諾
71 | 肯尼亞 肯亞
72 | 莫桑比克 莫三比克
73 | 萊索托 賴索托
74 | 萬象 永珍
75 | 蘇里南 蘇利南
76 | 貝寧 貝南
77 | 贊比亞 尚比亞
78 | 阿塞拜疆 亞塞拜然
79 | 阿拉伯聯合酋長國 阿拉伯聯合大公國
80 | 香農 夏農
81 | 馬爾代夫 馬爾地夫
82 | 馬里共和國 馬利共和國
83 |
--------------------------------------------------------------------------------
/wasm/generated/dict/TWPhrasesName.txt:
--------------------------------------------------------------------------------
1 | 乍得 查德
2 | 也門 葉門
3 | 仙童半導體 快捷半導體
4 | 伯利茲 貝里斯
5 | 佛得角 維德角
6 | 傅里葉 傅立葉
7 | 克羅地亞 克羅埃西亞
8 | 列支敦士登 列支敦斯登
9 | 利比里亞 賴比瑞亞
10 | 加納 迦納
11 | 加蓬 加彭
12 | 博茨瓦納 波札那
13 | 卡塔爾 卡達
14 | 危地馬拉 瓜地馬拉
15 | 厄瓜多爾 厄瓜多
16 | 厄立特里亞 厄利垂亞
17 | 吉布堤 吉布地
18 | 哈薩克斯坦 哈薩克
19 | 哥斯達黎加 哥斯大黎加
20 | 圖瓦盧 吐瓦魯
21 | 土庫曼斯坦 土庫曼
22 | 圭亞那 蓋亞那
23 | 坦桑尼亞 坦尚尼亞
24 | 埃塞俄比亞 衣索比亞
25 | 基里巴斯 吉里巴斯
26 | 塔吉克斯坦 塔吉克
27 | 塞拉利昂 獅子山
28 | 塞浦路斯 塞普勒斯
29 | 塞舌爾 塞席爾
30 | 多米尼加 多明尼加
31 | 安提瓜和巴布達 安地卡及巴布達
32 | 尼日利亞 奈及利亞
33 | 尼日爾 尼日
34 | 岡比亞 甘比亞
35 | 巴巴多斯 巴貝多
36 | 巴布亞新幾內亞 巴布亞紐幾內亞
37 | 布基納法索 布吉納法索
38 | 布隆迪 蒲隆地
39 | 帕勞 帛琉
40 | 幾內亞比紹 幾內亞比索
41 | 意大利 義大利
42 | 所羅門羣島 索羅門羣島
43 | 文萊 汶萊
44 | 斯威士蘭 史瓦濟蘭
45 | 斯洛文尼亞 斯洛維尼亞
46 | 新西蘭 紐西蘭
47 | 格林納達 格瑞那達
48 | 格魯吉亞 喬治亞
49 | 歐拉 尤拉
50 | 毛里塔尼亞 茅利塔尼亞
51 | 毛里求斯 模里西斯
52 | 沙特阿拉伯 沙烏地阿拉伯
53 | 波斯尼亞黑塞哥維那 波士尼亞赫塞哥維納
54 | 津巴布韋 辛巴威
55 | 洪都拉斯 宏都拉斯
56 | 溫納圖萬 那杜
57 | 烏茲別克斯坦 烏茲別克
58 | 特立尼達和多巴哥 千里達及托巴哥
59 | 瑙魯 諾魯
60 | 瓦努阿圖 萬那杜
61 | 盧旺達 盧安達
62 | 科摩羅 葛摩
63 | 科特迪瓦 象牙海岸
64 | 突尼斯 突尼西亞
65 | 索馬里 索馬利亞
66 | 老撾 寮國
67 | 聖基茨和尼維斯 聖克里斯多福及尼維斯
68 | 聖文森特和格林納丁斯 聖文森及格瑞那丁
69 | 聖盧西亞 聖露西亞
70 | 聖馬力諾 聖馬利諾
71 | 肯尼亞 肯亞
72 | 莫桑比克 莫三比克
73 | 萊索托 賴索托
74 | 萬象 永珍
75 | 蘇里南 蘇利南
76 | 貝寧 貝南
77 | 贊比亞 尚比亞
78 | 阿塞拜疆 亞塞拜然
79 | 阿拉伯聯合酋長國 阿拉伯聯合大公國
80 | 香農 夏農
81 | 馬爾代夫 馬爾地夫
82 | 馬里共和國 馬利共和國
83 |
--------------------------------------------------------------------------------
/src/DictGroupTestBase.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "DictGroup.hpp"
22 | #include "TextDictTestBase.hpp"
23 |
24 | namespace opencc {
25 |
26 | class DictGroupTestBase : public TextDictTestBase {
27 | protected:
28 | DictGroupPtr CreateDictGroupForConversion() const {
29 | DictPtr phrasesDict = CreateDictForPhrases();
30 | DictPtr charactersDict = CreateDictForCharacters();
31 | DictGroupPtr dictGroup(
32 | new DictGroup(list{phrasesDict, charactersDict}));
33 | return dictGroup;
34 | }
35 | };
36 |
37 | } // namespace opencc
38 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "opencc",
3 | "version": "1.0.5",
4 | "description": "Conversion between Traditional and Simplified Chinese",
5 | "author": "BYVoid ",
6 | "license": "Apache-2.0",
7 | "main": "node/opencc.js",
8 | "scripts": {
9 | "test": "mocha -R spec node/test.js",
10 | "deploy": "node-pre-gyp package && (node-pre-gyp-github publish --release || exit 0)",
11 | "install": "node-pre-gyp install --fallback-to-build || node-pre-gyp rebuild"
12 | },
13 | "binary": {
14 | "module_name": "opencc",
15 | "module_path": "./build/Release/",
16 | "host": "https://github.com/BYVoid/OpenCC/releases/download/",
17 | "remote_path": "{version}"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "git://github.com/BYVoid/OpenCC.git"
22 | },
23 | "bugs": {
24 | "url": "https://github.com/BYVoid/Opencc/issues"
25 | },
26 | "keywords": [
27 | "opencc",
28 | "Chinese",
29 | "conversion",
30 | "unicode",
31 | "Simplified Chinese",
32 | "Traditional Chinese"
33 | ],
34 | "devDependencies": {
35 | "mocha": "^3.5.0",
36 | "node-pre-gyp-github": "^1.3.1"
37 | },
38 | "dependencies": {
39 | "nan": "^2.7.0",
40 | "node-pre-gyp": "^0.6.36"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Converter.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "Converter.hpp"
20 | #include "ConversionChain.hpp"
21 | #include "Segments.hpp"
22 |
23 | using namespace opencc;
24 |
25 | string Converter::Convert(const string& text) const {
26 | const SegmentsPtr& segments = segmentation->Segment(text);
27 | const SegmentsPtr& converted = conversionChain->Convert(segments);
28 | return converted->ToString();
29 | }
30 |
31 | size_t Converter::Convert(const char* input, char* output) const {
32 | const string& converted = Convert(input);
33 | strcpy(output, converted.c_str());
34 | return converted.length();
35 | }
36 |
--------------------------------------------------------------------------------
/src/ConversionChain.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "Conversion.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Chain of conversions
27 | * Consists of a list of conversions. Converts input in sequence.
28 | * @ingroup opencc_cpp_api
29 | */
30 | class OPENCC_EXPORT ConversionChain {
31 | public:
32 | ConversionChain(const list _conversions);
33 |
34 | SegmentsPtr Convert(const SegmentsPtr& input) const;
35 |
36 | const list GetConversions() const { return conversions; }
37 |
38 | private:
39 | const list conversions;
40 | };
41 | }
42 |
--------------------------------------------------------------------------------
/wasm/src/ConfigParser.js:
--------------------------------------------------------------------------------
1 | const EXT_FROM = '.ocd'
2 | const EXT_TO = '.txt'
3 |
4 | // NOTE: We will replace all .ocd with .txt.
5 | function replaceExt(str) {
6 | if (str.indexOf(EXT_FROM) === str.length - EXT_FROM.length) {
7 | return str.replace(EXT_FROM, EXT_TO)
8 | }
9 |
10 | return str
11 | }
12 |
13 | function parseDict(obj) {
14 | if (obj.type === 'group') {
15 | return obj.dicts.map(i => replaceExt(i.file))
16 | }
17 |
18 | return replaceExt(obj.file)
19 | }
20 |
21 | function parse(json) {
22 | const { segmentation, conversion_chain: convertionChain } = json
23 |
24 | const result = {
25 | segmentation: parseDict(segmentation.dict),
26 | convertionChain: convertionChain.map(i => parseDict(i.dict))
27 | }
28 |
29 | return result
30 | }
31 |
32 | function isValidSegmentationArg(segmentationString) {
33 | return typeof segmentationString === 'string'
34 | }
35 |
36 | function isValidConvertionChainArg(arg) {
37 | let valid = true
38 |
39 | if (!Array.isArray(arg)) {
40 | valid = false
41 | }
42 |
43 | arg.forEach(i => {
44 | if (!Array.isArray(i) && typeof i !== 'string') {
45 | valid = false
46 | }
47 | })
48 |
49 | return valid
50 | }
51 |
52 | module.exports = {
53 | parse,
54 | isValidSegmentationArg,
55 | isValidConvertionChainArg,
56 | }
57 |
--------------------------------------------------------------------------------
/src/MaxMatchSegmentation.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "DictGroup.hpp"
23 | #include "Segmentation.hpp"
24 |
25 | namespace opencc {
26 | /**
27 | * Implementation of maximal match segmentation
28 | * @ingroup opencc_cpp_api
29 | */
30 | class OPENCC_EXPORT MaxMatchSegmentation : public Segmentation {
31 | public:
32 | MaxMatchSegmentation(const DictPtr _dict) : dict(_dict) {}
33 |
34 | virtual ~MaxMatchSegmentation() {}
35 |
36 | virtual SegmentsPtr Segment(const string& text) const;
37 |
38 | const DictPtr GetDict() const { return dict; }
39 |
40 | private:
41 | const DictPtr dict;
42 | };
43 | }
44 |
--------------------------------------------------------------------------------
/src/TextDictTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "TextDictTestBase.hpp"
20 |
21 | namespace opencc {
22 |
23 | class TextDictTest : public TextDictTestBase {
24 | protected:
25 | TextDictTest() : fileName("dict.txt"){};
26 |
27 | const string fileName;
28 | };
29 |
30 | TEST_F(TextDictTest, DictTest) { TestDict(textDict); }
31 |
32 | TEST_F(TextDictTest, Serialization) {
33 | textDict->opencc::SerializableDict::SerializeToFile(fileName);
34 | }
35 |
36 | TEST_F(TextDictTest, Deserialization) {
37 | const TextDictPtr& deserialized =
38 | SerializableDict::NewFromFile(fileName);
39 | TestDict(deserialized);
40 | }
41 |
42 | } // namespace opencc
43 |
--------------------------------------------------------------------------------
/src/Conversion.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "Segmentation.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Conversion interface
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT Conversion {
30 | public:
31 | Conversion(DictPtr _dict) : dict(_dict) {}
32 |
33 | // Convert single phrase
34 | string Convert(const string& phrase) const;
35 |
36 | // Convert single phrase
37 | string Convert(const char* phrase) const;
38 |
39 | // Convert segmented text
40 | SegmentsPtr Convert(const SegmentsPtr& input) const;
41 |
42 | const DictPtr GetDict() const { return dict; }
43 |
44 | private:
45 | const DictPtr dict;
46 | };
47 | }
48 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/xcode/Config/General.xcconfig:
--------------------------------------------------------------------------------
1 | //
2 | // General.xcconfig
3 | //
4 | // These are General configuration settings for the gtest framework and
5 | // examples.
6 | // This file is based on the Xcode Configuration files in:
7 | // http://code.google.com/p/google-toolbox-for-mac/
8 | //
9 |
10 | // Build for PPC and Intel, 32- and 64-bit
11 | ARCHS = i386 x86_64 ppc ppc64
12 |
13 | // Zerolink prevents link warnings so turn it off
14 | ZERO_LINK = NO
15 |
16 | // Prebinding considered unhelpful in 10.3 and later
17 | PREBINDING = NO
18 |
19 | // Strictest warning policy
20 | WARNING_CFLAGS = -Wall -Werror -Wendif-labels -Wnewline-eof -Wno-sign-compare -Wshadow
21 |
22 | // Work around Xcode bugs by using external strip. See:
23 | // http://lists.apple.com/archives/Xcode-users/2006/Feb/msg00050.html
24 | SEPARATE_STRIP = YES
25 |
26 | // Force C99 dialect
27 | GCC_C_LANGUAGE_STANDARD = c99
28 |
29 | // not sure why apple defaults this on, but it's pretty risky
30 | ALWAYS_SEARCH_USER_PATHS = NO
31 |
32 | // Turn on position dependent code for most cases (overridden where appropriate)
33 | GCC_DYNAMIC_NO_PIC = YES
34 |
35 | // Default SDK and minimum OS version is 10.4
36 | SDKROOT = $(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk
37 | MACOSX_DEPLOYMENT_TARGET = 10.4
38 | GCC_VERSION = 4.0
39 |
40 | // VERSIONING BUILD SETTINGS (used in Info.plist)
41 | GTEST_VERSIONINFO_ABOUT = © 2008 Google Inc.
42 |
--------------------------------------------------------------------------------
/src/Export.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #if defined(Opencc_BUILT_AS_STATIC) || !defined(_WIN32)
22 | #define OPENCC_EXPORT
23 | #define OPENCC_NO_EXPORT
24 | #else // if defined(Opencc_BUILT_AS_STATIC) || !defined(_WIN32)
25 | #ifndef OPENCC_EXPORT
26 | #ifdef libopencc_EXPORTS
27 |
28 | /* We are building this library */
29 | #define OPENCC_EXPORT __declspec(dllexport)
30 | #else // ifdef libopencc_EXPORTS
31 |
32 | /* We are using this library */
33 | #define OPENCC_EXPORT __declspec(dllimport)
34 | #endif // ifdef libopencc_EXPORTS
35 | #endif // ifndef OPENCC_EXPORT
36 |
37 | #ifndef OPENCC_NO_EXPORT
38 | #define OPENCC_NO_EXPORT
39 | #endif // ifndef OPENCC_NO_EXPORT
40 | #endif // if defined(Opencc_BUILT_AS_STATIC) || !defined(_WIN32)
41 |
--------------------------------------------------------------------------------
/docs/lib/build.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _fs = require('fs');
4 |
5 | var _fs2 = _interopRequireDefault(_fs);
6 |
7 | var _path = require('path');
8 |
9 | var _path2 = _interopRequireDefault(_path);
10 |
11 | var _react = require('react');
12 |
13 | var _react2 = _interopRequireDefault(_react);
14 |
15 | var _server = require('react-dom/server');
16 |
17 | var _server2 = _interopRequireDefault(_server);
18 |
19 | var _App = require('./App');
20 |
21 | var _App2 = _interopRequireDefault(_App);
22 |
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24 |
25 | function template(content) {
26 | return '\n \n \n \n wasm-opencc\u5F00\u653E\u4E2D\u6587\u8F6C\u6362wasm\u7248\u672C\uFF0C\u53EF\u5728\u6D4F\u89C8\u5668\u4E2D\u76F4\u63A5\u8FD0\u884C\u3002\n \n \n \n \n ' + content + '
\n \n \n \n \n ';
27 | }
28 |
29 | function main() {
30 | var content = _server2.default.renderToString(_react2.default.createElement(_App2.default, null));
31 |
32 | _fs2.default.writeFile(_path2.default.resolve(__dirname, '../index.html'), template(content), function (err) {
33 | if (err) {
34 | throw err;
35 | }
36 | });
37 | }
38 |
39 | main();
--------------------------------------------------------------------------------
/wasm/src/__tests__/ConfigParser.spec.js:
--------------------------------------------------------------------------------
1 | const { parse } = require('../ConfigParser')
2 |
3 | const config = {
4 | "name": "Traditional Chinese (Taiwan standard) to Simplified Chinese (with phrases)",
5 | "segmentation": {
6 | "type": "mmseg",
7 | "dict": {
8 | "type": "ocd",
9 | "file": "TSPhrases.ocd"
10 | }
11 | },
12 | "conversion_chain": [{
13 | "dict": {
14 | "type": "group",
15 | "dicts": [{
16 | "type": "ocd",
17 | "file": "TWVariantsRevPhrases.ocd"
18 | }, {
19 | "type": "ocd",
20 | "file": "TWVariantsRev.ocd"
21 | }]
22 | }
23 | }, {
24 | "dict": {
25 | "type": "ocd",
26 | "file": "TWPhrasesRev.ocd"
27 | }
28 | }, {
29 | "dict": {
30 | "type": "group",
31 | "dicts": [{
32 | "type": "ocd",
33 | "file": "TSPhrases.ocd"
34 | }, {
35 | "type": "ocd",
36 | "file": "TSCharacters.ocd"
37 | }]
38 | }
39 | }]
40 | }
41 |
42 | describe('ConfigParser', () => {
43 | describe('parse', () => {
44 | it('should parse content correctly', () => {
45 | const { segmentation, convertionChain } = parse(config)
46 |
47 | expect(typeof segmentation === 'string').toBe(true)
48 | expect(Array.isArray(convertionChain)).toBe(true)
49 |
50 | convertionChain.forEach(i => {
51 | expect(Array.isArray(convertionChain) || typeof convertionChain === 'string').toBe(true)
52 | })
53 | })
54 | })
55 | })
56 |
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/Visitor.h:
--------------------------------------------------------------------------------
1 |
2 | /******************************************************************************
3 | *
4 | * file: Visitor.h
5 | *
6 | * Copyright (c) 2003, Michael E. Smoot .
7 | * All rights reverved.
8 | *
9 | * See the file COPYING in the top directory of this distribution for
10 | * more information.
11 | *
12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 | * DEALINGS IN THE SOFTWARE.
19 | *
20 | *****************************************************************************/
21 |
22 |
23 | #ifndef TCLAP_VISITOR_H
24 | #define TCLAP_VISITOR_H
25 |
26 | namespace TCLAP {
27 |
28 | /**
29 | * A base class that defines the interface for visitors.
30 | */
31 | class Visitor
32 | {
33 | public:
34 |
35 | /**
36 | * Constructor. Does nothing.
37 | */
38 | Visitor() { }
39 |
40 | /**
41 | * Destructor. Does nothing.
42 | */
43 | virtual ~Visitor() { }
44 |
45 | /**
46 | * Does nothing. Should be overridden by child.
47 | */
48 | virtual void visit() { }
49 | };
50 |
51 | }
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/node/demo.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Example of Node.js API.
4 | *
5 | * @license
6 | * Open Chinese Convert
7 | *
8 | * Copyright 2010-2014 BYVoid
9 | *
10 | * Licensed under the Apache License, Version 2.0 (the "License");
11 | * you may not use this file except in compliance with the License.
12 | * You may obtain a copy of the License at
13 | *
14 | * http://www.apache.org/licenses/LICENSE-2.0
15 | *
16 | * Unless required by applicable law or agreed to in writing, software
17 | * distributed under the License is distributed on an "AS IS" BASIS,
18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | * See the License for the specific language governing permissions and
20 | * limitations under the License.
21 | */
22 |
23 | /**
24 | * @example node/demo.js
25 | * This is an example of how to use the Node.js API.
26 | */
27 |
28 | // In your project you should replace './opencc' with 'opencc'
29 | const OpenCC = require('./opencc');
30 |
31 | console.log('OpenCC version', OpenCC.version);
32 |
33 | // Load the default Simplified to Traditional config
34 | const opencc = new OpenCC('s2t.json');
35 |
36 | // Sync API
37 | const converted = opencc.convertSync("汉字");
38 | console.log(converted);
39 |
40 | // Async API
41 | opencc.convert("汉字", (err, converted) => {
42 | console.log(err, converted);
43 | });
44 |
45 | // Async API with Promise
46 | opencc.convertPromise("汉字").then(converted => {
47 | console.log(converted);
48 | });
49 |
--------------------------------------------------------------------------------
/src/UTF8Util.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "UTF8Util.hpp"
20 |
21 | using namespace opencc;
22 |
23 | void UTF8Util::SkipUtf8Bom(FILE* fp) {
24 | /* UTF-8 BOM is EF BB BF */
25 | if (fp == NULL) {
26 | return;
27 | }
28 | /* If we are not at beginning of file, return */
29 | if (ftell(fp) != 0) {
30 | return;
31 | }
32 |
33 | /* Try to read first 3 bytes */
34 | int bom[3];
35 | int n;
36 | for (n = 0; n <= 2 && (bom[n] = getc(fp)) != EOF; n++) {
37 | }
38 | /* If we can only read <3 bytes, push them back */
39 | /* Or if first 3 bytes is not BOM, push them back */
40 | if ((n < 3) || (bom[0] != 0xEF) || (bom[1] != 0xBB) || (bom[2] != 0xBF)) {
41 | for (n--; n >= 0; n--) {
42 | ungetc(bom[n], fp);
43 | }
44 | }
45 |
46 | /* Otherwise, BOM is already skipped */
47 | }
48 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This file contains a list of people who've made non-trivial
2 | # contribution to the Google C++ Testing Framework project. People
3 | # who commit code to the project are encouraged to add their names
4 | # here. Please keep the list sorted by first names.
5 |
6 | Ajay Joshi
7 | Balázs Dán
8 | Bharat Mediratta
9 | Chandler Carruth
10 | Chris Prince
11 | Chris Taylor
12 | Dan Egnor
13 | Eric Roman
14 | Hady Zalek
15 | Jeffrey Yasskin
16 | Jói Sigurðsson
17 | Keir Mierle
18 | Keith Ray
19 | Kenton Varda
20 | Manuel Klimek
21 | Markus Heule
22 | Mika Raento
23 | Miklós Fazekas
24 | Pasi Valminen
25 | Patrick Hanna
26 | Patrick Riley
27 | Peter Kaminski
28 | Preston Jackson
29 | Rainer Klaffenboeck
30 | Russ Cox
31 | Russ Rufer
32 | Sean Mcafee
33 | Sigurður Ásgeirsson
34 | Tracy Bialik
35 | Vadim Berman
36 | Vlad Losev
37 | Zhanyong Wan
38 |
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/IgnoreRestVisitor.h:
--------------------------------------------------------------------------------
1 |
2 | /******************************************************************************
3 | *
4 | * file: IgnoreRestVisitor.h
5 | *
6 | * Copyright (c) 2003, Michael E. Smoot .
7 | * All rights reverved.
8 | *
9 | * See the file COPYING in the top directory of this distribution for
10 | * more information.
11 | *
12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 | * DEALINGS IN THE SOFTWARE.
19 | *
20 | *****************************************************************************/
21 |
22 |
23 | #ifndef TCLAP_IGNORE_REST_VISITOR_H
24 | #define TCLAP_IGNORE_REST_VISITOR_H
25 |
26 | #include
27 | #include
28 |
29 | namespace TCLAP {
30 |
31 | /**
32 | * A Vistor that tells the CmdLine to begin ignoring arguments after
33 | * this one is parsed.
34 | */
35 | class IgnoreRestVisitor: public Visitor
36 | {
37 | public:
38 |
39 | /**
40 | * Constructor.
41 | */
42 | IgnoreRestVisitor() : Visitor() {}
43 |
44 | /**
45 | * Sets Arg::_ignoreRest.
46 | */
47 | void visit() { Arg::beginIgnoring(); }
48 | };
49 |
50 | }
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2008, Google Inc.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/src/ConversionTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "Conversion.hpp"
20 | #include "DictGroupTestBase.hpp"
21 |
22 | namespace opencc {
23 |
24 | class ConversionTest : public DictGroupTestBase {
25 | protected:
26 | ConversionTest()
27 | : input(utf8("太后的头发干燥")), expected(utf8("太后的頭髮乾燥")) {}
28 |
29 | virtual void SetUp() {
30 | dict = CreateDictGroupForConversion();
31 | conversion = ConversionPtr(new Conversion(dict));
32 | }
33 |
34 | DictPtr dict;
35 | ConversionPtr conversion;
36 | const string input;
37 | const string expected;
38 | };
39 |
40 | TEST_F(ConversionTest, ConvertString) {
41 | const string converted = conversion->Convert(input);
42 | EXPECT_EQ(expected, converted);
43 | }
44 |
45 | TEST_F(ConversionTest, ConvertCString) {
46 | const string converted = conversion->Convert(input.c_str());
47 | EXPECT_EQ(expected, converted);
48 | }
49 |
50 | } // namespace opencc
51 |
--------------------------------------------------------------------------------
/src/MaxMatchSegmentationTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "DictGroupTestBase.hpp"
20 | #include "MaxMatchSegmentation.hpp"
21 |
22 | namespace opencc {
23 |
24 | class MaxMatchSegmentationTest : public DictGroupTestBase {
25 | protected:
26 | MaxMatchSegmentationTest() {}
27 |
28 | virtual void SetUp() {
29 | dict = CreateDictGroupForConversion();
30 | segmenter = SegmentationPtr(new MaxMatchSegmentation(dict));
31 | }
32 |
33 | DictPtr dict;
34 | SegmentationPtr segmenter;
35 | };
36 |
37 | TEST_F(MaxMatchSegmentationTest, Segment) {
38 | const auto& segments = segmenter->Segment(utf8("太后的头发干燥"));
39 | EXPECT_EQ(4, segments->Length());
40 | EXPECT_EQ(utf8("太后"), string(segments->At(0)));
41 | EXPECT_EQ(utf8("的"), string(segments->At(1)));
42 | EXPECT_EQ(utf8("头发"), string(segments->At(2)));
43 | EXPECT_EQ(utf8("干燥"), string(segments->At(3)));
44 | }
45 |
46 | } // namespace opencc
47 |
--------------------------------------------------------------------------------
/deps/rapidjson-0.11/stringbuffer.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_STRINGBUFFER_H_
2 | #define RAPIDJSON_STRINGBUFFER_H_
3 |
4 | #include "rapidjson.h"
5 | #include "internal/stack.h"
6 |
7 | namespace rapidjson {
8 |
9 | //! Represents an in-memory output stream.
10 | /*!
11 | \tparam Encoding Encoding of the stream.
12 | \tparam Allocator type for allocating memory buffer.
13 | \implements Stream
14 | */
15 | template
16 | struct GenericStringBuffer {
17 | typedef typename Encoding::Ch Ch;
18 |
19 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
20 |
21 | void Put(Ch c) { *stack_.template Push() = c; }
22 |
23 | void Clear() { stack_.Clear(); }
24 |
25 | const char* GetString() const {
26 | // Push and pop a null terminator. This is safe.
27 | *stack_.template Push() = '\0';
28 | stack_.template Pop(1);
29 |
30 | return stack_.template Bottom();
31 | }
32 |
33 | size_t Size() const { return stack_.GetSize(); }
34 |
35 | static const size_t kDefaultCapacity = 256;
36 | mutable internal::Stack stack_;
37 | };
38 |
39 | typedef GenericStringBuffer > StringBuffer;
40 |
41 | //! Implement specialized version of PutN() with memset() for better performance.
42 | template<>
43 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) {
44 | memset(stream.stack_.Push(n), c, n * sizeof(c));
45 | }
46 |
47 | } // namespace rapidjson
48 |
49 | #endif // RAPIDJSON_STRINGBUFFER_H_
50 |
--------------------------------------------------------------------------------
/src/DictGroup.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "Dict.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Group of dictionaries
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT DictGroup : public Dict {
30 | public:
31 | DictGroup(const list& dicts);
32 |
33 | static DictGroupPtr NewFromDict(const Dict& dict);
34 |
35 | virtual ~DictGroup();
36 |
37 | virtual size_t KeyMaxLength() const;
38 |
39 | virtual Optional Match(const char* word) const;
40 |
41 | virtual Optional MatchPrefix(const char* word) const;
42 |
43 | virtual vector MatchAllPrefixes(const char* word) const;
44 |
45 | virtual LexiconPtr GetLexicon() const;
46 |
47 | const list GetDicts() const { return dicts; }
48 |
49 | private:
50 | const size_t keyMaxLength;
51 | const list dicts;
52 | };
53 | }
54 |
--------------------------------------------------------------------------------
/src/CmdLineOutput.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "tclap/CmdLine.h"
22 |
23 | class CmdLineOutput : public TCLAP::StdOutput {
24 | public:
25 | virtual void usage(TCLAP::CmdLineInterface& cmd) {
26 | std::cout << std::endl << cmd.getMessage() << std::endl
27 | << "Author: Carbo Kuo " << std::endl
28 | << "Bug Report: http://github.com/BYVoid/OpenCC/issues"
29 | << std::endl << std::endl << "Usage: " << std::endl << std::endl;
30 |
31 | _shortUsage(cmd, std::cout);
32 | std::cout << std::endl;
33 | std::cout << "Options: " << std::endl << std::endl;
34 | _longUsage(cmd, std::cout);
35 | std::cout << std::endl;
36 | }
37 |
38 | virtual void version(TCLAP::CmdLineInterface& cmd) {
39 | std::cout << std::endl << cmd.getMessage() << std::endl
40 | << "Version: " << cmd.getVersion() << std::endl << std::endl;
41 | }
42 | };
43 |
--------------------------------------------------------------------------------
/src/Lexicon.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "DictEntry.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Storage of all entries
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT Lexicon {
30 | public:
31 | Lexicon() {}
32 |
33 | ~Lexicon() {
34 | for (DictEntry* entry : entries) {
35 | delete entry;
36 | }
37 | }
38 |
39 | void Add(DictEntry* entry) { entries.push_back(entry); }
40 |
41 | void Sort() {
42 | std::sort(entries.begin(), entries.end(), DictEntry::PtrLessThan);
43 | }
44 |
45 | const DictEntry* At(size_t index) const { return entries.at(index); }
46 |
47 | size_t Length() const { return entries.size(); }
48 |
49 | vector::const_iterator begin() const { return entries.begin(); }
50 |
51 | vector::const_iterator end() const { return entries.end(); }
52 |
53 | private:
54 | vector entries;
55 | };
56 | }
57 |
--------------------------------------------------------------------------------
/src/Converter.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "Segmentation.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Controller of segmentation and conversion
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT Converter {
30 | public:
31 | Converter(const string& _name, SegmentationPtr _segmentation,
32 | ConversionChainPtr _conversionChain)
33 | : name(_name), segmentation(_segmentation),
34 | conversionChain(_conversionChain) {}
35 |
36 | string Convert(const string& text) const;
37 |
38 | size_t Convert(const char* input, char* output) const;
39 |
40 | const SegmentationPtr GetSegmentation() const { return segmentation; }
41 |
42 | const ConversionChainPtr GetConversionChain() const {
43 | return conversionChain;
44 | }
45 |
46 | private:
47 | const string name;
48 | const SegmentationPtr segmentation;
49 | const ConversionChainPtr conversionChain;
50 | };
51 | }
52 |
--------------------------------------------------------------------------------
/src/BinaryDict.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "SerializableDict.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Binary dictionary for faster deserialization
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT BinaryDict : public SerializableDict {
30 | public:
31 | BinaryDict(const LexiconPtr& _lexicon) : lexicon(_lexicon) {}
32 |
33 | virtual ~BinaryDict() {}
34 |
35 | virtual void SerializeToFile(FILE* fp) const;
36 |
37 | static BinaryDictPtr NewFromFile(FILE* fp);
38 |
39 | const LexiconPtr& GetLexicon() const { return lexicon; }
40 |
41 | size_t KeyMaxLength() const;
42 |
43 | private:
44 | LexiconPtr lexicon;
45 | string keyBuffer;
46 | string valueBuffer;
47 |
48 | void ConstructBuffer(string& keyBuffer, vector& keyOffset,
49 | size_t& keyTotalLength, string& valueBuffer,
50 | vector& valueOffset,
51 | size_t& valueTotalLength) const;
52 | };
53 | }
54 |
--------------------------------------------------------------------------------
/src/DartsDict.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "SerializableDict.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Darts dictionary
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT DartsDict : public Dict, public SerializableDict {
30 | public:
31 | virtual ~DartsDict();
32 |
33 | virtual size_t KeyMaxLength() const;
34 |
35 | virtual Optional Match(const char* word) const;
36 |
37 | virtual Optional MatchPrefix(const char* word) const;
38 |
39 | virtual LexiconPtr GetLexicon() const;
40 |
41 | virtual void SerializeToFile(FILE* fp) const;
42 |
43 | /**
44 | * Constructs a DartsDict from another dictionary.
45 | */
46 | static DartsDictPtr NewFromDict(const Dict& thatDict);
47 |
48 | static DartsDictPtr NewFromFile(FILE* fp);
49 |
50 | private:
51 | DartsDict();
52 |
53 | size_t maxLength;
54 | LexiconPtr lexicon;
55 |
56 | class DartsInternal;
57 | DartsInternal* internal;
58 | };
59 | }
60 |
--------------------------------------------------------------------------------
/src/TextDict.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | #include "Common.hpp"
22 | #include "SerializableDict.hpp"
23 |
24 | namespace opencc {
25 | /**
26 | * Text dictionary
27 | * @ingroup opencc_cpp_api
28 | */
29 | class OPENCC_EXPORT TextDict : public Dict, public SerializableDict {
30 | public:
31 | /**
32 | * Constructor of TextDict.
33 | * _lexicon must be sorted.
34 | */
35 | TextDict(const LexiconPtr& _lexicon);
36 |
37 | virtual ~TextDict();
38 |
39 | virtual size_t KeyMaxLength() const;
40 |
41 | virtual Optional Match(const char* word) const;
42 |
43 | virtual LexiconPtr GetLexicon() const;
44 |
45 | virtual void SerializeToFile(FILE* fp) const;
46 |
47 | /**
48 | * Constructs a TextDict from another dictionary.
49 | */
50 | static TextDictPtr NewFromDict(const Dict& dict);
51 |
52 | static TextDictPtr NewFromFile(FILE* fp);
53 |
54 | static TextDictPtr NewFromSortedFile(FILE* fp);
55 |
56 | private:
57 | const size_t maxLength;
58 | const LexiconPtr lexicon;
59 | };
60 | }
61 |
--------------------------------------------------------------------------------
/wasm/src/__tests__/DictSource.spec.js:
--------------------------------------------------------------------------------
1 | const { DictSource } = require('../DictSource')
2 |
3 | describe('DictSource', () => {
4 | it('should throw when passing invalid source key', (done) => {
5 | try {
6 | new DictSource('INVALID')
7 | } catch (e) {
8 | done()
9 | }
10 | })
11 |
12 | it('should get source file content', (done) => {
13 | const dictSource = new DictSource('s2t.json')
14 |
15 | dictSource.get().then(([a, b]) => {
16 | expect(typeof a).toBe('string')
17 | expect(Array.isArray(b))
18 |
19 | done()
20 | }).catch(err => {
21 | setTimeout(() => {
22 | throw err
23 | })
24 | })
25 | })
26 |
27 | it('should set getSource implmentation by setDictProxy', () => {
28 | const sourceName = 's2t.json'
29 | const dictSource = new DictSource(sourceName)
30 | let called = 0
31 |
32 | dictSource.setDictProxy((name) => {
33 | called += 1
34 | return `${name} content`
35 | })
36 |
37 | dictSource.get().then(([a, b]) => {
38 | expect(called).toBe(3)
39 | expect(typeof a).toBe('string')
40 | expect(Array.isArray(b))
41 |
42 | done()
43 | }).catch(err => {
44 | setTimeout(() => {
45 | throw err
46 | })
47 | })
48 | })
49 |
50 | it('should trigger catch when failing to get source', (done) => {
51 | const sourceName = 's2t.json'
52 | const dictSource = new DictSource(sourceName)
53 | let called = 0
54 |
55 | dictSource.setDictProxy((name) => {
56 | return Promise.reject(new Error('fail'))
57 | })
58 |
59 | dictSource.get().then(([a, b]) => {
60 | throw new Error()
61 | }).catch(err => {
62 | done()
63 | })
64 | })
65 | })
66 |
--------------------------------------------------------------------------------
/node/test.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 | var fs = require('fs');
3 | var OpenCC = require('./opencc');
4 |
5 | var configs = [
6 | 's2t',
7 | 's2tw',
8 | 's2twp',
9 | 't2s',
10 | 'tw2s',
11 | 'tw2sp',
12 | 's2hk',
13 | 'hk2s',
14 | ];
15 |
16 | var testSync = function (config, done) {
17 | var inputName = 'test/testcases/' + config + '.in';
18 | var outputName = 'test/testcases/' + config + '.ans';
19 | var configName = config + '.json';
20 | var opencc = new OpenCC(configName);
21 | var text = fs.readFileSync(inputName, 'utf-8');
22 | var converted = opencc.convertSync(text);
23 | var answer = fs.readFileSync(outputName, 'utf-8');
24 | assert.equal(converted, answer);
25 | done();
26 | };
27 |
28 | var testAsync = function (config, done) {
29 | var inputName = 'test/testcases/' + config + '.in';
30 | var outputName = 'test/testcases/' + config + '.ans';
31 | var configName = config + '.json';
32 | var opencc = new OpenCC(configName);
33 | fs.readFile(inputName, 'utf-8', function (err, text) {
34 | if (err) return done(err);
35 | opencc.convert(text, function (err, converted) {
36 | if (err) return done(err);
37 | fs.readFile(outputName, 'utf-8', function (err, answer) {
38 | if (err) return done(err);
39 | assert.equal(converted, answer);
40 | done();
41 | });
42 | });
43 | });
44 | };
45 |
46 | describe('Sync API', function () {
47 | configs.forEach(function (config) {
48 | it(config, function (done) {
49 | testSync(config, done);
50 | });
51 | });
52 | });
53 |
54 | describe('Async API', function () {
55 | configs.forEach(function (config) {
56 | it(config, function (done) {
57 | testAsync(config, done);
58 | });
59 | });
60 | });
61 |
--------------------------------------------------------------------------------
/src/Conversion.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "Conversion.hpp"
20 | #include "Dict.hpp"
21 |
22 | using namespace opencc;
23 |
24 | string Conversion::Convert(const char* phrase) const {
25 | std::ostringstream buffer;
26 | for (const char* pstr = phrase; *pstr != '\0';) {
27 | Optional matched = dict->MatchPrefix(pstr);
28 | size_t matchedLength;
29 | if (matched.IsNull()) {
30 | matchedLength = UTF8Util::NextCharLength(pstr);
31 | buffer << UTF8Util::FromSubstr(pstr, matchedLength);
32 | } else {
33 | matchedLength = matched.Get()->KeyLength();
34 | buffer << matched.Get()->GetDefault();
35 | }
36 | pstr += matchedLength;
37 | }
38 | return buffer.str();
39 | }
40 |
41 | string Conversion::Convert(const string& phrase) const {
42 | return Convert(phrase.c_str());
43 | }
44 |
45 | SegmentsPtr Conversion::Convert(const SegmentsPtr& input) const {
46 | SegmentsPtr output(new Segments);
47 | for (const char* segment : *input) {
48 | output->AddSegment(Convert(segment));
49 | }
50 | return output;
51 | }
52 |
--------------------------------------------------------------------------------
/docs/dict/HKVariantsRevPhrases.txt:
--------------------------------------------------------------------------------
1 | 七星巖 七星巖
2 | 世胄 世胄
3 | 介胄 介冑
4 | 傅巖 傅巖
5 | 免胄 免冑
6 | 冠胄 冠冑
7 | 千巖競秀 千巖競秀
8 | 千巖萬壑 千巖萬壑
9 | 千巖萬谷 千巖萬谷
10 | 台山 台山
11 | 台州 台州
12 | 台州地區 台州地區
13 | 台州市 台州市
14 | 名胄 名胄
15 | 國胄 國胄
16 | 圍巖 圍巖
17 | 地胄 地胄
18 | 壓胄子 壓冑子
19 | 士胄 士胄
20 | 大巖桐 大巖桐
21 | 天台女 天台女
22 | 天台宗 天台宗
23 | 天台山 天台山
24 | 天台縣 天台縣
25 | 天潢貴胄 天潢貴胄
26 | 奇巖 奇巖
27 | 寶胄 寶胄
28 | 小巖洞 小巖洞
29 | 岫巖縣 岫巖縣
30 | 峯巖 峯巖
31 | 嵌巖 嵌巖
32 | 巉巖 巉巖
33 | 巖壁 巖壁
34 | 巖居 巖居
35 | 巖居穴處 巖居穴處
36 | 巖居谷飲 巖居谷飲
37 | 巖岸 巖岸
38 | 巖巉 巖巉
39 | 巖巖 巖巖
40 | 巖徼 巖徼
41 | 巖手縣 巖手縣
42 | 巖村 巖村
43 | 巖洞 巖洞
44 | 巖流圈 巖流圈
45 | 巖牆 巖牆
46 | 巖牆之下 巖牆之下
47 | 巖畫 巖畫
48 | 巖穴 巖穴
49 | 巖穴之士 巖穴之士
50 | 巖薔薇 巖薔薇
51 | 巖邑 巖邑
52 | 巖郎 巖郎
53 | 巖阻 巖阻
54 | 巖陛 巖陛
55 | 帝胄 帝胄
56 | 幽巖 幽巖
57 | 幽棲巖谷 幽棲巖谷
58 | 懸巖 懸巖
59 | 懸巖峭壁 懸巖峭壁
60 | 懸胄 懸冑
61 | 攀巖 攀巖
62 | 支胄 支胄
63 | 教胄 教胄
64 | 景胄 景胄
65 | 望胄 望胄
66 | 末胄 末胄
67 | 村胄 村胄
68 | 枕巖漱流 枕巖漱流
69 | 枝胄 枝胄
70 | 氏胄 氏胄
71 | 洪胄 洪胄
72 | 浙江天台縣 浙江天台縣
73 | 清胄 清胄
74 | 灰巖殘丘 灰巖殘丘
75 | 玄胄 玄胄
76 | 甲胄 甲冑
77 | 甲胄魚類 甲冑魚類
78 | 皇胄 皇胄
79 | 石灰巖洞 石灰巖洞
80 | 神胄 神胄
81 | 簪纓世胄 簪纓世胄
82 | 系胄 系胄
83 | 紅巖 紅巖
84 | 絕巖 絕巖
85 | 緒胄 緒胄
86 | 纂胄 纂胄
87 | 胄嗣 胄嗣
88 | 胄子 胄子
89 | 胄序 胄序
90 | 胄族 胄族
91 | 胄甲 冑甲
92 | 胄監 胄監
93 | 胄科 冑科
94 | 胄緒 胄緒
95 | 胄胤 胄胤
96 | 胄裔 胄裔
97 | 胄裔繁衍 胄裔繁衍
98 | 胄閥 胄閥
99 | 胡雪巖 胡雪巖
100 | 胤胄 胤胄
101 | 苗胄 苗胄
102 | 英胄 英胄
103 | 華胄 華胄
104 | 血胄 血胄
105 | 裔胄 裔胄
106 | 訓胄 訓胄
107 | 試胄 試胄
108 | 豪門貴胄 豪門貴胄
109 | 貝胄 貝冑
110 | 貴胄 貴胄
111 | 賢胄 賢胄
112 | 躬擐甲胄 躬擐甲冑
113 | 遐胄 遐胄
114 | 遙胄 遙胄
115 | 遙遙華胄 遙遙華胄
116 | 遠胄 遠胄
117 | 遺胄 遺胄
118 | 重巖疊嶂 重巖疊嶂
119 | 金胄 金胄
120 | 鎧胄 鎧冑
121 | 鑿巖 鑿巖
122 | 門胄 門胄
123 | 雲巖區 雲巖區
124 | 非層巖 非層巖
125 | 韓侂胄 韓侂冑
126 | 飮胄 飮冑
127 | 骨巖巖 骨巖巖
128 | 高胄 高胄
129 | 魚胄 魚冑
130 | 鮮胄 鮮胄
131 | 鴻胄 鴻胄
132 | 黃巖區 黃巖區
133 | 黃巖島 黃巖島
134 | 黃炎貴胄 黃炎貴胄
135 | 齒胄 齒胄
136 | 龍巖 龍巖
137 | 龍巖市 龍巖市
138 | 龍巖村 龍巖村
139 | 龍胄 龍胄
140 |
--------------------------------------------------------------------------------
/data/dictionary/HKVariantsRevPhrases.txt:
--------------------------------------------------------------------------------
1 | 七星巖 七星巖
2 | 世胄 世胄
3 | 介胄 介冑
4 | 傅巖 傅巖
5 | 免胄 免冑
6 | 冠胄 冠冑
7 | 千巖競秀 千巖競秀
8 | 千巖萬壑 千巖萬壑
9 | 千巖萬谷 千巖萬谷
10 | 台山 台山
11 | 台州 台州
12 | 台州地區 台州地區
13 | 台州市 台州市
14 | 名胄 名胄
15 | 國胄 國胄
16 | 圍巖 圍巖
17 | 地胄 地胄
18 | 壓胄子 壓冑子
19 | 士胄 士胄
20 | 大巖桐 大巖桐
21 | 天台女 天台女
22 | 天台宗 天台宗
23 | 天台山 天台山
24 | 天台縣 天台縣
25 | 天潢貴胄 天潢貴胄
26 | 奇巖 奇巖
27 | 寶胄 寶胄
28 | 小巖洞 小巖洞
29 | 岫巖縣 岫巖縣
30 | 峯巖 峯巖
31 | 嵌巖 嵌巖
32 | 巉巖 巉巖
33 | 巖壁 巖壁
34 | 巖居 巖居
35 | 巖居穴處 巖居穴處
36 | 巖居谷飲 巖居谷飲
37 | 巖岸 巖岸
38 | 巖巉 巖巉
39 | 巖巖 巖巖
40 | 巖徼 巖徼
41 | 巖手縣 巖手縣
42 | 巖村 巖村
43 | 巖洞 巖洞
44 | 巖流圈 巖流圈
45 | 巖牆 巖牆
46 | 巖牆之下 巖牆之下
47 | 巖畫 巖畫
48 | 巖穴 巖穴
49 | 巖穴之士 巖穴之士
50 | 巖薔薇 巖薔薇
51 | 巖邑 巖邑
52 | 巖郎 巖郎
53 | 巖阻 巖阻
54 | 巖陛 巖陛
55 | 帝胄 帝胄
56 | 幽巖 幽巖
57 | 幽棲巖谷 幽棲巖谷
58 | 懸巖 懸巖
59 | 懸巖峭壁 懸巖峭壁
60 | 懸胄 懸冑
61 | 攀巖 攀巖
62 | 支胄 支胄
63 | 教胄 教胄
64 | 景胄 景胄
65 | 望胄 望胄
66 | 末胄 末胄
67 | 村胄 村胄
68 | 枕巖漱流 枕巖漱流
69 | 枝胄 枝胄
70 | 氏胄 氏胄
71 | 洪胄 洪胄
72 | 浙江天台縣 浙江天台縣
73 | 清胄 清胄
74 | 灰巖殘丘 灰巖殘丘
75 | 玄胄 玄胄
76 | 甲胄 甲冑
77 | 甲胄魚類 甲冑魚類
78 | 皇胄 皇胄
79 | 石灰巖洞 石灰巖洞
80 | 神胄 神胄
81 | 簪纓世胄 簪纓世胄
82 | 系胄 系胄
83 | 紅巖 紅巖
84 | 絕巖 絕巖
85 | 緒胄 緒胄
86 | 纂胄 纂胄
87 | 胄嗣 胄嗣
88 | 胄子 胄子
89 | 胄序 胄序
90 | 胄族 胄族
91 | 胄甲 冑甲
92 | 胄監 胄監
93 | 胄科 冑科
94 | 胄緒 胄緒
95 | 胄胤 胄胤
96 | 胄裔 胄裔
97 | 胄裔繁衍 胄裔繁衍
98 | 胄閥 胄閥
99 | 胡雪巖 胡雪巖
100 | 胤胄 胤胄
101 | 苗胄 苗胄
102 | 英胄 英胄
103 | 華胄 華胄
104 | 血胄 血胄
105 | 裔胄 裔胄
106 | 訓胄 訓胄
107 | 試胄 試胄
108 | 豪門貴胄 豪門貴胄
109 | 貝胄 貝冑
110 | 貴胄 貴胄
111 | 賢胄 賢胄
112 | 躬擐甲胄 躬擐甲冑
113 | 遐胄 遐胄
114 | 遙胄 遙胄
115 | 遙遙華胄 遙遙華胄
116 | 遠胄 遠胄
117 | 遺胄 遺胄
118 | 重巖疊嶂 重巖疊嶂
119 | 金胄 金胄
120 | 鎧胄 鎧冑
121 | 鑿巖 鑿巖
122 | 門胄 門胄
123 | 雲巖區 雲巖區
124 | 非層巖 非層巖
125 | 韓侂胄 韓侂冑
126 | 飮胄 飮冑
127 | 骨巖巖 骨巖巖
128 | 高胄 高胄
129 | 魚胄 魚冑
130 | 鮮胄 鮮胄
131 | 鴻胄 鴻胄
132 | 黃巖區 黃巖區
133 | 黃巖島 黃巖島
134 | 黃炎貴胄 黃炎貴胄
135 | 齒胄 齒胄
136 | 龍巖 龍巖
137 | 龍巖市 龍巖市
138 | 龍巖村 龍巖村
139 | 龍胄 龍胄
140 |
--------------------------------------------------------------------------------
/wasm/dist/dict/HKVariantsRevPhrases.txt:
--------------------------------------------------------------------------------
1 | 七星巖 七星巖
2 | 世胄 世胄
3 | 介胄 介冑
4 | 傅巖 傅巖
5 | 免胄 免冑
6 | 冠胄 冠冑
7 | 千巖競秀 千巖競秀
8 | 千巖萬壑 千巖萬壑
9 | 千巖萬谷 千巖萬谷
10 | 台山 台山
11 | 台州 台州
12 | 台州地區 台州地區
13 | 台州市 台州市
14 | 名胄 名胄
15 | 國胄 國胄
16 | 圍巖 圍巖
17 | 地胄 地胄
18 | 壓胄子 壓冑子
19 | 士胄 士胄
20 | 大巖桐 大巖桐
21 | 天台女 天台女
22 | 天台宗 天台宗
23 | 天台山 天台山
24 | 天台縣 天台縣
25 | 天潢貴胄 天潢貴胄
26 | 奇巖 奇巖
27 | 寶胄 寶胄
28 | 小巖洞 小巖洞
29 | 岫巖縣 岫巖縣
30 | 峯巖 峯巖
31 | 嵌巖 嵌巖
32 | 巉巖 巉巖
33 | 巖壁 巖壁
34 | 巖居 巖居
35 | 巖居穴處 巖居穴處
36 | 巖居谷飲 巖居谷飲
37 | 巖岸 巖岸
38 | 巖巉 巖巉
39 | 巖巖 巖巖
40 | 巖徼 巖徼
41 | 巖手縣 巖手縣
42 | 巖村 巖村
43 | 巖洞 巖洞
44 | 巖流圈 巖流圈
45 | 巖牆 巖牆
46 | 巖牆之下 巖牆之下
47 | 巖畫 巖畫
48 | 巖穴 巖穴
49 | 巖穴之士 巖穴之士
50 | 巖薔薇 巖薔薇
51 | 巖邑 巖邑
52 | 巖郎 巖郎
53 | 巖阻 巖阻
54 | 巖陛 巖陛
55 | 帝胄 帝胄
56 | 幽巖 幽巖
57 | 幽棲巖谷 幽棲巖谷
58 | 懸巖 懸巖
59 | 懸巖峭壁 懸巖峭壁
60 | 懸胄 懸冑
61 | 攀巖 攀巖
62 | 支胄 支胄
63 | 教胄 教胄
64 | 景胄 景胄
65 | 望胄 望胄
66 | 末胄 末胄
67 | 村胄 村胄
68 | 枕巖漱流 枕巖漱流
69 | 枝胄 枝胄
70 | 氏胄 氏胄
71 | 洪胄 洪胄
72 | 浙江天台縣 浙江天台縣
73 | 清胄 清胄
74 | 灰巖殘丘 灰巖殘丘
75 | 玄胄 玄胄
76 | 甲胄 甲冑
77 | 甲胄魚類 甲冑魚類
78 | 皇胄 皇胄
79 | 石灰巖洞 石灰巖洞
80 | 神胄 神胄
81 | 簪纓世胄 簪纓世胄
82 | 系胄 系胄
83 | 紅巖 紅巖
84 | 絕巖 絕巖
85 | 緒胄 緒胄
86 | 纂胄 纂胄
87 | 胄嗣 胄嗣
88 | 胄子 胄子
89 | 胄序 胄序
90 | 胄族 胄族
91 | 胄甲 冑甲
92 | 胄監 胄監
93 | 胄科 冑科
94 | 胄緒 胄緒
95 | 胄胤 胄胤
96 | 胄裔 胄裔
97 | 胄裔繁衍 胄裔繁衍
98 | 胄閥 胄閥
99 | 胡雪巖 胡雪巖
100 | 胤胄 胤胄
101 | 苗胄 苗胄
102 | 英胄 英胄
103 | 華胄 華胄
104 | 血胄 血胄
105 | 裔胄 裔胄
106 | 訓胄 訓胄
107 | 試胄 試胄
108 | 豪門貴胄 豪門貴胄
109 | 貝胄 貝冑
110 | 貴胄 貴胄
111 | 賢胄 賢胄
112 | 躬擐甲胄 躬擐甲冑
113 | 遐胄 遐胄
114 | 遙胄 遙胄
115 | 遙遙華胄 遙遙華胄
116 | 遠胄 遠胄
117 | 遺胄 遺胄
118 | 重巖疊嶂 重巖疊嶂
119 | 金胄 金胄
120 | 鎧胄 鎧冑
121 | 鑿巖 鑿巖
122 | 門胄 門胄
123 | 雲巖區 雲巖區
124 | 非層巖 非層巖
125 | 韓侂胄 韓侂冑
126 | 飮胄 飮冑
127 | 骨巖巖 骨巖巖
128 | 高胄 高胄
129 | 魚胄 魚冑
130 | 鮮胄 鮮胄
131 | 鴻胄 鴻胄
132 | 黃巖區 黃巖區
133 | 黃巖島 黃巖島
134 | 黃炎貴胄 黃炎貴胄
135 | 齒胄 齒胄
136 | 龍巖 龍巖
137 | 龍巖市 龍巖市
138 | 龍巖村 龍巖村
139 | 龍胄 龍胄
140 |
--------------------------------------------------------------------------------
/wasm/docs/dict/HKVariantsRevPhrases.txt:
--------------------------------------------------------------------------------
1 | 七星巖 七星巖
2 | 世胄 世胄
3 | 介胄 介冑
4 | 傅巖 傅巖
5 | 免胄 免冑
6 | 冠胄 冠冑
7 | 千巖競秀 千巖競秀
8 | 千巖萬壑 千巖萬壑
9 | 千巖萬谷 千巖萬谷
10 | 台山 台山
11 | 台州 台州
12 | 台州地區 台州地區
13 | 台州市 台州市
14 | 名胄 名胄
15 | 國胄 國胄
16 | 圍巖 圍巖
17 | 地胄 地胄
18 | 壓胄子 壓冑子
19 | 士胄 士胄
20 | 大巖桐 大巖桐
21 | 天台女 天台女
22 | 天台宗 天台宗
23 | 天台山 天台山
24 | 天台縣 天台縣
25 | 天潢貴胄 天潢貴胄
26 | 奇巖 奇巖
27 | 寶胄 寶胄
28 | 小巖洞 小巖洞
29 | 岫巖縣 岫巖縣
30 | 峯巖 峯巖
31 | 嵌巖 嵌巖
32 | 巉巖 巉巖
33 | 巖壁 巖壁
34 | 巖居 巖居
35 | 巖居穴處 巖居穴處
36 | 巖居谷飲 巖居谷飲
37 | 巖岸 巖岸
38 | 巖巉 巖巉
39 | 巖巖 巖巖
40 | 巖徼 巖徼
41 | 巖手縣 巖手縣
42 | 巖村 巖村
43 | 巖洞 巖洞
44 | 巖流圈 巖流圈
45 | 巖牆 巖牆
46 | 巖牆之下 巖牆之下
47 | 巖畫 巖畫
48 | 巖穴 巖穴
49 | 巖穴之士 巖穴之士
50 | 巖薔薇 巖薔薇
51 | 巖邑 巖邑
52 | 巖郎 巖郎
53 | 巖阻 巖阻
54 | 巖陛 巖陛
55 | 帝胄 帝胄
56 | 幽巖 幽巖
57 | 幽棲巖谷 幽棲巖谷
58 | 懸巖 懸巖
59 | 懸巖峭壁 懸巖峭壁
60 | 懸胄 懸冑
61 | 攀巖 攀巖
62 | 支胄 支胄
63 | 教胄 教胄
64 | 景胄 景胄
65 | 望胄 望胄
66 | 末胄 末胄
67 | 村胄 村胄
68 | 枕巖漱流 枕巖漱流
69 | 枝胄 枝胄
70 | 氏胄 氏胄
71 | 洪胄 洪胄
72 | 浙江天台縣 浙江天台縣
73 | 清胄 清胄
74 | 灰巖殘丘 灰巖殘丘
75 | 玄胄 玄胄
76 | 甲胄 甲冑
77 | 甲胄魚類 甲冑魚類
78 | 皇胄 皇胄
79 | 石灰巖洞 石灰巖洞
80 | 神胄 神胄
81 | 簪纓世胄 簪纓世胄
82 | 系胄 系胄
83 | 紅巖 紅巖
84 | 絕巖 絕巖
85 | 緒胄 緒胄
86 | 纂胄 纂胄
87 | 胄嗣 胄嗣
88 | 胄子 胄子
89 | 胄序 胄序
90 | 胄族 胄族
91 | 胄甲 冑甲
92 | 胄監 胄監
93 | 胄科 冑科
94 | 胄緒 胄緒
95 | 胄胤 胄胤
96 | 胄裔 胄裔
97 | 胄裔繁衍 胄裔繁衍
98 | 胄閥 胄閥
99 | 胡雪巖 胡雪巖
100 | 胤胄 胤胄
101 | 苗胄 苗胄
102 | 英胄 英胄
103 | 華胄 華胄
104 | 血胄 血胄
105 | 裔胄 裔胄
106 | 訓胄 訓胄
107 | 試胄 試胄
108 | 豪門貴胄 豪門貴胄
109 | 貝胄 貝冑
110 | 貴胄 貴胄
111 | 賢胄 賢胄
112 | 躬擐甲胄 躬擐甲冑
113 | 遐胄 遐胄
114 | 遙胄 遙胄
115 | 遙遙華胄 遙遙華胄
116 | 遠胄 遠胄
117 | 遺胄 遺胄
118 | 重巖疊嶂 重巖疊嶂
119 | 金胄 金胄
120 | 鎧胄 鎧冑
121 | 鑿巖 鑿巖
122 | 門胄 門胄
123 | 雲巖區 雲巖區
124 | 非層巖 非層巖
125 | 韓侂胄 韓侂冑
126 | 飮胄 飮冑
127 | 骨巖巖 骨巖巖
128 | 高胄 高胄
129 | 魚胄 魚冑
130 | 鮮胄 鮮胄
131 | 鴻胄 鴻胄
132 | 黃巖區 黃巖區
133 | 黃巖島 黃巖島
134 | 黃炎貴胄 黃炎貴胄
135 | 齒胄 齒胄
136 | 龍巖 龍巖
137 | 龍巖市 龍巖市
138 | 龍巖村 龍巖村
139 | 龍胄 龍胄
140 |
--------------------------------------------------------------------------------
/wasm/generated/dict/HKVariantsRevPhrases.txt:
--------------------------------------------------------------------------------
1 | 七星巖 七星巖
2 | 世胄 世胄
3 | 介胄 介冑
4 | 傅巖 傅巖
5 | 免胄 免冑
6 | 冠胄 冠冑
7 | 千巖競秀 千巖競秀
8 | 千巖萬壑 千巖萬壑
9 | 千巖萬谷 千巖萬谷
10 | 台山 台山
11 | 台州 台州
12 | 台州地區 台州地區
13 | 台州市 台州市
14 | 名胄 名胄
15 | 國胄 國胄
16 | 圍巖 圍巖
17 | 地胄 地胄
18 | 壓胄子 壓冑子
19 | 士胄 士胄
20 | 大巖桐 大巖桐
21 | 天台女 天台女
22 | 天台宗 天台宗
23 | 天台山 天台山
24 | 天台縣 天台縣
25 | 天潢貴胄 天潢貴胄
26 | 奇巖 奇巖
27 | 寶胄 寶胄
28 | 小巖洞 小巖洞
29 | 岫巖縣 岫巖縣
30 | 峯巖 峯巖
31 | 嵌巖 嵌巖
32 | 巉巖 巉巖
33 | 巖壁 巖壁
34 | 巖居 巖居
35 | 巖居穴處 巖居穴處
36 | 巖居谷飲 巖居谷飲
37 | 巖岸 巖岸
38 | 巖巉 巖巉
39 | 巖巖 巖巖
40 | 巖徼 巖徼
41 | 巖手縣 巖手縣
42 | 巖村 巖村
43 | 巖洞 巖洞
44 | 巖流圈 巖流圈
45 | 巖牆 巖牆
46 | 巖牆之下 巖牆之下
47 | 巖畫 巖畫
48 | 巖穴 巖穴
49 | 巖穴之士 巖穴之士
50 | 巖薔薇 巖薔薇
51 | 巖邑 巖邑
52 | 巖郎 巖郎
53 | 巖阻 巖阻
54 | 巖陛 巖陛
55 | 帝胄 帝胄
56 | 幽巖 幽巖
57 | 幽棲巖谷 幽棲巖谷
58 | 懸巖 懸巖
59 | 懸巖峭壁 懸巖峭壁
60 | 懸胄 懸冑
61 | 攀巖 攀巖
62 | 支胄 支胄
63 | 教胄 教胄
64 | 景胄 景胄
65 | 望胄 望胄
66 | 末胄 末胄
67 | 村胄 村胄
68 | 枕巖漱流 枕巖漱流
69 | 枝胄 枝胄
70 | 氏胄 氏胄
71 | 洪胄 洪胄
72 | 浙江天台縣 浙江天台縣
73 | 清胄 清胄
74 | 灰巖殘丘 灰巖殘丘
75 | 玄胄 玄胄
76 | 甲胄 甲冑
77 | 甲胄魚類 甲冑魚類
78 | 皇胄 皇胄
79 | 石灰巖洞 石灰巖洞
80 | 神胄 神胄
81 | 簪纓世胄 簪纓世胄
82 | 系胄 系胄
83 | 紅巖 紅巖
84 | 絕巖 絕巖
85 | 緒胄 緒胄
86 | 纂胄 纂胄
87 | 胄嗣 胄嗣
88 | 胄子 胄子
89 | 胄序 胄序
90 | 胄族 胄族
91 | 胄甲 冑甲
92 | 胄監 胄監
93 | 胄科 冑科
94 | 胄緒 胄緒
95 | 胄胤 胄胤
96 | 胄裔 胄裔
97 | 胄裔繁衍 胄裔繁衍
98 | 胄閥 胄閥
99 | 胡雪巖 胡雪巖
100 | 胤胄 胤胄
101 | 苗胄 苗胄
102 | 英胄 英胄
103 | 華胄 華胄
104 | 血胄 血胄
105 | 裔胄 裔胄
106 | 訓胄 訓胄
107 | 試胄 試胄
108 | 豪門貴胄 豪門貴胄
109 | 貝胄 貝冑
110 | 貴胄 貴胄
111 | 賢胄 賢胄
112 | 躬擐甲胄 躬擐甲冑
113 | 遐胄 遐胄
114 | 遙胄 遙胄
115 | 遙遙華胄 遙遙華胄
116 | 遠胄 遠胄
117 | 遺胄 遺胄
118 | 重巖疊嶂 重巖疊嶂
119 | 金胄 金胄
120 | 鎧胄 鎧冑
121 | 鑿巖 鑿巖
122 | 門胄 門胄
123 | 雲巖區 雲巖區
124 | 非層巖 非層巖
125 | 韓侂胄 韓侂冑
126 | 飮胄 飮冑
127 | 骨巖巖 骨巖巖
128 | 高胄 高胄
129 | 魚胄 魚冑
130 | 鮮胄 鮮胄
131 | 鴻胄 鴻胄
132 | 黃巖區 黃巖區
133 | 黃巖島 黃巖島
134 | 黃炎貴胄 黃炎貴胄
135 | 齒胄 齒胄
136 | 龍巖 龍巖
137 | 龍巖市 龍巖市
138 | 龍巖村 龍巖村
139 | 龍胄 龍胄
140 |
--------------------------------------------------------------------------------
/src/MaxMatchSegmentation.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "MaxMatchSegmentation.hpp"
20 |
21 | using namespace opencc;
22 |
23 | SegmentsPtr MaxMatchSegmentation::Segment(const string& text) const {
24 | SegmentsPtr segments(new Segments);
25 | const char* segStart = text.c_str();
26 | size_t segLength = 0;
27 | auto clearBuffer = [&segments, &segStart, &segLength]() {
28 | if (segLength > 0) {
29 | segments->AddSegment(UTF8Util::FromSubstr(segStart, segLength));
30 | segLength = 0;
31 | }
32 | };
33 | for (const char* pstr = text.c_str(); *pstr != '\0';) {
34 | const Optional& matched = dict->MatchPrefix(pstr);
35 | size_t matchedLength;
36 | if (matched.IsNull()) {
37 | matchedLength = UTF8Util::NextCharLength(pstr);
38 | segLength += matchedLength;
39 | } else {
40 | clearBuffer();
41 | matchedLength = matched.Get()->KeyLength();
42 | segments->AddSegment(matched.Get()->Key());
43 | segStart = pstr + matchedLength;
44 | }
45 | pstr += matchedLength;
46 | }
47 | clearBuffer();
48 | return segments;
49 | }
50 |
--------------------------------------------------------------------------------
/data/scheme/variant.txt:
--------------------------------------------------------------------------------
1 | 丟 丟 丢
2 | 並 並 竝
3 | 幷 并 幷
4 | 僞 偽 僞
5 | 兌 兌 兑
6 | 內 內 内
7 | 冊 冊 册
8 | 冢 冢 塚
9 | 剁 剁 刴
10 | 剋 剋 尅
11 | 劃 劃 𠟱 劐 𠜻
12 | 劍 劍 劎 劒 剣 剱 劔
13 | 匯 匯 滙
14 | 升 升 陞 阩 𧿘
15 | 只 只 𠮡 𠷓
16 | 呆 呆 獃
17 | 啓 啓 啟
18 | 回 回 囘 囬
19 | 囪 囪 囱
20 | 垛 垛 垜
21 | 埼 埼 碕 崎 隑
22 | 壩 垻 壩
23 | 壺 壷 壺
24 | 夠 够 夠
25 | 嫋 嫋 嬝
26 | 嬀 媯 嬀
27 | 嬤 嬤 嬷
28 | 崙 崙 崘
29 | 嶽 嶽 𡶓 𡶳 𡴳
30 | 廁 廁 厠
31 | 愨 愨 慤 𣪎
32 | 戶 戶 户 戸
33 | 挆 挆 挅
34 | 捂 捂 摀
35 | 擔 擔 担
36 | 擡 擡 抬
37 | 曬 曬 晒
38 | 朵 朵 朶
39 | 杴 杴 鍁 𣞘
40 | 查 査 查
41 | 棱 棱 稜
42 | 殼 㱿 殻 殼 㱿 𣪊
43 | 污 汙 污 汚
44 | 泄 泄 洩
45 | 涌 湧 涌
46 | 溯 溯 泝
47 | 潙 溈 潙
48 | 煙 煙 烟
49 | 爲 爲 為
50 | 牀 牀 床
51 | 牆 牆 墻
52 | 獎 獎 奬 𤟌 㢡
53 | 產 產 産
54 | 畫 畫 畵 𤱪 𨽶 𤲯
55 | 瘻 瘻 瘺
56 | 癡 癡 痴
57 | 衆 衆 眾
58 | 禿 禿 秃
59 | 秋 秋 龝 秌
60 | 秘 祕 秘
61 | 竈 竈 灶
62 | 累 累 纍
63 | 絕 絕 絶 𢇍 𠤉
64 | 絛 絛 縧
65 | 綠 綠 緑
66 | 綫 線 綫
67 | 繃 繃 綳
68 | 繡 繡 綉
69 | 繮 繮 韁
70 | 罈 罈 墰 罎 壜
71 | 罵 罵 駡
72 | 羣 羣 群
73 | 考 考 攷
74 | 脣 脣 唇
75 | 蓴 蓴 蒓
76 | 蘊 蘊 藴
77 | 裏 裏 裡
78 | 說 說 説
79 | 謠 謠 謡 䚻
80 | 譾 譾 謭
81 | 豎 豎 竪
82 | 豔 艷 豔 豓
83 | 贓 贓 贜
84 | 贗 贗 贋 偐
85 | 跺 跺 跥
86 | 踊 踴 踊
87 | 躲 躲 躱
88 | 逾 逾 踰
89 | 醞 醞 醖
90 | 醯 酰 醯
91 | 鉢 鉢 缽
92 | 鉤 鉤 鈎
93 | 銳 銳 鋭
94 | 錄 錄 録
95 | 錘 錘 鎚
96 | 鏽 鏥 銹 鏽
97 | 鐫 鐫 鎸 鋑 𥍯
98 | 钁 钁 鐝
99 | 閱 閱 閲
100 | 阪 坂 阪
101 | 僱 僱 雇
102 | 雕 雕 彫 琱
103 | 雞 雞 鷄 鶏
104 | 鞝 鞝 緔
105 | 頹 頹 頽
106 | 顏 顏 顔
107 | 館 館 舘
108 | 鬥 鬭 鬥 鬭 闘
109 | 鬨 鬨 閧
110 | 鯗 鯗 鮝
111 | 鱷 鱷 鰐 𧍞
112 | 鳧 鳧 鳬
113 | 鶿 鶿 鷀
114 | 鹼 鹼 礆 碱
115 | 麴 麯 麴
116 | 麪 麪 麵
117 | 麼 麽 麼
118 | 黴 黴 霉
119 | 齎 齎 賫
120 | 捻 捻 撚
121 | 柺 柺 枴
122 | 棲 棲 栖
123 | 臥 臥 卧
124 | 教 教 敎
125 | 勳 勳 勛
126 | 剿 剿 勦
127 | 甕 甕 瓮
128 | 餚 餚 肴
129 | 鼴 鼴 鼹
130 | 蔥 葱 蔥
131 | 搗 擣 搗
132 | 螂 蜋 螂
133 | 溼 濕 溼
134 | 羶 羶 羴
135 | 痺 痺 痹
136 | 蝨 虱 蝨
137 | 檐 檐 簷
138 | 暱 昵 暱
139 | 灩 灩 灎 灧
140 | 齧 嚙 齧
141 | 彝 彝 彞
142 | 檾 檾 苘 䔛
143 | 餈 餈 糍
144 | 拋 拋 抛
145 | 糉 糉 粽
146 | 峯 峰 峯
147 | 鵰 鵰 雕
--------------------------------------------------------------------------------
/wasm/src/Converter.js:
--------------------------------------------------------------------------------
1 | const config = require('../generated/config');
2 | const M = require('./Module');
3 | const {
4 | isValidSegmentationArg,
5 | isValidConvertionChainArg,
6 | } = require('./ConfigParser');
7 |
8 | function checkReady() {
9 | if (!M.isReady()) {
10 | throw new Error('Try to create a Converter but the script is not ready.');
11 | }
12 | }
13 |
14 | function createFromDictsString_(
15 | converter,
16 | segmentationString,
17 | convertionStrings,
18 | ) {
19 | checkReady();
20 |
21 | const wasmConverter = new M[M.EMBIND_MODULE_NAME].Wasm();
22 |
23 | wasmConverter.pushSegmentation(segmentationString);
24 |
25 | convertionStrings.forEach(item => {
26 | if (Array.isArray(item)) {
27 | item.forEach(str => {
28 | wasmConverter.pushConversion(str)
29 | })
30 | wasmConverter.createConvertionGroup()
31 | return
32 | }
33 |
34 | wasmConverter.pushConversion(item)
35 | wasmConverter.createConvertionGroup()
36 | })
37 |
38 | wasmConverter.createConverter();
39 |
40 | converter.wasmConverter = wasmConverter;
41 | }
42 |
43 | class Converter {
44 | constructor(...args) {
45 | this.checkReady = checkReady;
46 |
47 | if (
48 | args.length === 2 &&
49 | isValidSegmentationArg(args[0]) &&
50 | isValidConvertionChainArg(args[1])
51 | ) {
52 | createFromDictsString_(this, ...args);
53 | return;
54 | }
55 |
56 | throw new Error('Invalid constructor arguments for Converter.');
57 | }
58 |
59 | convert(...args) {
60 | this.checkReady();
61 | return this.wasmConverter.convert(...args);
62 | }
63 |
64 | delete() {
65 | if (!this.wasmConverter) {
66 | return;
67 | }
68 |
69 | this.wasmConverter.delete();
70 | }
71 | }
72 |
73 | module.exports = {
74 | Converter,
75 | };
76 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/production.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 | //
32 | // This is part of the unit test for include/gtest/gtest_prod.h.
33 |
34 | #include "production.h"
35 |
36 | PrivateCode::PrivateCode() : x_(0) {}
37 |
--------------------------------------------------------------------------------
/src/BinaryDictTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "BinaryDict.hpp"
20 | #include "TextDictTestBase.hpp"
21 |
22 | namespace opencc {
23 |
24 | class BinaryDictTest : public TextDictTestBase {
25 | protected:
26 | BinaryDictTest()
27 | : binDict(new BinaryDict(textDict->GetLexicon())), fileName("dict.bin"){};
28 |
29 | const BinaryDictPtr binDict;
30 | const string fileName;
31 | };
32 |
33 | TEST_F(BinaryDictTest, Serialization) {
34 | binDict->opencc::SerializableDict::SerializeToFile(fileName);
35 | }
36 |
37 | TEST_F(BinaryDictTest, Deserialization) {
38 | const BinaryDictPtr& deserialized =
39 | SerializableDict::NewFromFile(fileName);
40 | const LexiconPtr& lex1 = binDict->GetLexicon();
41 | const LexiconPtr& lex2 = deserialized->GetLexicon();
42 |
43 | // Compare every entry
44 | EXPECT_EQ(lex1->Length(), lex2->Length());
45 | for (size_t i = 0; i < lex1->Length(); i++) {
46 | EXPECT_EQ(string(lex1->At(i)->Key()), lex2->At(i)->Key());
47 | EXPECT_EQ(lex1->At(i)->NumValues(), lex2->At(i)->NumValues());
48 | }
49 |
50 | const TextDictPtr deserializedTextDict(new TextDict(lex2));
51 | TestDict(deserializedTextDict);
52 | }
53 |
54 | } // namespace opencc
55 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/src/gtest_main.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | #include
31 |
32 | #include "gtest/gtest.h"
33 |
34 | GTEST_API_ int main(int argc, char **argv) {
35 | printf("Running main() from gtest_main.cc\n");
36 | testing::InitGoogleTest(&argc, argv);
37 | return RUN_ALL_TESTS();
38 | }
39 |
--------------------------------------------------------------------------------
/wasm/scripts/copy_dicts.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs')
2 | const path = require('path')
3 | const { DIR_FOLDER, getFilesInAFolder } = require('./merge_config')
4 |
5 | const DICT_PATH = path.resolve(__dirname, '../../data/dictionary')
6 | const BUILT_DICT_PATH = path.resolve(__dirname, '../../build/rel/data')
7 | const GENERATED_FOLDER = DIR_FOLDER
8 | const DIST_FOLDER = path.resolve(__dirname, '../dist')
9 | const DICT_NAME = 'dict'
10 | const TARGET_FOLDERS = [
11 | path.resolve(GENERATED_FOLDER, DICT_NAME),
12 | path.resolve(DIST_FOLDER, DICT_NAME),
13 | ]
14 |
15 | async function ensureDir(folder) {
16 | return new Promise((resovle) => {
17 | fs.mkdir(folder, (err) => {
18 | resovle()
19 | })
20 | })
21 | }
22 |
23 | async function copyFile(file, targetPath) {
24 | return new Promise((resolve, reject) => {
25 | fs.copyFile(file, targetPath, (err) => {
26 | if (err) {
27 | reject(err)
28 | return
29 | }
30 | resolve()
31 | })
32 | })
33 | }
34 |
35 | async function copyDicts_(dictPath) {
36 | let files = await getFilesInAFolder(dictPath)
37 | files = files.filter(i => path.extname(i) === '.txt')
38 |
39 | for (let i = 0; i < TARGET_FOLDERS.length; i += 1) {
40 | const folder = TARGET_FOLDERS[i]
41 | await ensureDir(folder)
42 | }
43 |
44 | for (let i = 0; i < files.length; i += 1) {
45 | const file = files[i]
46 | const srcFile = path.resolve(dictPath, file)
47 | for (let j = 0; j < TARGET_FOLDERS.length; j += 1) {
48 | const folder = TARGET_FOLDERS[j]
49 | await copyFile(srcFile, path.resolve(folder, file))
50 | }
51 | }
52 | }
53 |
54 | async function copyDicts() {
55 | await copyDicts_(DICT_PATH)
56 | await copyDicts_(BUILT_DICT_PATH)
57 | }
58 |
59 | module.exports = {
60 | copyDicts,
61 | DIST_FOLDER,
62 | copyFile,
63 | ensureDir,
64 | }
65 |
66 | if (module === require.main) {
67 | copyDicts()
68 | }
69 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/fused-src/gtest/gtest_main.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | #include
31 |
32 | #include "gtest/gtest.h"
33 |
34 | GTEST_API_ int main(int argc, char **argv) {
35 | printf("Running main() from gtest_main.cc\n");
36 | testing::InitGoogleTest(&argc, argv);
37 | return RUN_ALL_TESTS();
38 | }
39 |
--------------------------------------------------------------------------------
/src/DartsDictTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "DartsDict.hpp"
20 | #include "TextDictTestBase.hpp"
21 |
22 | namespace opencc {
23 |
24 | class DartsDictTest : public TextDictTestBase {
25 | protected:
26 | DartsDictTest()
27 | : dartsDict(DartsDict::NewFromDict(*textDict.get())),
28 | fileName("dict.ocd"){};
29 |
30 | const DartsDictPtr dartsDict;
31 | const string fileName;
32 | };
33 |
34 | TEST_F(DartsDictTest, DictTest) { TestDict(dartsDict); }
35 |
36 | TEST_F(DartsDictTest, Serialization) {
37 | dartsDict->opencc::SerializableDict::SerializeToFile(fileName);
38 | }
39 |
40 | TEST_F(DartsDictTest, Deserialization) {
41 | const DartsDictPtr& deserialized =
42 | SerializableDict::NewFromFile(fileName);
43 | const LexiconPtr& lex1 = dartsDict->GetLexicon();
44 | const LexiconPtr& lex2 = deserialized->GetLexicon();
45 |
46 | // Compare every entry
47 | EXPECT_EQ(lex1->Length(), lex2->Length());
48 | for (size_t i = 0; i < lex1->Length(); i++) {
49 | EXPECT_EQ(string(lex1->At(i)->Key()), lex2->At(i)->Key());
50 | EXPECT_EQ(lex1->At(i)->NumValues(), lex2->At(i)->NumValues());
51 | }
52 |
53 | const TextDictPtr deserializedTextDict(new TextDict(lex2));
54 | TestDict(deserializedTextDict);
55 | }
56 |
57 | } // namespace opencc
58 |
--------------------------------------------------------------------------------
/src/Optional.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #pragma once
20 |
21 | namespace opencc {
22 | /**
23 | * A class that wraps type T into a nullable type.
24 | * @ingroup opencc_cpp_api
25 | */
26 | template class Optional {
27 | public:
28 | /**
29 | * The constructor of Optional.
30 | */
31 | Optional(T actual) : isNull(false), data(actual) {}
32 |
33 | /**
34 | * Returns true if the instance is null.
35 | */
36 | bool IsNull() const { return isNull; }
37 |
38 | /**
39 | * Returns the containing data of the instance.
40 | */
41 | const T& Get() const { return data; }
42 |
43 | /**
44 | * Constructs a null instance.
45 | */
46 | static Optional Null() { return Optional(); }
47 |
48 | private:
49 | Optional() : isNull(true) {}
50 |
51 | bool isNull;
52 | T data;
53 | };
54 |
55 | /**
56 | * Specialization of Optional for pointers.
57 | *
58 | * Reduce a bool.
59 | */
60 | template class Optional {
61 | private:
62 | Optional() : data(nullptr) {}
63 |
64 | typedef T* TPtr;
65 | TPtr data;
66 |
67 | public:
68 | Optional(TPtr actual) : data(actual) {}
69 |
70 | bool IsNull() const { return data == nullptr; }
71 |
72 | const TPtr& Get() const { return data; }
73 |
74 | static Optional Null() { return Optional(); }
75 | };
76 | }
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/OptionalUnlabeledTracker.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | /******************************************************************************
4 | *
5 | * file: OptionalUnlabeledTracker.h
6 | *
7 | * Copyright (c) 2005, Michael E. Smoot .
8 | * All rights reverved.
9 | *
10 | * See the file COPYING in the top directory of this distribution for
11 | * more information.
12 | *
13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | * DEALINGS IN THE SOFTWARE.
20 | *
21 | *****************************************************************************/
22 |
23 |
24 | #ifndef TCLAP_OPTIONAL_UNLABELED_TRACKER_H
25 | #define TCLAP_OPTIONAL_UNLABELED_TRACKER_H
26 |
27 | #include
28 |
29 | namespace TCLAP {
30 |
31 | class OptionalUnlabeledTracker
32 | {
33 |
34 | public:
35 |
36 | static void check( bool req, const std::string& argName );
37 |
38 | static void gotOptional() { alreadyOptionalRef() = true; }
39 |
40 | static bool& alreadyOptional() { return alreadyOptionalRef(); }
41 |
42 | private:
43 |
44 | static bool& alreadyOptionalRef() { static bool ct = false; return ct; }
45 | };
46 |
47 |
48 | inline void OptionalUnlabeledTracker::check( bool req, const std::string& argName )
49 | {
50 | if ( OptionalUnlabeledTracker::alreadyOptional() )
51 | throw( SpecificationException(
52 | "You can't specify ANY Unlabeled Arg following an optional Unlabeled Arg",
53 | argName ) );
54 |
55 | if ( !req )
56 | OptionalUnlabeledTracker::gotOptional();
57 | }
58 |
59 |
60 | } // namespace TCLAP
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Open Chinese Convert
3 | #
4 | # Copyright 2010-2015 BYVoid
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | PREFIX = /usr
20 |
21 | .PHONY: build clean node test xcode-build
22 |
23 | build:
24 | mkdir -p build/rel
25 | (cd build/rel; cmake \
26 | -DBUILD_DOCUMENTATION:BOOL=ON \
27 | -DENABLE_GTEST:BOOL=OFF \
28 | -DCMAKE_BUILD_TYPE=Release \
29 | -DCMAKE_INSTALL_PREFIX=${PREFIX} \
30 | ../..)
31 | make -C build/rel VERBOSE=${VERBOSE} PREFIX=${PREFIX}
32 |
33 | package: build
34 | make -C build/rel package_source VERBOSE=${VERBOSE}
35 | make -C build/rel package_source VERBOSE=${VERBOSE} PREFIX=${PREFIX}
36 |
37 | test:
38 | mkdir -p build/dbg/root
39 | (cd build/dbg; cmake \
40 | -DBUILD_DOCUMENTATION:BOOL=OFF \
41 | -DENABLE_GTEST:BOOL=ON \
42 | -DCMAKE_BUILD_TYPE=Debug \
43 | -DCMAKE_INSTALL_PREFIX=`pwd`/root \
44 | ../..)
45 | make -C build/dbg VERBOSE=${VERBOSE}
46 | (cd build/dbg; ctest --verbose)
47 | make -C build/dbg install VERBOSE=${VERBOSE}
48 |
49 | node:
50 | node-gyp configure
51 | node-gyp build
52 |
53 | node-test: node
54 | npm test
55 |
56 | xcode-build:
57 | mkdir -p xcode
58 | (cd xcode; cmake \
59 | -G "Xcode" \
60 | -DBUILD_DOCUMENTATION:BOOL=OFF \
61 | -DENABLE_GTEST:BOOL=ON \
62 | ..; \
63 | xcodebuild build)
64 |
65 | test-all: test node-test
66 |
67 | clean:
68 | rm -rf build xcode
69 |
70 | install: build
71 | make -C build/rel install VERBOSE=${VERBOSE} PREFIX=${PREFIX}
72 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/codegear/gtest_all.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: Josh Kelley (joshkel@gmail.com)
31 | //
32 | // Google C++ Testing Framework (Google Test)
33 | //
34 | // C++Builder's IDE cannot build a static library from files with hyphens
35 | // in their name. See http://qc.codegear.com/wc/qcmain.aspx?d=70977 .
36 | // This file serves as a workaround.
37 |
38 | #include "src/gtest-all.cc"
39 |
--------------------------------------------------------------------------------
/src/DictGroupTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "DictGroupTestBase.hpp"
20 |
21 | namespace opencc {
22 |
23 | class DictGroupTest : public DictGroupTestBase {
24 | protected:
25 | DictGroupTest() {}
26 | };
27 |
28 | TEST_F(DictGroupTest, SimpleGroupTest) {
29 | const DictGroupPtr& dictGroup = CreateDictGroupForConversion();
30 | const auto& entry = dictGroup->Dict::MatchPrefix(utf8("Unknown"));
31 | EXPECT_TRUE(entry.IsNull());
32 |
33 | const auto& matches = dictGroup->Dict::MatchAllPrefixes(utf8("干燥"));
34 | EXPECT_EQ(2, matches.size());
35 | EXPECT_EQ(utf8("乾燥"), matches.at(0)->GetDefault());
36 | EXPECT_EQ(utf8("幹"), matches.at(1)->GetDefault());
37 | }
38 |
39 | TEST_F(DictGroupTest, TaiwanPhraseGroupTest) {
40 | const DictGroupPtr dictGroup(new DictGroup(
41 | list{CreateDictForPhrases(), CreateTaiwanPhraseDict()}));
42 | {
43 | const auto& entry = dictGroup->Dict::MatchPrefix(utf8("鼠标"));
44 | EXPECT_EQ(utf8("鼠標"), entry.Get()->GetDefault());
45 | }
46 | {
47 | const auto& entry = dictGroup->Dict::MatchPrefix(utf8("克罗地亚"));
48 | EXPECT_EQ(utf8("克羅埃西亞"), entry.Get()->GetDefault());
49 | }
50 | {
51 | const auto& matches = dictGroup->Dict::MatchAllPrefixes(utf8("鼠标"));
52 | EXPECT_EQ(1, matches.size());
53 | EXPECT_EQ(utf8("鼠標"), matches[0]->GetDefault());
54 | }
55 | }
56 |
57 | } // namespace opencc
58 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/scripts/test/Makefile:
--------------------------------------------------------------------------------
1 | # A Makefile for fusing Google Test and building a sample test against it.
2 | #
3 | # SYNOPSIS:
4 | #
5 | # make [all] - makes everything.
6 | # make TARGET - makes the given target.
7 | # make check - makes everything and runs the built sample test.
8 | # make clean - removes all files generated by make.
9 |
10 | # Points to the root of fused Google Test, relative to where this file is.
11 | FUSED_GTEST_DIR = output
12 |
13 | # Paths to the fused gtest files.
14 | FUSED_GTEST_H = $(FUSED_GTEST_DIR)/gtest/gtest.h
15 | FUSED_GTEST_ALL_CC = $(FUSED_GTEST_DIR)/gtest/gtest-all.cc
16 |
17 | # Where to find the sample test.
18 | SAMPLE_DIR = ../../samples
19 |
20 | # Where to find gtest_main.cc.
21 | GTEST_MAIN_CC = ../../src/gtest_main.cc
22 |
23 | # Flags passed to the preprocessor.
24 | # We have no idea here whether pthreads is available in the system, so
25 | # disable its use.
26 | CPPFLAGS += -I$(FUSED_GTEST_DIR) -DGTEST_HAS_PTHREAD=0
27 |
28 | # Flags passed to the C++ compiler.
29 | CXXFLAGS += -g
30 |
31 | all : sample1_unittest
32 |
33 | check : all
34 | ./sample1_unittest
35 |
36 | clean :
37 | rm -rf $(FUSED_GTEST_DIR) sample1_unittest *.o
38 |
39 | $(FUSED_GTEST_H) :
40 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR)
41 |
42 | $(FUSED_GTEST_ALL_CC) :
43 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR)
44 |
45 | gtest-all.o : $(FUSED_GTEST_H) $(FUSED_GTEST_ALL_CC)
46 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FUSED_GTEST_DIR)/gtest/gtest-all.cc
47 |
48 | gtest_main.o : $(FUSED_GTEST_H) $(GTEST_MAIN_CC)
49 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(GTEST_MAIN_CC)
50 |
51 | sample1.o : $(SAMPLE_DIR)/sample1.cc $(SAMPLE_DIR)/sample1.h
52 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1.cc
53 |
54 | sample1_unittest.o : $(SAMPLE_DIR)/sample1_unittest.cc \
55 | $(SAMPLE_DIR)/sample1.h $(FUSED_GTEST_H)
56 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1_unittest.cc
57 |
58 | sample1_unittest : sample1.o sample1_unittest.o gtest-all.o gtest_main.o
59 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@
60 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/gtest_main_unittest.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2006, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include "gtest/gtest.h"
33 |
34 | // Tests that we don't have to define main() when we link to
35 | // gtest_main instead of gtest.
36 |
37 | namespace {
38 |
39 | TEST(GTestMainTest, ShouldSucceed) {
40 | }
41 |
42 | } // namespace
43 |
44 | // We are using the main() function defined in src/gtest_main.cc, so
45 | // we don't define it here.
46 |
--------------------------------------------------------------------------------
/data/scripts/common.py:
--------------------------------------------------------------------------------
1 | #coding: utf-8
2 | import codecs
3 | import sys
4 |
5 | def sort_items(input_filename, output_filename):
6 | input_file = codecs.open(input_filename, "r", encoding="utf-8")
7 | dic = {}
8 |
9 | for line in input_file:
10 | if len(line) == 0 or line == '\n':
11 | continue
12 | try:
13 | key, value = line.split("\t")
14 | except ValueError:
15 | print(line)
16 | while value[-1] == "\n" or value[-1] == "\r":
17 | value = value[:-1]
18 | dic[key] = value
19 |
20 | input_file.close()
21 |
22 | output_file = open(output_filename, "wb")
23 |
24 | for key in sorted(dic.keys()):
25 | line = key + "\t" + dic[key] + "\n"
26 | output_file.write(line.encode('utf-8'))
27 |
28 | output_file.close()
29 |
30 | def reverse_items(input_filename, output_filename):
31 | input_file = codecs.open(input_filename, "r", encoding="utf-8")
32 | dic = {}
33 |
34 | for line in input_file:
35 | if len(line) == 0:
36 | continue
37 | key, value = line.split("\t")
38 | while value[-1] == "\n" or value[-1] == "\r":
39 | value = value[:-1]
40 |
41 | value_list = value.split(" ")
42 | for value in value_list:
43 | if value in dic:
44 | dic[value].append(key)
45 | else:
46 | dic[value] = [key]
47 |
48 | input_file.close()
49 |
50 | output_file = open(output_filename, "wb")
51 |
52 | for key in sorted(dic.keys()):
53 | line = key + "\t" + " ".join(dic[key]) + "\n"
54 | output_file.write(line.encode('utf-8'))
55 |
56 | output_file.close()
57 |
58 | def find_target_items(input_filename, keyword):
59 | input_file = codecs.open(input_filename, "r", encoding="utf-8")
60 | for line in input_file:
61 | if len(line) == 0:
62 | continue
63 | key, value = line.split("\t")
64 | while value[-1] == "\n" or value[-1] == "\r":
65 | value = value[:-1]
66 |
67 | value_list = value.split(" ")
68 | for value in value_list:
69 | if keyword in value:
70 | sys.stdout.write(line)
71 |
72 | input_file.close()
73 |
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/Constraint.h:
--------------------------------------------------------------------------------
1 |
2 | /******************************************************************************
3 | *
4 | * file: Constraint.h
5 | *
6 | * Copyright (c) 2005, Michael E. Smoot
7 | * All rights reverved.
8 | *
9 | * See the file COPYING in the top directory of this distribution for
10 | * more information.
11 | *
12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 | * DEALINGS IN THE SOFTWARE.
19 | *
20 | *****************************************************************************/
21 |
22 | #ifndef TCLAP_CONSTRAINT_H
23 | #define TCLAP_CONSTRAINT_H
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | namespace TCLAP {
33 |
34 | /**
35 | * The interface that defines the interaction between the Arg and Constraint.
36 | */
37 | template
38 | class Constraint
39 | {
40 |
41 | public:
42 | /**
43 | * Returns a description of the Constraint.
44 | */
45 | virtual std::string description() const =0;
46 |
47 | /**
48 | * Returns the short ID for the Constraint.
49 | */
50 | virtual std::string shortID() const =0;
51 |
52 | /**
53 | * The method used to verify that the value parsed from the command
54 | * line meets the constraint.
55 | * \param value - The value that will be checked.
56 | */
57 | virtual bool check(const T& value) const =0;
58 |
59 | /**
60 | * Destructor.
61 | * Silences warnings about Constraint being a base class with virtual
62 | * functions but without a virtual destructor.
63 | */
64 | virtual ~Constraint() { ; }
65 | };
66 |
67 | } //namespace TCLAP
68 | #endif
69 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/samples/sample4_unittest.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include "gtest/gtest.h"
33 | #include "sample4.h"
34 |
35 | // Tests the Increment() method.
36 | TEST(Counter, Increment) {
37 | Counter c;
38 |
39 | // EXPECT_EQ() evaluates its arguments exactly once, so they
40 | // can have side effects.
41 |
42 | EXPECT_EQ(0, c.Increment());
43 | EXPECT_EQ(1, c.Increment());
44 | EXPECT_EQ(2, c.Increment());
45 | }
46 |
--------------------------------------------------------------------------------
/src/DictConverter.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2017 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "DartsDict.hpp"
20 | #include "DictConverter.hpp"
21 | #include "TextDict.hpp"
22 |
23 | using namespace opencc;
24 |
25 | DictPtr LoadDictionary(const string& format, const string& inputFileName) {
26 | if (format == "text") {
27 | return SerializableDict::NewFromFile(inputFileName);
28 | } else if (format == "ocd") {
29 | return SerializableDict::NewFromFile(inputFileName);
30 | } else {
31 | fprintf(stderr, "Unknown dictionary format: %s\n", format.c_str());
32 | exit(2);
33 | }
34 | return nullptr;
35 | }
36 |
37 | SerializableDictPtr ConvertDict(const string& format,
38 | const DictPtr dict) {
39 | if (format == "text") {
40 | return TextDict::NewFromDict(*dict.get());
41 | } else if (format == "ocd") {
42 | return DartsDict::NewFromDict(*dict.get());
43 | } else {
44 | fprintf(stderr, "Unknown dictionary format: %s\n", format.c_str());
45 | exit(2);
46 | }
47 | return nullptr;
48 | }
49 |
50 | namespace opencc {
51 | void ConvertDictionary(const string inputFileName, const string outputFileName,
52 | const string formatFrom, const string formatTo) {
53 | DictPtr dictFrom = LoadDictionary(formatFrom, inputFileName);
54 | SerializableDictPtr dictTo = ConvertDict(formatTo, dictFrom);
55 | dictTo->SerializeToFile(outputFileName);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/samples/sample1.h:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #ifndef GTEST_SAMPLES_SAMPLE1_H_
35 | #define GTEST_SAMPLES_SAMPLE1_H_
36 |
37 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1.
38 | int Factorial(int n);
39 |
40 | // Returns true iff n is a prime number.
41 | bool IsPrime(int n);
42 |
43 | #endif // GTEST_SAMPLES_SAMPLE1_H_
44 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/gtest_uninitialized_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include "gtest/gtest.h"
33 |
34 | TEST(DummyTest, Dummy) {
35 | // This test doesn't verify anything. We just need it to create a
36 | // realistic stage for testing the behavior of Google Test when
37 | // RUN_ALL_TESTS() is called without testing::InitGoogleTest() being
38 | // called first.
39 | }
40 |
41 | int main() {
42 | return RUN_ALL_TESTS();
43 | }
44 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/samples/sample4.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #include
35 |
36 | #include "sample4.h"
37 |
38 | // Returns the current counter value, and increments it.
39 | int Counter::Increment() {
40 | return counter_++;
41 | }
42 |
43 | // Prints the current counter value to STDOUT.
44 | void Counter::Print() const {
45 | printf("%d", counter_);
46 | }
47 |
--------------------------------------------------------------------------------
/WasmMakefile:
--------------------------------------------------------------------------------
1 | #
2 | # Open Chinese Convert
3 | #
4 | # Copyright 2010-2015 BYVoid
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | PREFIX = /usr
20 |
21 | .PHONY: build clean node test xcode-build
22 |
23 | build:
24 | mkdir -p build/rel
25 | (cd build/rel; cmake \
26 | -DCMAKE_TOOLCHAIN_FILE=/Users/oyyd/code/github/em2/emscripten/1.38.12/cmake/Modules/Platform/Emscripten.cmake \
27 | -DBUILD_DOCUMENTATION:BOOL=OFF \
28 | -DENABLE_GTEST:BOOL=OFF \
29 | -DCMAKE_BUILD_TYPE=Release \
30 | -DCMAKE_INSTALL_PREFIX=${PREFIX} \
31 | ../..)
32 | make -C build/rel VERBOSE=1 PREFIX=${PREFIX}
33 |
34 | package: build
35 | make -C build/rel package_source VERBOSE=${VERBOSE}
36 | make -C build/rel package_source VERBOSE=${VERBOSE} PREFIX=${PREFIX}
37 |
38 | test:
39 | mkdir -p build/dbg/root
40 | (cd build/dbg; cmake \
41 | -DBUILD_DOCUMENTATION:BOOL=OFF \
42 | -DENABLE_GTEST:BOOL=ON \
43 | -DCMAKE_BUILD_TYPE=Debug \
44 | -DCMAKE_INSTALL_PREFIX=`pwd`/root \
45 | ../..)
46 | make -C build/dbg VERBOSE=${VERBOSE}
47 | (cd build/dbg; ctest --verbose)
48 | make -C build/dbg install VERBOSE=${VERBOSE}
49 |
50 | node:
51 | node-gyp configure
52 | node-gyp build
53 |
54 | node-test: node
55 | npm test
56 |
57 | xcode-build:
58 | mkdir -p xcode
59 | (cd xcode; cmake \
60 | -G "Xcode" \
61 | -DBUILD_DOCUMENTATION:BOOL=OFF \
62 | -DENABLE_GTEST:BOOL=ON \
63 | ..; \
64 | xcodebuild build)
65 |
66 | test-all: test node-test
67 |
68 | clean:
69 | rm -rf build xcode
70 |
71 | install: build
72 | make -C build/rel install VERBOSE=${VERBOSE} PREFIX=${PREFIX}
73 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/build-aux/config.h.in:
--------------------------------------------------------------------------------
1 | /* build-aux/config.h.in. Generated from configure.ac by autoheader. */
2 |
3 | /* Define to 1 if you have the header file. */
4 | #undef HAVE_DLFCN_H
5 |
6 | /* Define to 1 if you have the header file. */
7 | #undef HAVE_INTTYPES_H
8 |
9 | /* Define to 1 if you have the header file. */
10 | #undef HAVE_MEMORY_H
11 |
12 | /* Define if you have POSIX threads libraries and header files. */
13 | #undef HAVE_PTHREAD
14 |
15 | /* Define to 1 if you have the header file. */
16 | #undef HAVE_STDINT_H
17 |
18 | /* Define to 1 if you have the header file. */
19 | #undef HAVE_STDLIB_H
20 |
21 | /* Define to 1 if you have the header file. */
22 | #undef HAVE_STRINGS_H
23 |
24 | /* Define to 1 if you have the header file. */
25 | #undef HAVE_STRING_H
26 |
27 | /* Define to 1 if you have the header file. */
28 | #undef HAVE_SYS_STAT_H
29 |
30 | /* Define to 1 if you have the header file. */
31 | #undef HAVE_SYS_TYPES_H
32 |
33 | /* Define to 1 if you have the header file. */
34 | #undef HAVE_UNISTD_H
35 |
36 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
37 | */
38 | #undef LT_OBJDIR
39 |
40 | /* Name of package */
41 | #undef PACKAGE
42 |
43 | /* Define to the address where bug reports for this package should be sent. */
44 | #undef PACKAGE_BUGREPORT
45 |
46 | /* Define to the full name of this package. */
47 | #undef PACKAGE_NAME
48 |
49 | /* Define to the full name and version of this package. */
50 | #undef PACKAGE_STRING
51 |
52 | /* Define to the one symbol short name of this package. */
53 | #undef PACKAGE_TARNAME
54 |
55 | /* Define to the home page for this package. */
56 | #undef PACKAGE_URL
57 |
58 | /* Define to the version of this package. */
59 | #undef PACKAGE_VERSION
60 |
61 | /* Define to necessary symbol if this constant uses a non-standard name on
62 | your system. */
63 | #undef PTHREAD_CREATE_JOINABLE
64 |
65 | /* Define to 1 if you have the ANSI C header files. */
66 | #undef STDC_HEADERS
67 |
68 | /* Version number of package */
69 | #undef VERSION
70 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/codegear/gtest_link.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: Josh Kelley (joshkel@gmail.com)
31 | //
32 | // Google C++ Testing Framework (Google Test)
33 | //
34 | // Links gtest.lib and gtest_main.lib into the current project in C++Builder.
35 | // This means that these libraries can't be renamed, but it's the only way to
36 | // ensure that Debug versus Release test builds are linked against the
37 | // appropriate Debug or Release build of the libraries.
38 |
39 | #pragma link "gtest.lib"
40 | #pragma link "gtest_main.lib"
41 |
--------------------------------------------------------------------------------
/src/ConversionChainTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2015 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "ConversionChain.hpp"
20 | #include "DictGroupTestBase.hpp"
21 |
22 | namespace opencc {
23 |
24 | class ConversionChainTest : public DictGroupTestBase {
25 | protected:
26 | ConversionChainTest() {}
27 |
28 | virtual void SetUp() {
29 | dict = CreateDictGroupForConversion();
30 | conversion = ConversionPtr(new Conversion(dict));
31 | }
32 |
33 | void SegmentsAssertEquals(const SegmentsPtr& expected,
34 | const SegmentsPtr& actual) {
35 | const size_t length = expected->Length();
36 | EXPECT_TRUE(length == actual->Length());
37 | for (size_t i = 0; i < length; i++) {
38 | EXPECT_EQ(string(expected->At(i)), string(actual->At(i)));
39 | }
40 | }
41 |
42 | DictPtr dict;
43 | ConversionPtr conversion;
44 | };
45 |
46 | TEST_F(ConversionChainTest, Convert) {
47 | // Variants
48 | const DictPtr& dictVariants = CreateDictForTaiwanVariants();
49 | const ConversionPtr& conversionVariants =
50 | ConversionPtr(new Conversion(dictVariants));
51 | const list conversions{conversion, conversionVariants};
52 | const ConversionChainPtr& conversionChain =
53 | ConversionChainPtr(new ConversionChain(conversions));
54 | const SegmentsPtr& converted =
55 | conversionChain->Convert(SegmentsPtr(new Segments{utf8("里面")}));
56 | SegmentsAssertEquals(SegmentsPtr(new Segments{utf8("裡面")}), converted);
57 | }
58 |
59 | } // namespace opencc
60 |
--------------------------------------------------------------------------------
/src/Dict.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Open Chinese Convert
3 | *
4 | * Copyright 2010-2014 BYVoid
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | #include "Dict.hpp"
20 |
21 | using namespace opencc;
22 |
23 | Optional Dict::MatchPrefix(const char* word) const {
24 | string wordTrunc = UTF8Util::TruncateUTF8(word, KeyMaxLength());
25 | const char* wordTruncPtr = wordTrunc.c_str() + wordTrunc.length();
26 | for (long len = static_cast(wordTrunc.length()); len > 0;) {
27 | wordTrunc.resize(static_cast(len));
28 | wordTruncPtr = wordTrunc.c_str() + len;
29 | const Optional& result = Match(wordTrunc.c_str());
30 | if (!result.IsNull()) {
31 | return result;
32 | }
33 | len -= static_cast(UTF8Util::PrevCharLength(wordTruncPtr));
34 | }
35 | return Optional::Null();
36 | }
37 |
38 | vector Dict::MatchAllPrefixes(const char* word) const {
39 | vector matchedLengths;
40 | string wordTrunc = UTF8Util::TruncateUTF8(word, KeyMaxLength());
41 | const char* wordTruncPtr = wordTrunc.c_str() + wordTrunc.length();
42 | for (long len = static_cast(wordTrunc.length()); len > 0;
43 | len -= static_cast(UTF8Util::PrevCharLength(wordTruncPtr))) {
44 | wordTrunc.resize(static_cast(len));
45 | wordTruncPtr = wordTrunc.c_str() + len;
46 | const Optional& result = Match(wordTrunc.c_str());
47 | if (!result.IsNull()) {
48 | matchedLengths.push_back(result.Get());
49 | }
50 | }
51 | return matchedLengths;
52 | }
53 |
--------------------------------------------------------------------------------
/wasm/scripts/generate.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const fs = require('fs')
3 | const { writeFile, getFile, mergeConfig, DIR_FOLDER } = require('./merge_config')
4 | const { copyDicts, ensureDir, copyFile, DIST_FOLDER } = require('./copy_dicts')
5 | const { JS_FILE_NAME, concatFile } = require('./concat')
6 | const { EMBIND_MODULE_NAME, NAME_ON_WINDOW } = require('../src/Module')
7 |
8 | const MEM_FILE_NAME = `${JS_FILE_NAME}.mem`
9 |
10 | const FILE_NAMES = [
11 | JS_FILE_NAME,
12 | MEM_FILE_NAME
13 | ]
14 |
15 | const BUILT_FILE_PATH = path.resolve(__dirname, `../../build/rel/src/wasm/`)
16 |
17 | async function copyBuiltFile(fileName) {
18 | const file = path.resolve(BUILT_FILE_PATH, fileName)
19 | const targetPath = path.resolve(DIR_FOLDER, `./${fileName}`)
20 | return copyFile(file, targetPath)
21 | }
22 |
23 | async function copyBuiltFiles() {
24 | for (let i = 0; i < FILE_NAMES.length; i += 1) {
25 | const fileName = FILE_NAMES[i]
26 |
27 | await copyBuiltFile(fileName)
28 | }
29 | }
30 |
31 | // NOTE: The compiled file could not recognize Jest environment correctly
32 | // and we don't want to modify code inside in so we wrap it in a function
33 | // and controll it from outside.
34 | async function wrapASMFile() {
35 | const file = path.resolve(DIR_FOLDER, JS_FILE_NAME)
36 | const asmContent = await getFile(file)
37 |
38 | return writeFile(file, `(function(window) { var Module = typeof window === 'undefined' ? undefined : window.${NAME_ON_WINDOW}.${EMBIND_MODULE_NAME}; ${asmContent} })(!(typeof global !== 'undefined' && typeof process !== 'undefined' && process.version) ? window : undefined);`)
39 | }
40 |
41 | async function copyMemFile() {
42 | const file = path.resolve(BUILT_FILE_PATH, MEM_FILE_NAME)
43 | const targetPath = path.resolve(DIST_FOLDER, `./${MEM_FILE_NAME}`)
44 | return copyFile(file, targetPath)
45 | }
46 |
47 | async function main() {
48 | await ensureDir(DIR_FOLDER)
49 | await copyDicts()
50 | await mergeConfig()
51 | await copyBuiltFiles()
52 | await wrapASMFile()
53 | await copyMemFile()
54 | }
55 |
56 | module.exports = {
57 | JS_FILE_NAME,
58 | }
59 |
60 | if (module === require.main) {
61 | main().catch((err) => console.error(err.stack()))
62 | }
63 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/gtest_xml_outfile1_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: keith.ray@gmail.com (Keith Ray)
31 | //
32 | // gtest_xml_outfile1_test_ writes some xml via TestProperty used by
33 | // gtest_xml_outfiles_test.py
34 |
35 | #include "gtest/gtest.h"
36 |
37 | class PropertyOne : public testing::Test {
38 | protected:
39 | virtual void SetUp() {
40 | RecordProperty("SetUpProp", 1);
41 | }
42 | virtual void TearDown() {
43 | RecordProperty("TearDownProp", 1);
44 | }
45 | };
46 |
47 | TEST_F(PropertyOne, TestSomeProperties) {
48 | RecordProperty("TestSomeProperty", 1);
49 | }
50 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/gtest_xml_outfile2_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: keith.ray@gmail.com (Keith Ray)
31 | //
32 | // gtest_xml_outfile2_test_ writes some xml via TestProperty used by
33 | // gtest_xml_outfiles_test.py
34 |
35 | #include "gtest/gtest.h"
36 |
37 | class PropertyTwo : public testing::Test {
38 | protected:
39 | virtual void SetUp() {
40 | RecordProperty("SetUpProp", 2);
41 | }
42 | virtual void TearDown() {
43 | RecordProperty("TearDownProp", 2);
44 | }
45 | };
46 |
47 | TEST_F(PropertyTwo, TestSomeProperties) {
48 | RecordProperty("TestSomeProperty", 2);
49 | }
50 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/codegear/gtest.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {c1d923e0-6cba-4332-9b6f-3420acbf5091}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | Default.Personality
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/gtest-typed-test2_test.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2008 Google Inc.
2 | // All Rights Reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | #include
33 |
34 | #include "test/gtest-typed-test_test.h"
35 | #include "gtest/gtest.h"
36 |
37 | #if GTEST_HAS_TYPED_TEST_P
38 |
39 | // Tests that the same type-parameterized test case can be
40 | // instantiated in different translation units linked together.
41 | // (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
42 | INSTANTIATE_TYPED_TEST_CASE_P(Vector, ContainerTest,
43 | testing::Types >);
44 |
45 | #endif // GTEST_HAS_TYPED_TEST_P
46 |
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/CmdLineOutput.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | /******************************************************************************
4 | *
5 | * file: CmdLineOutput.h
6 | *
7 | * Copyright (c) 2004, Michael E. Smoot
8 | * All rights reverved.
9 | *
10 | * See the file COPYING in the top directory of this distribution for
11 | * more information.
12 | *
13 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | * DEALINGS IN THE SOFTWARE.
20 | *
21 | *****************************************************************************/
22 |
23 | #ifndef TCLAP_CMDLINEOUTPUT_H
24 | #define TCLAP_CMDLINEOUTPUT_H
25 |
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | namespace TCLAP {
34 |
35 | class CmdLineInterface;
36 | class ArgException;
37 |
38 | /**
39 | * The interface that any output object must implement.
40 | */
41 | class CmdLineOutput
42 | {
43 |
44 | public:
45 |
46 | /**
47 | * Virtual destructor.
48 | */
49 | virtual ~CmdLineOutput() {}
50 |
51 | /**
52 | * Generates some sort of output for the USAGE.
53 | * \param c - The CmdLine object the output is generated for.
54 | */
55 | virtual void usage(CmdLineInterface& c)=0;
56 |
57 | /**
58 | * Generates some sort of output for the version.
59 | * \param c - The CmdLine object the output is generated for.
60 | */
61 | virtual void version(CmdLineInterface& c)=0;
62 |
63 | /**
64 | * Generates some sort of output for a failure.
65 | * \param c - The CmdLine object the output is generated for.
66 | * \param e - The ArgException that caused the failure.
67 | */
68 | virtual void failure( CmdLineInterface& c,
69 | ArgException& e )=0;
70 |
71 | };
72 |
73 | } //namespace TCLAP
74 | #endif
75 |
--------------------------------------------------------------------------------
/deps/tclap-1.2.1/tclap/HelpVisitor.h:
--------------------------------------------------------------------------------
1 |
2 | /******************************************************************************
3 | *
4 | * file: HelpVisitor.h
5 | *
6 | * Copyright (c) 2003, Michael E. Smoot .
7 | * All rights reverved.
8 | *
9 | * See the file COPYING in the top directory of this distribution for
10 | * more information.
11 | *
12 | * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 | * DEALINGS IN THE SOFTWARE.
19 | *
20 | *****************************************************************************/
21 |
22 | #ifndef TCLAP_HELP_VISITOR_H
23 | #define TCLAP_HELP_VISITOR_H
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | namespace TCLAP {
30 |
31 | /**
32 | * A Visitor object that calls the usage method of the given CmdLineOutput
33 | * object for the specified CmdLine object.
34 | */
35 | class HelpVisitor: public Visitor
36 | {
37 | private:
38 | /**
39 | * Prevent accidental copying.
40 | */
41 | HelpVisitor(const HelpVisitor& rhs);
42 | HelpVisitor& operator=(const HelpVisitor& rhs);
43 |
44 | protected:
45 |
46 | /**
47 | * The CmdLine the output will be generated for.
48 | */
49 | CmdLineInterface* _cmd;
50 |
51 | /**
52 | * The output object.
53 | */
54 | CmdLineOutput** _out;
55 |
56 | public:
57 |
58 | /**
59 | * Constructor.
60 | * \param cmd - The CmdLine the output will be generated for.
61 | * \param out - The type of output.
62 | */
63 | HelpVisitor(CmdLineInterface* cmd, CmdLineOutput** out)
64 | : Visitor(), _cmd( cmd ), _out( out ) { }
65 |
66 | /**
67 | * Calls the usage method of the CmdLineOutput for the
68 | * specified CmdLine.
69 | */
70 | void visit() { (*_out)->usage(*_cmd); throw ExitException(0); }
71 |
72 | };
73 |
74 | }
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/samples/sample4.h:
--------------------------------------------------------------------------------
1 | // Copyright 2005, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | // A sample program demonstrating using Google C++ testing framework.
31 | //
32 | // Author: wan@google.com (Zhanyong Wan)
33 |
34 | #ifndef GTEST_SAMPLES_SAMPLE4_H_
35 | #define GTEST_SAMPLES_SAMPLE4_H_
36 |
37 | // A simple monotonic counter.
38 | class Counter {
39 | private:
40 | int counter_;
41 |
42 | public:
43 | // Creates a counter that starts at 0.
44 | Counter() : counter_(0) {}
45 |
46 | // Returns the current counter value, and increments it.
47 | int Increment();
48 |
49 | // Prints the current counter value to STDOUT.
50 | void Print() const;
51 | };
52 |
53 | #endif // GTEST_SAMPLES_SAMPLE4_H_
54 |
--------------------------------------------------------------------------------
/wasm/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wasm-opencc",
3 | "version": "1.0.2",
4 | "description": "OpenCC compiled by Emscripten so that you can run it in browsers.",
5 | "author": "oyyd ",
6 | "main": "lib/index.js",
7 | "scripts": {
8 | "docs": "cp -r dist/ ./docs/ && cp node_modules/codemirror/lib/codemirror.css ./docs/ && babel docs/src/ --out-dir docs/lib && node docs/lib/build && webpack --config docs/webpack.config.js && cp -r docs/ ../docs/",
9 | "test": "jest",
10 | "generate": "node scripts/generate",
11 | "build_node": "babel src --out-dir lib",
12 | "build_browser": "webpack && node scripts/concat",
13 | "build": "npm run generate && npm run build_node && npm run build_browser"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/oyyd/nysocks.git"
18 | },
19 | "homepage": "https://oyyd.github.io/wasm-opencc/",
20 | "files": [
21 | "generated",
22 | "lib/*.js",
23 | "package.json",
24 | "README.md"
25 | ],
26 | "license": "Apache-2.0",
27 | "devDependencies": {
28 | "babel-cli": "^6.26.0",
29 | "babel-core": "^6.26.3",
30 | "babel-jest": "^23.6.0",
31 | "babel-loader": "^7.1.5",
32 | "babel-preset-env": "^1.7.0",
33 | "babel-preset-react": "^6.24.1",
34 | "codemirror": "^5.40.0",
35 | "imports-loader": "^0.8.0",
36 | "jest": "^23.6.0",
37 | "react": "^16.5.1",
38 | "react-dom": "^16.5.1",
39 | "react-dom-server": "0.0.5",
40 | "react-markdown": "^3.6.0",
41 | "react-syntax-highlighter": "^8.0.1",
42 | "uglifyjs-webpack-plugin": "^2.0.0",
43 | "webpack": "^4.19.0",
44 | "webpack-cli": "^3.1.0"
45 | },
46 | "eslintConfig": {
47 | "env": {
48 | "node": true,
49 | "jest": true
50 | },
51 | "extends": "airbnb-base",
52 | "rules": {
53 | "semi": [
54 | 2,
55 | "never"
56 | ],
57 | "arrow-parens": 0,
58 | "global-require": 0,
59 | "no-underscore-dangle": 0,
60 | "no-param-reassign": 0,
61 | "import/prefer-default-export": 0
62 | }
63 | },
64 | "jest": {
65 | "transformIgnorePatterns": [
66 | "opencc-asm"
67 | ],
68 | "verbose": true,
69 | "testMatch": [
70 | "**/src/**/__tests__/**/*.spec.js"
71 | ]
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/deps/gtest-1.7.0/test/gtest_help_test_.cc:
--------------------------------------------------------------------------------
1 | // Copyright 2009, Google Inc.
2 | // All rights reserved.
3 | //
4 | // Redistribution and use in source and binary forms, with or without
5 | // modification, are permitted provided that the following conditions are
6 | // met:
7 | //
8 | // * Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // * Redistributions in binary form must reproduce the above
11 | // copyright notice, this list of conditions and the following disclaimer
12 | // in the documentation and/or other materials provided with the
13 | // distribution.
14 | // * Neither the name of Google Inc. nor the names of its
15 | // contributors may be used to endorse or promote products derived from
16 | // this software without specific prior written permission.
17 | //
18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | //
30 | // Author: wan@google.com (Zhanyong Wan)
31 |
32 | // This program is meant to be run by gtest_help_test.py. Do not run
33 | // it directly.
34 |
35 | #include "gtest/gtest.h"
36 |
37 | // When a help flag is specified, this program should skip the tests
38 | // and exit with 0; otherwise the following test will be executed,
39 | // causing this program to exit with a non-zero code.
40 | TEST(HelpFlagTest, ShouldNotBeRun) {
41 | ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified.";
42 | }
43 |
44 | #if GTEST_HAS_DEATH_TEST
45 | TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {}
46 | #endif
47 |
--------------------------------------------------------------------------------