nodejieba-plus 3.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +12 -0
- package/.github/workflows/github_release.yml +61 -0
- package/.github/workflows/npm_publish.yml +24 -0
- package/.github/workflows/stale-issues.yml +24 -0
- package/.github/workflows/test.yml +42 -0
- package/.gitmodules +3 -0
- package/.npmignore +15 -0
- package/CHANGELOG.md +360 -0
- package/CONTRIBUTING.md +78 -0
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/binding.gyp +63 -0
- package/index.js +77 -0
- package/lib/index.cpp +3 -0
- package/lib/nodejieba.cpp +218 -0
- package/lib/nodejieba.h +28 -0
- package/lib/utils.h +47 -0
- package/package.json +48 -0
- package/submodules/cppjieba/.github/workflows/cmake.yml +51 -0
- package/submodules/cppjieba/.github/workflows/stale-issues.yml +24 -0
- package/submodules/cppjieba/.gitmodules +3 -0
- package/submodules/cppjieba/CHANGELOG.md +305 -0
- package/submodules/cppjieba/CMakeLists.txt +42 -0
- package/submodules/cppjieba/LICENSE +20 -0
- package/submodules/cppjieba/README.md +280 -0
- package/submodules/cppjieba/deps/limonp/.github/workflows/cmake.yml +43 -0
- package/submodules/cppjieba/deps/limonp/.gitmodules +0 -0
- package/submodules/cppjieba/deps/limonp/CHANGELOG.md +160 -0
- package/submodules/cppjieba/deps/limonp/CMakeLists.txt +61 -0
- package/submodules/cppjieba/deps/limonp/LICENSE +20 -0
- package/submodules/cppjieba/deps/limonp/README.md +38 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/ArgvContext.hpp +70 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Closure.hpp +206 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Colors.hpp +31 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Condition.hpp +38 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Config.hpp +103 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/ForcePublic.hpp +7 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/LocalVector.hpp +139 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/Logging.hpp +90 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/NonCopyable.hpp +21 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/StdExtension.hpp +157 -0
- package/submodules/cppjieba/deps/limonp/include/limonp/StringUtil.hpp +386 -0
- package/submodules/cppjieba/deps/limonp/test/CMakeLists.txt +8 -0
- package/submodules/cppjieba/deps/limonp/test/demo.cpp +40 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/1.conf +5 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/StdExtension.data +3 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/dict.gbk +50 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/dict.utf8 +50 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/io_testfile +2 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.0.1.utf8 +93 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.0.utf8 +93 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.1.utf8 +67 -0
- package/submodules/cppjieba/deps/limonp/test/testdata/jieba.dict.2.utf8 +64 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/CMakeLists.txt +30 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TArgvContext.cpp +16 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TCastFloat.cpp +19 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TClosure.cpp +85 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TColorPrint.cpp +20 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TConfig.cpp +17 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TLocalVector.cpp +41 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TLogging.cpp +12 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TStdExtension.cpp +95 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/TStringUtil.cpp +183 -0
- package/submodules/cppjieba/deps/limonp/test/unittest/gtest_main.cpp +39 -0
- package/submodules/cppjieba/dict/README.md +31 -0
- package/submodules/cppjieba/dict/hmm_model.utf8 +34 -0
- package/submodules/cppjieba/dict/idf.utf8 +258826 -0
- package/submodules/cppjieba/dict/jieba.dict.utf8 +348982 -0
- package/submodules/cppjieba/dict/pos_dict/char_state_tab.utf8 +6653 -0
- package/submodules/cppjieba/dict/pos_dict/prob_emit.utf8 +166 -0
- package/submodules/cppjieba/dict/pos_dict/prob_start.utf8 +259 -0
- package/submodules/cppjieba/dict/pos_dict/prob_trans.utf8 +5222 -0
- package/submodules/cppjieba/dict/stop_words.utf8 +1534 -0
- package/submodules/cppjieba/dict/user.dict.utf8 +4 -0
- package/submodules/cppjieba/include/cppjieba/DictTrie.hpp +381 -0
- package/submodules/cppjieba/include/cppjieba/FullSegment.hpp +93 -0
- package/submodules/cppjieba/include/cppjieba/HMMModel.hpp +129 -0
- package/submodules/cppjieba/include/cppjieba/HMMSegment.hpp +190 -0
- package/submodules/cppjieba/include/cppjieba/Jieba.hpp +169 -0
- package/submodules/cppjieba/include/cppjieba/KeywordExtractor.hpp +153 -0
- package/submodules/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
- package/submodules/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
- package/submodules/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
- package/submodules/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
- package/submodules/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
- package/submodules/cppjieba/include/cppjieba/SegmentBase.hpp +48 -0
- package/submodules/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
- package/submodules/cppjieba/include/cppjieba/TextRankExtractor.hpp +190 -0
- package/submodules/cppjieba/include/cppjieba/Trie.hpp +200 -0
- package/submodules/cppjieba/include/cppjieba/Unicode.hpp +231 -0
- package/submodules/cppjieba/test/CMakeLists.txt +4 -0
- package/submodules/cppjieba/test/load_test.cpp +54 -0
- package/submodules/cppjieba/test/testdata/curl.res +1 -0
- package/submodules/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +109750 -0
- package/submodules/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +34 -0
- package/submodules/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +348982 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.0.1.utf8 +93 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.0.utf8 +93 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.1.utf8 +67 -0
- package/submodules/cppjieba/test/testdata/jieba.dict.2.utf8 +64 -0
- package/submodules/cppjieba/test/testdata/load_test.urls +2 -0
- package/submodules/cppjieba/test/testdata/review.100 +100 -0
- package/submodules/cppjieba/test/testdata/review.100.res +200 -0
- package/submodules/cppjieba/test/testdata/server.conf +19 -0
- package/submodules/cppjieba/test/testdata/testlines.gbk +9 -0
- package/submodules/cppjieba/test/testdata/testlines.utf8 +8 -0
- package/submodules/cppjieba/test/testdata/userdict.2.utf8 +1 -0
- package/submodules/cppjieba/test/testdata/userdict.english +2 -0
- package/submodules/cppjieba/test/testdata/userdict.utf8 +8 -0
- package/submodules/cppjieba/test/testdata/weicheng.utf8 +247 -0
- package/submodules/cppjieba/test/unittest/CMakeLists.txt +33 -0
- package/submodules/cppjieba/test/unittest/gtest_main.cpp +39 -0
- package/submodules/cppjieba/test/unittest/jieba_test.cpp +166 -0
- package/submodules/cppjieba/test/unittest/keyword_extractor_test.cpp +79 -0
- package/submodules/cppjieba/test/unittest/pos_tagger_test.cpp +41 -0
- package/submodules/cppjieba/test/unittest/pre_filter_test.cpp +43 -0
- package/submodules/cppjieba/test/unittest/segments_test.cpp +256 -0
- package/submodules/cppjieba/test/unittest/textrank_test.cpp +86 -0
- package/submodules/cppjieba/test/unittest/trie_test.cpp +177 -0
- package/submodules/cppjieba/test/unittest/unicode_test.cpp +43 -0
- package/test/debug_split +0 -0
- package/test/debug_split2 +0 -0
- package/test/debug_split3 +0 -0
- package/test/load_dict_test.js +14 -0
- package/test/missing_binding_test.js +42 -0
- package/test/test.js +366 -0
- package/test/testdata/userdict.utf8 +1 -0
- package/tsconfig.json +59 -0
- package/types/index.d.ts +30 -0
- package/typescript_demo.ts +38 -0
|
File without changes
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## v1.0.0
|
|
4
|
+
|
|
5
|
+
+ rm thread pool demo
|
|
6
|
+
+ deleted: include/limonp/BlockingQueue.hpp
|
|
7
|
+
+ deleted: include/limonp/BoundedBlockingQueue.hpp
|
|
8
|
+
+ deleted: include/limonp/BoundedQueue.hpp
|
|
9
|
+
+ deleted: include/limonp/MutexLock.hpp
|
|
10
|
+
+ deleted: include/limonp/Thread.hpp
|
|
11
|
+
+ deleted: include/limonp/ThreadPool.hpp
|
|
12
|
+
+ deleted: test/unittest/TBlockingQueue.cpp
|
|
13
|
+
+ deleted: test/unittest/TBoundedQueue.cpp
|
|
14
|
+
+ deleted: test/unittest/TMutexLock.cpp
|
|
15
|
+
+ deleted: test/unittest/TThread.cpp
|
|
16
|
+
+ deleted: test/unittest/TThreadPool.cpp
|
|
17
|
+
+ rm FileLock
|
|
18
|
+
+ rm Md5.hpp
|
|
19
|
+
|
|
20
|
+
## v0.9.0
|
|
21
|
+
|
|
22
|
+
+ [c++20] compatibility
|
|
23
|
+
+ [c++17] compatibility
|
|
24
|
+
|
|
25
|
+
## v0.8.1
|
|
26
|
+
|
|
27
|
+
+ [CI] fix windows gtest thread link error
|
|
28
|
+
+ [submodule] rm test/googletest
|
|
29
|
+
+ [CMake] FetchContent googletest
|
|
30
|
+
+ [CMake] required 3.5 -> 3.14
|
|
31
|
+
|
|
32
|
+
## v0.8.0
|
|
33
|
+
|
|
34
|
+
+ [StringUtil] Fix windows assert typo
|
|
35
|
+
+ [CMake] find_package(Threads REQUIRED); target_link_libraries(... Threads::Threads)
|
|
36
|
+
+ [CMAKE][CI] windows: 2019,2022
|
|
37
|
+
+ [CMAKE][CI] matrix.build_type[Release, Debug]
|
|
38
|
+
+ [unittest] disable #TMd5.cpp
|
|
39
|
+
+ [unittest] disable #TFileLock.cpp
|
|
40
|
+
+ [unittest] disable #TBoundedQueue.cpp
|
|
41
|
+
+ [unittest] disable #TMutexLock.cpp
|
|
42
|
+
+ [unittest] disable #TBlockingQueue.cpp
|
|
43
|
+
+ [unittest] disable #TThread.cpp
|
|
44
|
+
+ [unittest] disable #TThreadPool.cpp
|
|
45
|
+
|
|
46
|
+
## v0.7.2
|
|
47
|
+
|
|
48
|
+
+ [CI] ubuntu version from 20 to 22, macos version from 12 to 14
|
|
49
|
+
+ [test/unittes] uint->size_t
|
|
50
|
+
+ [googletest] v1.6.0->v1.10.0
|
|
51
|
+
+ [CMake] version required 3.0 -> 3.5
|
|
52
|
+
|
|
53
|
+
## v0.7.1
|
|
54
|
+
|
|
55
|
+
+ [CMake] fix CMAKE_CXX_STANDARD passed from github/actions and [c++11, c++14] only
|
|
56
|
+
|
|
57
|
+
## v0.7.0
|
|
58
|
+
|
|
59
|
+
+ [CI] Added os.macos and cpp_version=[c++98, c++03, c++11, c++14, c++17, c++20]
|
|
60
|
+
+ [git submodule] Added googletest-release-v1.6.0
|
|
61
|
+
|
|
62
|
+
## v0.6.7
|
|
63
|
+
|
|
64
|
+
+ Merged [pr35](https://github.com/yanyiwu/limonp/pull/35)
|
|
65
|
+
+ Merged [pr33](https://github.com/yanyiwu/limonp/pull/33)
|
|
66
|
+
+ Merged [pr32](https://github.com/yanyiwu/limonp/pull/32)
|
|
67
|
+
|
|
68
|
+
## v0.6.6
|
|
69
|
+
|
|
70
|
+
+ Merged [pr-31 To be compatible with cpp17 and later, use lambda instead of std::not1 & std::bind2nd #31](https://github.com/yanyiwu/limonp/pull/31)
|
|
71
|
+
|
|
72
|
+
## v0.6.5
|
|
73
|
+
|
|
74
|
+
+ Merged [pr-25 Update cmake.yml](https://github.com/yanyiwu/limonp/pull/25)
|
|
75
|
+
+ Merged [pr-26 fix license for end of line sequence and remove useless signature](https://github.com/yanyiwu/limonp/pull/26)
|
|
76
|
+
+ Merged [pr-27 Update cmake.yml](https://github.com/yanyiwu/limonp/pull/27)
|
|
77
|
+
+ Merged [pr-28 add a target to be ready to support installation](https://github.com/yanyiwu/limonp/pull/28)
|
|
78
|
+
+ Merged [pr-29 Installable by cmake](https://github.com/yanyiwu/limonp/pull/29)
|
|
79
|
+
+ Merged [pr-30 Replace localtime with localtime_s on Windows and localtime_r on Linux](https://github.com/yanyiwu/limonp/pull/30)
|
|
80
|
+
|
|
81
|
+
## v0.6.4
|
|
82
|
+
|
|
83
|
+
+ merge [fixup gcc8 warnings](https://github.com/yanyiwu/gojieba/pull/70)
|
|
84
|
+
|
|
85
|
+
## v0.6.3
|
|
86
|
+
|
|
87
|
+
+ remove compiler conplained macro
|
|
88
|
+
|
|
89
|
+
## v0.6.2
|
|
90
|
+
|
|
91
|
+
+ merge [pr-18](https://github.com/yanyiwu/limonp/pull/18/files)
|
|
92
|
+
|
|
93
|
+
## v0.6.1
|
|
94
|
+
|
|
95
|
+
add Specialized template for vector<string>
|
|
96
|
+
|
|
97
|
+
when it is `vector<string>`, print like this: ["hello", "world"]; (special case)
|
|
98
|
+
when it is `vector<int>`, print like this: [1, 10, 1000]; (common cases)
|
|
99
|
+
|
|
100
|
+
## v0.6.0
|
|
101
|
+
|
|
102
|
+
+ remove Trim out of Split.
|
|
103
|
+
|
|
104
|
+
## v0.5.6
|
|
105
|
+
|
|
106
|
+
+ fix hidden trouble.
|
|
107
|
+
|
|
108
|
+
## v0.5.5
|
|
109
|
+
|
|
110
|
+
+ macro name LOG and CHECK in Logging.hpp is so easy to confict with other lib, so I have to rename them to XLOG and XCHECK for avoiding those macro name conflicts.
|
|
111
|
+
|
|
112
|
+
## v0.5.4
|
|
113
|
+
|
|
114
|
+
+ add ForcePublic.hpp
|
|
115
|
+
+ Add Utf8ToUnicode32 and Unicode32ToUtf8 in StringUtil.hpp
|
|
116
|
+
|
|
117
|
+
## v0.5.3
|
|
118
|
+
|
|
119
|
+
+ Fix incompatibility problem about 'time.h' in Windows.
|
|
120
|
+
|
|
121
|
+
## v0.5.2
|
|
122
|
+
|
|
123
|
+
+ Fix incompatibility problem about `enum {INFO ...}` name conflicts in Windows .
|
|
124
|
+
+ So from this version begin: the compile flags: `-DLOGGING_LEVEL=WARNING` must be changed to `-DLOGGING_LEVEL=LL_WARNING`
|
|
125
|
+
|
|
126
|
+
## v0.5.1
|
|
127
|
+
|
|
128
|
+
+ add `ThreadPool::Stop()` to wait util all the threads finished.
|
|
129
|
+
If Stop() has not been called, it will be called when the ThreadPool destructing.
|
|
130
|
+
|
|
131
|
+
## v0.5.0
|
|
132
|
+
|
|
133
|
+
+ Reorganized directories: include/ -> include/limonp/ ... and so on.
|
|
134
|
+
+ Add `NewClosure` in Closure.hpp, 0~3 arguments have been supported.
|
|
135
|
+
+ Update ThreadPool, use `NewClosure` instead of `CreateTask`
|
|
136
|
+
|
|
137
|
+
## v0.4.1
|
|
138
|
+
|
|
139
|
+
+ `CHECK(exp) << "log message"` supported;
|
|
140
|
+
|
|
141
|
+
## v0.4.0
|
|
142
|
+
|
|
143
|
+
+ add test/demo.cc as example.
|
|
144
|
+
+ move `print` macro to StdExtension.hpp
|
|
145
|
+
+ BigChange: rewrite `log` module, use `LOG(INFO) << "xxx" ` instead `LogInfo` .
|
|
146
|
+
+ remove HandyMacro.hpp, add CHECK in Logging.hpp instead.
|
|
147
|
+
|
|
148
|
+
## v0.3.0
|
|
149
|
+
|
|
150
|
+
+ remove 'MysqlClient.hpp', 'InitOnOff.hpp', 'CastFloat.hpp'
|
|
151
|
+
+ add 'Closure.hpp'
|
|
152
|
+
+ uniform code style
|
|
153
|
+
|
|
154
|
+
## v0.2.0
|
|
155
|
+
|
|
156
|
+
+ `namespace limonp`, not `Limonp` .
|
|
157
|
+
|
|
158
|
+
## v0.1.0
|
|
159
|
+
|
|
160
|
+
+ Basic functions
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.14)
|
|
2
|
+
|
|
3
|
+
PROJECT(limonp
|
|
4
|
+
LANGUAGES CXX)
|
|
5
|
+
|
|
6
|
+
################
|
|
7
|
+
# cmake config #
|
|
8
|
+
################
|
|
9
|
+
|
|
10
|
+
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
|
11
|
+
set(CMAKE_CXX_STANDARD 11)
|
|
12
|
+
endif()
|
|
13
|
+
message(STATUS "CMAKE_CXX_STANDARD is ${CMAKE_CXX_STANDARD}")
|
|
14
|
+
|
|
15
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
16
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
##############
|
|
20
|
+
# dependency #
|
|
21
|
+
##############
|
|
22
|
+
include(GNUInstallDirs)
|
|
23
|
+
|
|
24
|
+
##########
|
|
25
|
+
# target #
|
|
26
|
+
##########
|
|
27
|
+
|
|
28
|
+
add_library(${PROJECT_NAME} INTERFACE)
|
|
29
|
+
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
|
30
|
+
|
|
31
|
+
target_include_directories(${PROJECT_NAME}
|
|
32
|
+
INTERFACE
|
|
33
|
+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
|
34
|
+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>)
|
|
35
|
+
|
|
36
|
+
########
|
|
37
|
+
# test #
|
|
38
|
+
########
|
|
39
|
+
|
|
40
|
+
ENABLE_TESTING()
|
|
41
|
+
|
|
42
|
+
ADD_SUBDIRECTORY(test)
|
|
43
|
+
ADD_TEST(NAME ./test/demo COMMAND ./test/demo)
|
|
44
|
+
ADD_TEST(NAME ./test/test.run COMMAND ./test/test.run)
|
|
45
|
+
|
|
46
|
+
###########
|
|
47
|
+
# install #
|
|
48
|
+
###########
|
|
49
|
+
|
|
50
|
+
include(GNUInstallDirs)
|
|
51
|
+
|
|
52
|
+
install(TARGETS ${PROJECT_NAME}
|
|
53
|
+
EXPORT ${PROJECT_NAME})
|
|
54
|
+
|
|
55
|
+
install(EXPORT ${PROJECT_NAME}
|
|
56
|
+
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake/
|
|
57
|
+
NAMESPACE ${PROJECT_NAME}::
|
|
58
|
+
FILE ${PROJECT_NAME}-config.cmake)
|
|
59
|
+
|
|
60
|
+
install(DIRECTORY include/
|
|
61
|
+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# limonp
|
|
2
|
+
|
|
3
|
+
[](https://github.com/yanyiwu/limonp/actions/workflows/cmake.yml)
|
|
4
|
+
[](http://yanyiwu.com/)
|
|
5
|
+
[](https://github.com/yanyiwu/limonp)
|
|
6
|
+
[](https://github.com/yanyiwu/limonp/releases)
|
|
7
|
+
[](http://yanyiwu.mit-license.org)
|
|
8
|
+
|
|
9
|
+
## Introduction
|
|
10
|
+
|
|
11
|
+
`C++` headers(hpp) with Python style.
|
|
12
|
+
|
|
13
|
+
## Feature
|
|
14
|
+
|
|
15
|
+
+ linking is a annoying thing, so I write these source code in headers file(`*.hpp`), you can use them only with `#include "xx.hpp"`, without linking *.a or *.so .
|
|
16
|
+
|
|
17
|
+
**`no linking , no hurts`**
|
|
18
|
+
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
See Details in `test/demo.cpp`
|
|
22
|
+
|
|
23
|
+
## Cases
|
|
24
|
+
|
|
25
|
+
1. [CppJieba]
|
|
26
|
+
|
|
27
|
+
## Reference
|
|
28
|
+
|
|
29
|
+
1. `md5.hpp` is copied from network, you can find original author in source code(in comments).
|
|
30
|
+
2. `MutexLock.hpp`, `BlockingQueue.hpp`, `Condition.hpp` reference from [muduo].
|
|
31
|
+
|
|
32
|
+
## Contact
|
|
33
|
+
|
|
34
|
+
+ i@yanyiwu.com
|
|
35
|
+
|
|
36
|
+
[CppJieba]:https://github.com/yanyiwu/cppjieba.git
|
|
37
|
+
[muduo]:https://github.com/chenshuo/muduo.git
|
|
38
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/************************************
|
|
2
|
+
* file enc : ascii
|
|
3
|
+
* author : wuyanyi09@gmail.com
|
|
4
|
+
************************************/
|
|
5
|
+
|
|
6
|
+
#ifndef LIMONP_ARGV_FUNCTS_H
|
|
7
|
+
#define LIMONP_ARGV_FUNCTS_H
|
|
8
|
+
|
|
9
|
+
#include <set>
|
|
10
|
+
#include <sstream>
|
|
11
|
+
#include "StringUtil.hpp"
|
|
12
|
+
|
|
13
|
+
namespace limonp {
|
|
14
|
+
|
|
15
|
+
using namespace std;
|
|
16
|
+
|
|
17
|
+
class ArgvContext {
|
|
18
|
+
public :
|
|
19
|
+
ArgvContext(int argc, const char* const * argv) {
|
|
20
|
+
for(int i = 0; i < argc; i++) {
|
|
21
|
+
if(StartsWith(argv[i], "-")) {
|
|
22
|
+
if(i + 1 < argc && !StartsWith(argv[i + 1], "-")) {
|
|
23
|
+
mpss_[argv[i]] = argv[i+1];
|
|
24
|
+
i++;
|
|
25
|
+
} else {
|
|
26
|
+
sset_.insert(argv[i]);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
args_.push_back(argv[i]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
~ArgvContext() {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
friend ostream& operator << (ostream& os, const ArgvContext& args);
|
|
37
|
+
string operator [](size_t i) const {
|
|
38
|
+
if(i < args_.size()) {
|
|
39
|
+
return args_[i];
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
string operator [](const string& key) const {
|
|
44
|
+
map<string, string>::const_iterator it = mpss_.find(key);
|
|
45
|
+
if(it != mpss_.end()) {
|
|
46
|
+
return it->second;
|
|
47
|
+
}
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
bool HasKey(const string& key) const {
|
|
52
|
+
if(mpss_.find(key) != mpss_.end() || sset_.find(key) != sset_.end()) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
vector<string> args_;
|
|
60
|
+
map<string, string> mpss_;
|
|
61
|
+
set<string> sset_;
|
|
62
|
+
}; // class ArgvContext
|
|
63
|
+
|
|
64
|
+
inline ostream& operator << (ostream& os, const ArgvContext& args) {
|
|
65
|
+
return os<<args.args_<<args.mpss_<<args.sset_;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
} // namespace limonp
|
|
69
|
+
|
|
70
|
+
#endif
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#ifndef LIMONP_CLOSURE_HPP
|
|
2
|
+
#define LIMONP_CLOSURE_HPP
|
|
3
|
+
|
|
4
|
+
namespace limonp {
|
|
5
|
+
|
|
6
|
+
class ClosureInterface {
|
|
7
|
+
public:
|
|
8
|
+
virtual ~ClosureInterface() {
|
|
9
|
+
}
|
|
10
|
+
virtual void Run() = 0;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
template <class Funct>
|
|
14
|
+
class Closure0: public ClosureInterface {
|
|
15
|
+
public:
|
|
16
|
+
Closure0(Funct fun) {
|
|
17
|
+
fun_ = fun;
|
|
18
|
+
}
|
|
19
|
+
virtual ~Closure0() {
|
|
20
|
+
}
|
|
21
|
+
virtual void Run() {
|
|
22
|
+
(*fun_)();
|
|
23
|
+
}
|
|
24
|
+
private:
|
|
25
|
+
Funct fun_;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
template <class Funct, class Arg1>
|
|
29
|
+
class Closure1: public ClosureInterface {
|
|
30
|
+
public:
|
|
31
|
+
Closure1(Funct fun, Arg1 arg1) {
|
|
32
|
+
fun_ = fun;
|
|
33
|
+
arg1_ = arg1;
|
|
34
|
+
}
|
|
35
|
+
virtual ~Closure1() {
|
|
36
|
+
}
|
|
37
|
+
virtual void Run() {
|
|
38
|
+
(*fun_)(arg1_);
|
|
39
|
+
}
|
|
40
|
+
private:
|
|
41
|
+
Funct fun_;
|
|
42
|
+
Arg1 arg1_;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
template <class Funct, class Arg1, class Arg2>
|
|
46
|
+
class Closure2: public ClosureInterface {
|
|
47
|
+
public:
|
|
48
|
+
Closure2(Funct fun, Arg1 arg1, Arg2 arg2) {
|
|
49
|
+
fun_ = fun;
|
|
50
|
+
arg1_ = arg1;
|
|
51
|
+
arg2_ = arg2;
|
|
52
|
+
}
|
|
53
|
+
virtual ~Closure2() {
|
|
54
|
+
}
|
|
55
|
+
virtual void Run() {
|
|
56
|
+
(*fun_)(arg1_, arg2_);
|
|
57
|
+
}
|
|
58
|
+
private:
|
|
59
|
+
Funct fun_;
|
|
60
|
+
Arg1 arg1_;
|
|
61
|
+
Arg2 arg2_;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
template <class Funct, class Arg1, class Arg2, class Arg3>
|
|
65
|
+
class Closure3: public ClosureInterface {
|
|
66
|
+
public:
|
|
67
|
+
Closure3(Funct fun, Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
68
|
+
fun_ = fun;
|
|
69
|
+
arg1_ = arg1;
|
|
70
|
+
arg2_ = arg2;
|
|
71
|
+
arg3_ = arg3;
|
|
72
|
+
}
|
|
73
|
+
virtual ~Closure3() {
|
|
74
|
+
}
|
|
75
|
+
virtual void Run() {
|
|
76
|
+
(*fun_)(arg1_, arg2_, arg3_);
|
|
77
|
+
}
|
|
78
|
+
private:
|
|
79
|
+
Funct fun_;
|
|
80
|
+
Arg1 arg1_;
|
|
81
|
+
Arg2 arg2_;
|
|
82
|
+
Arg3 arg3_;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
template <class Obj, class Funct>
|
|
86
|
+
class ObjClosure0: public ClosureInterface {
|
|
87
|
+
public:
|
|
88
|
+
ObjClosure0(Obj* p, Funct fun) {
|
|
89
|
+
p_ = p;
|
|
90
|
+
fun_ = fun;
|
|
91
|
+
}
|
|
92
|
+
virtual ~ObjClosure0() {
|
|
93
|
+
}
|
|
94
|
+
virtual void Run() {
|
|
95
|
+
(p_->*fun_)();
|
|
96
|
+
}
|
|
97
|
+
private:
|
|
98
|
+
Obj* p_;
|
|
99
|
+
Funct fun_;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
template <class Obj, class Funct, class Arg1>
|
|
103
|
+
class ObjClosure1: public ClosureInterface {
|
|
104
|
+
public:
|
|
105
|
+
ObjClosure1(Obj* p, Funct fun, Arg1 arg1) {
|
|
106
|
+
p_ = p;
|
|
107
|
+
fun_ = fun;
|
|
108
|
+
arg1_ = arg1;
|
|
109
|
+
}
|
|
110
|
+
virtual ~ObjClosure1() {
|
|
111
|
+
}
|
|
112
|
+
virtual void Run() {
|
|
113
|
+
(p_->*fun_)(arg1_);
|
|
114
|
+
}
|
|
115
|
+
private:
|
|
116
|
+
Obj* p_;
|
|
117
|
+
Funct fun_;
|
|
118
|
+
Arg1 arg1_;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
template <class Obj, class Funct, class Arg1, class Arg2>
|
|
122
|
+
class ObjClosure2: public ClosureInterface {
|
|
123
|
+
public:
|
|
124
|
+
ObjClosure2(Obj* p, Funct fun, Arg1 arg1, Arg2 arg2) {
|
|
125
|
+
p_ = p;
|
|
126
|
+
fun_ = fun;
|
|
127
|
+
arg1_ = arg1;
|
|
128
|
+
arg2_ = arg2;
|
|
129
|
+
}
|
|
130
|
+
virtual ~ObjClosure2() {
|
|
131
|
+
}
|
|
132
|
+
virtual void Run() {
|
|
133
|
+
(p_->*fun_)(arg1_, arg2_);
|
|
134
|
+
}
|
|
135
|
+
private:
|
|
136
|
+
Obj* p_;
|
|
137
|
+
Funct fun_;
|
|
138
|
+
Arg1 arg1_;
|
|
139
|
+
Arg2 arg2_;
|
|
140
|
+
};
|
|
141
|
+
template <class Obj, class Funct, class Arg1, class Arg2, class Arg3>
|
|
142
|
+
class ObjClosure3: public ClosureInterface {
|
|
143
|
+
public:
|
|
144
|
+
ObjClosure3(Obj* p, Funct fun, Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
145
|
+
p_ = p;
|
|
146
|
+
fun_ = fun;
|
|
147
|
+
arg1_ = arg1;
|
|
148
|
+
arg2_ = arg2;
|
|
149
|
+
arg3_ = arg3;
|
|
150
|
+
}
|
|
151
|
+
virtual ~ObjClosure3() {
|
|
152
|
+
}
|
|
153
|
+
virtual void Run() {
|
|
154
|
+
(p_->*fun_)(arg1_, arg2_, arg3_);
|
|
155
|
+
}
|
|
156
|
+
private:
|
|
157
|
+
Obj* p_;
|
|
158
|
+
Funct fun_;
|
|
159
|
+
Arg1 arg1_;
|
|
160
|
+
Arg2 arg2_;
|
|
161
|
+
Arg3 arg3_;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
template<class R>
|
|
165
|
+
ClosureInterface* NewClosure(R (*fun)()) {
|
|
166
|
+
return new Closure0<R (*)()>(fun);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
template<class R, class Arg1>
|
|
170
|
+
ClosureInterface* NewClosure(R (*fun)(Arg1), Arg1 arg1) {
|
|
171
|
+
return new Closure1<R (*)(Arg1), Arg1>(fun, arg1);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
template<class R, class Arg1, class Arg2>
|
|
175
|
+
ClosureInterface* NewClosure(R (*fun)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) {
|
|
176
|
+
return new Closure2<R (*)(Arg1, Arg2), Arg1, Arg2>(fun, arg1, arg2);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
template<class R, class Arg1, class Arg2, class Arg3>
|
|
180
|
+
ClosureInterface* NewClosure(R (*fun)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
181
|
+
return new Closure3<R (*)(Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(fun, arg1, arg2, arg3);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
template<class R, class Obj>
|
|
185
|
+
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)()) {
|
|
186
|
+
return new ObjClosure0<Obj, R (Obj::* )()>(obj, fun);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
template<class R, class Obj, class Arg1>
|
|
190
|
+
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1), Arg1 arg1) {
|
|
191
|
+
return new ObjClosure1<Obj, R (Obj::* )(Arg1), Arg1>(obj, fun, arg1);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
template<class R, class Obj, class Arg1, class Arg2>
|
|
195
|
+
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) {
|
|
196
|
+
return new ObjClosure2<Obj, R (Obj::*)(Arg1, Arg2), Arg1, Arg2>(obj, fun, arg1, arg2);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
template<class R, class Obj, class Arg1, class Arg2, class Arg3>
|
|
200
|
+
ClosureInterface* NewClosure(Obj* obj, R (Obj::* fun)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) {
|
|
201
|
+
return new ObjClosure3<Obj, R (Obj::*)(Arg1, Arg2, Arg3), Arg1, Arg2, Arg3>(obj, fun, arg1, arg2, arg3);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
} // namespace limonp
|
|
205
|
+
|
|
206
|
+
#endif // LIMONP_CLOSURE_HPP
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#ifndef LIMONP_COLOR_PRINT_HPP
|
|
2
|
+
#define LIMONP_COLOR_PRINT_HPP
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <stdarg.h>
|
|
6
|
+
|
|
7
|
+
namespace limonp {
|
|
8
|
+
|
|
9
|
+
using std::string;
|
|
10
|
+
|
|
11
|
+
enum Color {
|
|
12
|
+
BLACK = 30,
|
|
13
|
+
RED,
|
|
14
|
+
GREEN,
|
|
15
|
+
YELLOW,
|
|
16
|
+
BLUE,
|
|
17
|
+
PURPLE
|
|
18
|
+
}; // enum Color
|
|
19
|
+
|
|
20
|
+
static void ColorPrintln(enum Color color, const char * fmt, ...) {
|
|
21
|
+
va_list ap;
|
|
22
|
+
printf("\033[0;%dm", color);
|
|
23
|
+
va_start(ap, fmt);
|
|
24
|
+
vprintf(fmt, ap);
|
|
25
|
+
va_end(ap);
|
|
26
|
+
printf("\033[0m\n"); // if not \n , in some situation , the next lines will be set the same color unexpectedly
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace limonp
|
|
30
|
+
|
|
31
|
+
#endif // LIMONP_COLOR_PRINT_HPP
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#ifndef LIMONP_CONDITION_HPP
|
|
2
|
+
#define LIMONP_CONDITION_HPP
|
|
3
|
+
|
|
4
|
+
#include "MutexLock.hpp"
|
|
5
|
+
|
|
6
|
+
namespace limonp {
|
|
7
|
+
|
|
8
|
+
class Condition : NonCopyable {
|
|
9
|
+
public:
|
|
10
|
+
explicit Condition(MutexLock& mutex)
|
|
11
|
+
: mutex_(mutex) {
|
|
12
|
+
XCHECK(!pthread_cond_init(&pcond_, NULL));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
~Condition() {
|
|
16
|
+
XCHECK(!pthread_cond_destroy(&pcond_));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void Wait() {
|
|
20
|
+
XCHECK(!pthread_cond_wait(&pcond_, mutex_.GetPthreadMutex()));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void Notify() {
|
|
24
|
+
XCHECK(!pthread_cond_signal(&pcond_));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void NotifyAll() {
|
|
28
|
+
XCHECK(!pthread_cond_broadcast(&pcond_));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private:
|
|
32
|
+
MutexLock& mutex_;
|
|
33
|
+
pthread_cond_t pcond_;
|
|
34
|
+
}; // class Condition
|
|
35
|
+
|
|
36
|
+
} // namespace limonp
|
|
37
|
+
|
|
38
|
+
#endif // LIMONP_CONDITION_HPP
|