ooxml_crypt 0.1.0
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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/ooxml_crypt/extconf.rb +18 -0
- data/ext/ooxml_crypt/ooxml_crypt.c +27 -0
- data/ext/ooxml_crypt/ooxml_crypt.h +7 -0
- data/lib/ooxml_crypt/version.rb +5 -0
- data/lib/ooxml_crypt.rb +75 -0
- data/vendor/cybozulib/.github/workflows/main.yml +12 -0
- data/vendor/cybozulib/.gitignore +5 -0
- data/vendor/cybozulib/CMakeLists.txt +6 -0
- data/vendor/cybozulib/COPYRIGHT +27 -0
- data/vendor/cybozulib/Makefile +26 -0
- data/vendor/cybozulib/bin/libeay32.dll +0 -0
- data/vendor/cybozulib/bin/libmecab.dll +0 -0
- data/vendor/cybozulib/bin/ssleay32.dll +0 -0
- data/vendor/cybozulib/common.mk +116 -0
- data/vendor/cybozulib/common.props +25 -0
- data/vendor/cybozulib/cybozulib.sln +286 -0
- data/vendor/cybozulib/debug.props +14 -0
- data/vendor/cybozulib/include/cybozu/array.hpp +197 -0
- data/vendor/cybozulib/include/cybozu/atoi.hpp +238 -0
- data/vendor/cybozulib/include/cybozu/atomic.hpp +146 -0
- data/vendor/cybozulib/include/cybozu/base64.hpp +210 -0
- data/vendor/cybozulib/include/cybozu/benchmark.hpp +212 -0
- data/vendor/cybozulib/include/cybozu/bfd.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/bit_operation.hpp +139 -0
- data/vendor/cybozulib/include/cybozu/bitvector.hpp +358 -0
- data/vendor/cybozulib/include/cybozu/condition_variable.hpp +113 -0
- data/vendor/cybozulib/include/cybozu/condition_variable_cs.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/config.hpp +392 -0
- data/vendor/cybozulib/include/cybozu/critical_section.hpp +60 -0
- data/vendor/cybozulib/include/cybozu/crypto.hpp +321 -0
- data/vendor/cybozulib/include/cybozu/csucvector.hpp +624 -0
- data/vendor/cybozulib/include/cybozu/csv.hpp +294 -0
- data/vendor/cybozulib/include/cybozu/data_type.hpp +27 -0
- data/vendor/cybozulib/include/cybozu/endian.hpp +224 -0
- data/vendor/cybozulib/include/cybozu/env.hpp +63 -0
- data/vendor/cybozulib/include/cybozu/event.hpp +122 -0
- data/vendor/cybozulib/include/cybozu/exception.hpp +253 -0
- data/vendor/cybozulib/include/cybozu/file.hpp +626 -0
- data/vendor/cybozulib/include/cybozu/fmindex.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/format.hpp +93 -0
- data/vendor/cybozulib/include/cybozu/frequency.hpp +264 -0
- data/vendor/cybozulib/include/cybozu/hash.hpp +67 -0
- data/vendor/cybozulib/include/cybozu/inttype.hpp +174 -0
- data/vendor/cybozulib/include/cybozu/itoa.hpp +336 -0
- data/vendor/cybozulib/include/cybozu/json.hpp +120 -0
- data/vendor/cybozulib/include/cybozu/line_stream.hpp +149 -0
- data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +21 -0
- data/vendor/cybozulib/include/cybozu/link_mpir.hpp +18 -0
- data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +19 -0
- data/vendor/cybozulib/include/cybozu/log.hpp +237 -0
- data/vendor/cybozulib/include/cybozu/minixml.hpp +452 -0
- data/vendor/cybozulib/include/cybozu/mmap.hpp +143 -0
- data/vendor/cybozulib/include/cybozu/mutex.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/nlp/mecab.hpp +96 -0
- data/vendor/cybozulib/include/cybozu/nlp/plsi.hpp +315 -0
- data/vendor/cybozulib/include/cybozu/nlp/random.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/nlp/sparse.hpp +529 -0
- data/vendor/cybozulib/include/cybozu/nlp/svd.hpp +486 -0
- data/vendor/cybozulib/include/cybozu/nlp/tfidf.hpp +226 -0
- data/vendor/cybozulib/include/cybozu/nlp/top_score.hpp +75 -0
- data/vendor/cybozulib/include/cybozu/option.hpp +743 -0
- data/vendor/cybozulib/include/cybozu/parallel.hpp +88 -0
- data/vendor/cybozulib/include/cybozu/pcg.hpp +72 -0
- data/vendor/cybozulib/include/cybozu/process.hpp +324 -0
- data/vendor/cybozulib/include/cybozu/quit_signal_handler.hpp +66 -0
- data/vendor/cybozulib/include/cybozu/random_generator.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/regex.hpp +463 -0
- data/vendor/cybozulib/include/cybozu/select8.hpp +279 -0
- data/vendor/cybozulib/include/cybozu/serializer.hpp +363 -0
- data/vendor/cybozulib/include/cybozu/sha1.hpp +209 -0
- data/vendor/cybozulib/include/cybozu/sha2.hpp +506 -0
- data/vendor/cybozulib/include/cybozu/siphash.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/socket.hpp +785 -0
- data/vendor/cybozulib/include/cybozu/ssl.hpp +203 -0
- data/vendor/cybozulib/include/cybozu/stacktrace.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/stream.hpp +269 -0
- data/vendor/cybozulib/include/cybozu/string.hpp +1746 -0
- data/vendor/cybozulib/include/cybozu/string_operation.hpp +365 -0
- data/vendor/cybozulib/include/cybozu/sucvector.hpp +378 -0
- data/vendor/cybozulib/include/cybozu/test.hpp +373 -0
- data/vendor/cybozulib/include/cybozu/thread.hpp +229 -0
- data/vendor/cybozulib/include/cybozu/time.hpp +281 -0
- data/vendor/cybozulib/include/cybozu/tls.hpp +115 -0
- data/vendor/cybozulib/include/cybozu/unordered_map.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/unordered_set.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/v128.hpp +376 -0
- data/vendor/cybozulib/include/cybozu/wavelet_matrix.hpp +345 -0
- data/vendor/cybozulib/include/cybozu/xorshift.hpp +189 -0
- data/vendor/cybozulib/include/cybozu/zlib.hpp +325 -0
- data/vendor/cybozulib/include/sais.hxx +364 -0
- data/vendor/cybozulib/misc/make_select8tbl.cpp +26 -0
- data/vendor/cybozulib/mk.bat +37 -0
- data/vendor/cybozulib/readme.md +29 -0
- data/vendor/cybozulib/release.props +12 -0
- data/vendor/cybozulib/sample/Makefile +30 -0
- data/vendor/cybozulib/sample/csucvector_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.S +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.U +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.V +6 -0
- data/vendor/cybozulib/sample/data/svd/test1 +4 -0
- data/vendor/cybozulib/sample/data/svd/test2 +4 -0
- data/vendor/cybozulib/sample/desymbol.cpp +127 -0
- data/vendor/cybozulib/sample/exception_smpl.cpp +46 -0
- data/vendor/cybozulib/sample/fmindex_smpl.cpp +231 -0
- data/vendor/cybozulib/sample/log_smpl.cpp +19 -0
- data/vendor/cybozulib/sample/mecab_smpl.cpp +37 -0
- data/vendor/cybozulib/sample/option2_smpl.cpp +68 -0
- data/vendor/cybozulib/sample/option_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/plsi_smpl.cpp +207 -0
- data/vendor/cybozulib/sample/proj/exception_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/mecab_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl.vcproj +347 -0
- data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/svd_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/quit_signal_handler.cpp +30 -0
- data/vendor/cybozulib/sample/serializer_smpl.cpp +196 -0
- data/vendor/cybozulib/sample/socket_smpl.cpp +82 -0
- data/vendor/cybozulib/sample/ssl_smpl.cpp +39 -0
- data/vendor/cybozulib/sample/stacktrace_smpl.cpp +52 -0
- data/vendor/cybozulib/sample/svd_bench_smpl.cpp +143 -0
- data/vendor/cybozulib/sample/svd_smpl.cpp +94 -0
- data/vendor/cybozulib/sample/wm_bench_smpl.cpp +182 -0
- data/vendor/cybozulib/sample/zlib_smpl.cpp +41 -0
- data/vendor/cybozulib/src/Makefile +8 -0
- data/vendor/cybozulib/src/base/Makefile +19 -0
- data/vendor/cybozulib/test/Makefile +12 -0
- data/vendor/cybozulib/test/base/Makefile +37 -0
- data/vendor/cybozulib/test/base/array_test.cpp +173 -0
- data/vendor/cybozulib/test/base/atoi_test.cpp +774 -0
- data/vendor/cybozulib/test/base/atomic_test.cpp +49 -0
- data/vendor/cybozulib/test/base/base64_test.cpp +113 -0
- data/vendor/cybozulib/test/base/bit_operation_test.cpp +134 -0
- data/vendor/cybozulib/test/base/bitvector_test.cpp +204 -0
- data/vendor/cybozulib/test/base/condition_variable_cs_test.cpp +92 -0
- data/vendor/cybozulib/test/base/condition_variable_test.cpp +88 -0
- data/vendor/cybozulib/test/base/config_test.cpp +236 -0
- data/vendor/cybozulib/test/base/crypto_test.cpp +122 -0
- data/vendor/cybozulib/test/base/csucvector_test.cpp +63 -0
- data/vendor/cybozulib/test/base/csv_test.cpp +182 -0
- data/vendor/cybozulib/test/base/data/a.xml +26 -0
- data/vendor/cybozulib/test/base/endian_test.cpp +56 -0
- data/vendor/cybozulib/test/base/env_test.cpp +22 -0
- data/vendor/cybozulib/test/base/event_test.cpp +41 -0
- data/vendor/cybozulib/test/base/file_test.cpp +233 -0
- data/vendor/cybozulib/test/base/fmindex_test.cpp +118 -0
- data/vendor/cybozulib/test/base/format_test.cpp +12 -0
- data/vendor/cybozulib/test/base/frequency_test.cpp +104 -0
- data/vendor/cybozulib/test/base/itoa_test.cpp +522 -0
- data/vendor/cybozulib/test/base/line_stream_test.cpp +208 -0
- data/vendor/cybozulib/test/base/mecab_test.cpp +41 -0
- data/vendor/cybozulib/test/base/minixml_test.cpp +103 -0
- data/vendor/cybozulib/test/base/mmap_test.cpp +15 -0
- data/vendor/cybozulib/test/base/option_test.cpp +487 -0
- data/vendor/cybozulib/test/base/parallel_test.cpp +48 -0
- data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +88 -0
- data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/random_generator_test.cpp +28 -0
- data/vendor/cybozulib/test/base/regex_test.cpp +74 -0
- data/vendor/cybozulib/test/base/serializer_test.cpp +483 -0
- data/vendor/cybozulib/test/base/sha1_test.cpp +61 -0
- data/vendor/cybozulib/test/base/sha2_test.cpp +191 -0
- data/vendor/cybozulib/test/base/siphash_test.cpp +33 -0
- data/vendor/cybozulib/test/base/socket_test.cpp +76 -0
- data/vendor/cybozulib/test/base/stream_test.cpp +101 -0
- data/vendor/cybozulib/test/base/string_operation_test.cpp +340 -0
- data/vendor/cybozulib/test/base/string_test.cpp +1705 -0
- data/vendor/cybozulib/test/base/sucvector_test.cpp +312 -0
- data/vendor/cybozulib/test/base/thread_test.cpp +62 -0
- data/vendor/cybozulib/test/base/time_test.cpp +164 -0
- data/vendor/cybozulib/test/base/tls_test.cpp +50 -0
- data/vendor/cybozulib/test/base/wavelet_matrix_test.cpp +145 -0
- data/vendor/cybozulib/test/base/zlib_test.cpp +371 -0
- data/vendor/cybozulib/test/nlp/Makefile +27 -0
- data/vendor/cybozulib/test/nlp/proj/random_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/sparse_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/svd_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/random_test.cpp +62 -0
- data/vendor/cybozulib/test/nlp/sparse_test.cpp +347 -0
- data/vendor/cybozulib/test/nlp/svd_test.cpp +234 -0
- data/vendor/cybozulib/test/nlp/top_score_test.cpp +40 -0
- data/vendor/cybozulib/tool/create_vcproj.py +186 -0
- data/vendor/cybozulib/tool/vcproj_tmpl.py +185 -0
- data/vendor/msoffice/COPYRIGHT +27 -0
- data/vendor/msoffice/Makefile +29 -0
- data/vendor/msoffice/bin/64/msoc.dll +0 -0
- data/vendor/msoffice/bin/64/msocsample.exe +0 -0
- data/vendor/msoffice/bin/64/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/bin/msoc.dll +0 -0
- data/vendor/msoffice/bin/msocsample.exe +0 -0
- data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/common.mk +71 -0
- data/vendor/msoffice/common.props +26 -0
- data/vendor/msoffice/debug.props +14 -0
- data/vendor/msoffice/include/attack.hpp +211 -0
- data/vendor/msoffice/include/cfb.hpp +777 -0
- data/vendor/msoffice/include/crypto_util.hpp +450 -0
- data/vendor/msoffice/include/custom_sha1.hpp +342 -0
- data/vendor/msoffice/include/decode.hpp +240 -0
- data/vendor/msoffice/include/encode.hpp +221 -0
- data/vendor/msoffice/include/make_dataspace.hpp +316 -0
- data/vendor/msoffice/include/msoc.h +129 -0
- data/vendor/msoffice/include/resource.hpp +7 -0
- data/vendor/msoffice/include/standard_encryption.hpp +145 -0
- data/vendor/msoffice/include/uint32vec.hpp +179 -0
- data/vendor/msoffice/include/util.hpp +212 -0
- data/vendor/msoffice/lib/.emptydir +0 -0
- data/vendor/msoffice/misc/decrypt-xls.vbs +46 -0
- data/vendor/msoffice/mk.bat +1 -0
- data/vendor/msoffice/mkdll.bat +3 -0
- data/vendor/msoffice/msoc.def +13 -0
- data/vendor/msoffice/msocsample.py +178 -0
- data/vendor/msoffice/msoffice12.sln +31 -0
- data/vendor/msoffice/readme.md +110 -0
- data/vendor/msoffice/release.props +28 -0
- data/vendor/msoffice/src/Makefile +19 -0
- data/vendor/msoffice/src/attack.cpp +124 -0
- data/vendor/msoffice/src/cfb_test.cpp +77 -0
- data/vendor/msoffice/src/minisample.c +54 -0
- data/vendor/msoffice/src/msocdll.cpp +276 -0
- data/vendor/msoffice/src/msocsample.c +136 -0
- data/vendor/msoffice/src/msoffice-crypt.cpp +219 -0
- data/vendor/msoffice/src/proj/attack/attack.vcxproj +88 -0
- data/vendor/msoffice/src/proj/main/msoffice-crypt.vcxproj +88 -0
- data/vendor/msoffice/src/sha1.cpp +234 -0
- data/vendor/msoffice/test/Makefile +20 -0
- data/vendor/msoffice/test/cfb_test.cpp +74 -0
- data/vendor/msoffice/test/hash_test.cpp +59 -0
- data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +90 -0
- data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +90 -0
- data/vendor/msoffice/test/sampl.bat +8 -0
- data/vendor/msoffice/test_all.py +46 -0
- data/vendor/update +4 -0
- metadata +351 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
/**
|
|
3
|
+
@file
|
|
4
|
+
@brief string operation for cybozu::String
|
|
5
|
+
|
|
6
|
+
@author MITSUNARI Shigeo(@herumi)
|
|
7
|
+
|
|
8
|
+
@note
|
|
9
|
+
modifying functions are almost the following type:
|
|
10
|
+
void function(String& out, String& in, bool doAppend = false);
|
|
11
|
+
if doAppend is true then the function will append string to <out>.
|
|
12
|
+
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
#include <algorithm>
|
|
16
|
+
#include <vector>
|
|
17
|
+
#include <cybozu/string.hpp>
|
|
18
|
+
|
|
19
|
+
#ifdef _MSC_VER
|
|
20
|
+
#pragma warning(push)
|
|
21
|
+
#pragma warning(disable : 4389) // compare signed and unsigned
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
namespace cybozu {
|
|
25
|
+
|
|
26
|
+
namespace string {
|
|
27
|
+
|
|
28
|
+
static const bool DoAppend = true;
|
|
29
|
+
|
|
30
|
+
} // string
|
|
31
|
+
|
|
32
|
+
namespace string_local {
|
|
33
|
+
|
|
34
|
+
template<class Iterator>
|
|
35
|
+
struct CharTag{ typedef typename Iterator::value_type value_type; };
|
|
36
|
+
|
|
37
|
+
template<>struct CharTag<char*> { typedef char value_type; };
|
|
38
|
+
template<>struct CharTag<const char*> { typedef char value_type; };
|
|
39
|
+
|
|
40
|
+
template<>struct CharTag<cybozu::Char*> { typedef cybozu::Char value_type; };
|
|
41
|
+
template<>struct CharTag<const cybozu::Char*> { typedef cybozu::Char value_type; };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
verify whether c is a space or 0xfeff(BOM)
|
|
46
|
+
the definition of space is
|
|
47
|
+
http://unicode.org/Public/UNIDATA/PropList.txt
|
|
48
|
+
0009..000D ; White_Space # Cc [5] <control-0009>..<control-000D>
|
|
49
|
+
0020 ; White_Space # Zs SPACE
|
|
50
|
+
0085 ; White_Space # Cc <control-0085>
|
|
51
|
+
00A0 ; White_Space # Zs NO-BREAK SPACE
|
|
52
|
+
1680 ; White_Space # Zs OGHAM SPACE MARK
|
|
53
|
+
180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR
|
|
54
|
+
2000..200A ; White_Space # Zs [11] EN QUAD..HAIR SPACE
|
|
55
|
+
2028 ; White_Space # Zl LINE SEPARATOR
|
|
56
|
+
2029 ; White_Space # Zp PARAGRAPH SEPARATOR
|
|
57
|
+
202F ; White_Space # Zs NARROW NO-BREAK SPACE
|
|
58
|
+
205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
|
|
59
|
+
3000 ; White_Space # Zs IDEOGRAPHIC SPACE
|
|
60
|
+
+
|
|
61
|
+
0xfeff // zero width no-break space
|
|
62
|
+
*/
|
|
63
|
+
template<class C>
|
|
64
|
+
bool IsSpace(C c);
|
|
65
|
+
|
|
66
|
+
template<>
|
|
67
|
+
inline bool IsSpace(cybozu::Char c)
|
|
68
|
+
{
|
|
69
|
+
if (c == 0x20 || c == 0x3000) return true;
|
|
70
|
+
if (unsigned(c - 0x09) <= 0x0d - 0x09) return true;
|
|
71
|
+
if (c == 0x85 || c == 0xa0) return true;
|
|
72
|
+
if (c < 0x1680) return false;
|
|
73
|
+
if (c == 0x1680 || c == 0x180e) return true;
|
|
74
|
+
if (unsigned(c - 0x2000) <= 0x200a - 0x2000) return true;
|
|
75
|
+
if (unsigned(c - 0x2028) <= 0x2029 - 0x2028) return true;
|
|
76
|
+
if (c == 0x202f || c == 0x205f || c == 0xfeff) return true;
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
c is space or tab(Don't modify this condition)
|
|
82
|
+
*/
|
|
83
|
+
template<>
|
|
84
|
+
inline bool IsSpace(char c)
|
|
85
|
+
{
|
|
86
|
+
if (c == ' ' || c == '\t') return true;
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
skip space
|
|
92
|
+
@param begin [in] begin of string
|
|
93
|
+
@param end [in] end of string
|
|
94
|
+
@param isSpace [in] check for white-space characters
|
|
95
|
+
*/
|
|
96
|
+
template<typename Iterator>
|
|
97
|
+
inline Iterator SkipSpace(Iterator begin, Iterator end, bool (*isSpace)(typename string_local::CharTag<Iterator>::value_type) = cybozu::IsSpace)
|
|
98
|
+
{
|
|
99
|
+
while (begin < end) {
|
|
100
|
+
if (!isSpace(*begin)) break;
|
|
101
|
+
++begin;
|
|
102
|
+
}
|
|
103
|
+
return begin;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
namespace string_local {
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
get trimed position [begin, end)
|
|
110
|
+
@param begin [in] begin of string
|
|
111
|
+
@param end [inout] end of string
|
|
112
|
+
@param isSpace [in] check for white-space characters
|
|
113
|
+
return new begin position
|
|
114
|
+
*/
|
|
115
|
+
template<typename Iterator>
|
|
116
|
+
inline Iterator GetTrimPosition(Iterator begin, Iterator &end, bool (*isSpace)(typename string_local::CharTag<Iterator>::value_type) = cybozu::IsSpace)
|
|
117
|
+
{
|
|
118
|
+
begin = SkipSpace(begin, end, isSpace);
|
|
119
|
+
while (begin < end) {
|
|
120
|
+
if (!isSpace(end[-1])) break;
|
|
121
|
+
--end;
|
|
122
|
+
}
|
|
123
|
+
return begin;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
template<class StringT1, class StringT2, class Func>
|
|
127
|
+
void ChangeCase(StringT1& out, const StringT2& in, Func f, bool doAppend)
|
|
128
|
+
{
|
|
129
|
+
size_t offset = doAppend ? out.size() : 0;
|
|
130
|
+
out.resize(offset + in.size());
|
|
131
|
+
std::transform(in.begin(), in.end(), out.begin() + offset, f);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
template<class CharT>struct SelectString;
|
|
135
|
+
template<> struct SelectString<char> { typedef std::string string_type; };
|
|
136
|
+
template<> struct SelectString<cybozu::Char> { typedef cybozu::String string_type; };
|
|
137
|
+
|
|
138
|
+
} // string_local
|
|
139
|
+
/**
|
|
140
|
+
trim space
|
|
141
|
+
@param str [inout] string to be trimed
|
|
142
|
+
*/
|
|
143
|
+
template<class StringT>
|
|
144
|
+
inline void Trim(StringT& str, bool (*isSpace)(typename StringT::value_type) = cybozu::IsSpace)
|
|
145
|
+
{
|
|
146
|
+
typedef typename StringT::value_type CharT;
|
|
147
|
+
if (str.empty()) return;
|
|
148
|
+
CharT *begin = &str[0];
|
|
149
|
+
CharT *end = begin + str.size();
|
|
150
|
+
CharT *newBegin = cybozu::string_local::GetTrimPosition(begin, end, isSpace);
|
|
151
|
+
size_t size = end - newBegin;
|
|
152
|
+
if (begin != newBegin) {
|
|
153
|
+
for (size_t i = 0; i < size; i++) {
|
|
154
|
+
*begin++ = *newBegin++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
str.resize(size);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
template<class StringT>
|
|
161
|
+
inline StringT TrimCopy(const StringT& str, bool (*isSpace)(typename StringT::value_type) = cybozu::IsSpace)
|
|
162
|
+
{
|
|
163
|
+
typedef typename StringT::value_type CharT;
|
|
164
|
+
if (str.empty()) return "";
|
|
165
|
+
const CharT *begin = &str[0];
|
|
166
|
+
const CharT *end = begin + str.size();
|
|
167
|
+
const CharT *newBegin = cybozu::string_local::GetTrimPosition(begin, end, isSpace);
|
|
168
|
+
return StringT(newBegin, end);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
template<class StringT1, class StringT2>
|
|
172
|
+
void ToLower(StringT1& out, const StringT2& in, bool doAppend = false)
|
|
173
|
+
{
|
|
174
|
+
string_local::ChangeCase(out, in, cybozu::tolower<typename StringT1::value_type>, doAppend);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
template<class StringT1, class StringT2>
|
|
178
|
+
void ToUpper(StringT1& out, const StringT2& in, bool doAppend = false)
|
|
179
|
+
{
|
|
180
|
+
string_local::ChangeCase(out, in, cybozu::toupper<typename StringT1::value_type>, doAppend);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
template<class StringT>
|
|
184
|
+
void ToLower(StringT& str)
|
|
185
|
+
{
|
|
186
|
+
ToLower(str, str);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
template<class StringT>
|
|
190
|
+
void ToUpper(StringT& str)
|
|
191
|
+
{
|
|
192
|
+
ToUpper(str, str);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
template<class StringT>
|
|
196
|
+
void Strip(StringT& str)
|
|
197
|
+
{
|
|
198
|
+
size_t size = str.size();
|
|
199
|
+
while (size > 0) {
|
|
200
|
+
const typename StringT::value_type c = str[size - 1];
|
|
201
|
+
if (c == '\n' || c == '\r') {
|
|
202
|
+
size--;
|
|
203
|
+
} else {
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
str.resize(size);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
case insensitive compare function
|
|
211
|
+
not depend on locale, not depend on compiler
|
|
212
|
+
*/
|
|
213
|
+
template<class CharT>
|
|
214
|
+
int CaseCompare(const CharT *lhs, size_t lhsSize, const CharT *rhs, size_t rhsSize)
|
|
215
|
+
{
|
|
216
|
+
size_t n = std::min(lhsSize, rhsSize);
|
|
217
|
+
for (size_t i = 0; i < n; i++) {
|
|
218
|
+
CharT cR = cybozu::tolower(lhs[i]);
|
|
219
|
+
CharT cL = cybozu::tolower(rhs[i]);
|
|
220
|
+
if (cR < cL) return -1;
|
|
221
|
+
if (cR > cL) return 1;
|
|
222
|
+
}
|
|
223
|
+
if (lhsSize < rhsSize) return -1;
|
|
224
|
+
if (lhsSize > rhsSize) return 1;
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
template<class CharT1, class CharT2>
|
|
229
|
+
bool CaseEqual(const CharT1 *lhs, size_t lhsSize, const CharT2 *rhs, size_t rhsSize)
|
|
230
|
+
{
|
|
231
|
+
if (lhsSize != rhsSize) return false;
|
|
232
|
+
for (size_t i = 0; i < lhsSize; i++) {
|
|
233
|
+
CharT1 cR = cybozu::tolower(lhs[i]);
|
|
234
|
+
CharT2 cL = cybozu::tolower(rhs[i]);
|
|
235
|
+
if (cR != cL) return false;
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
case insensitive compare lhs with rhs
|
|
242
|
+
@param lhs [in] left side string
|
|
243
|
+
@param rhs [in] right side string
|
|
244
|
+
@retval 1 if lhs > rhs
|
|
245
|
+
@retval 0 if lhs == rhs
|
|
246
|
+
@retval -1 if lhs < rhs
|
|
247
|
+
*/
|
|
248
|
+
template<class StringT>
|
|
249
|
+
int CaseCompare(const StringT& lhs, const StringT& rhs)
|
|
250
|
+
{
|
|
251
|
+
return cybozu::CaseCompare(&lhs[0], lhs.size(), &rhs[0], rhs.size());
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
whether lhs is equal to rhs with case insensitive
|
|
256
|
+
@param lhs [in] left side string
|
|
257
|
+
@param rhs [in] right side string
|
|
258
|
+
*/
|
|
259
|
+
template<class StringT>
|
|
260
|
+
bool CaseEqual(const StringT& lhs, const StringT& rhs)
|
|
261
|
+
{
|
|
262
|
+
return cybozu::CaseEqual(&lhs[0], lhs.size(), &rhs[0], rhs.size());
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
template<class StringT>
|
|
266
|
+
bool CaseEqual(const StringT& lhs, const char *rhs)
|
|
267
|
+
{
|
|
268
|
+
return cybozu::CaseEqual(&lhs[0], lhs.size(), rhs, strlen(rhs));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
find target in [begin, end) with case insensitive
|
|
273
|
+
@param begin [in] begin of string
|
|
274
|
+
@param end [in] end of string
|
|
275
|
+
@param targetBegin [in] begin of *small* target
|
|
276
|
+
@param targetEnd [in] end of *small* target string(if NULL then use null terminate string)
|
|
277
|
+
@retval !0 if found
|
|
278
|
+
@retval 0 if not found
|
|
279
|
+
*/
|
|
280
|
+
template<class CharT>
|
|
281
|
+
const CharT *CaseFind(const CharT *begin, const CharT *end, const char *targetBegin, const char *targetEnd = 0)
|
|
282
|
+
{
|
|
283
|
+
const size_t n = targetEnd ? targetEnd - targetBegin : ::strlen(targetBegin);
|
|
284
|
+
typename string_local::SelectString<CharT>::string_type t(targetBegin, n);
|
|
285
|
+
ToLower(t);
|
|
286
|
+
while (begin + n <= end) {
|
|
287
|
+
bool found = true;
|
|
288
|
+
for (size_t i = 0; i < n; i++) {
|
|
289
|
+
if (cybozu::tolower(begin[i]) != t[i]) {
|
|
290
|
+
found = false;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (found) return begin;
|
|
295
|
+
begin++;
|
|
296
|
+
}
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
template<class CharT>
|
|
301
|
+
size_t CaseFind(const typename string_local::SelectString<CharT>::string_type& str, const char *targetBegin, const char *targetEnd = 0)
|
|
302
|
+
{
|
|
303
|
+
if (!str.empty()) {
|
|
304
|
+
const CharT *p = CaseFind(&str[0], &str[0] + str.size(), targetBegin, targetEnd);
|
|
305
|
+
if (p) {
|
|
306
|
+
return p - &str[0];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return std::string::npos;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
whether lhs is equal to rhs[0..N) with case insensitive
|
|
315
|
+
@param lhs [in] left side string
|
|
316
|
+
@param rhs [in] right side string
|
|
317
|
+
*/
|
|
318
|
+
template<class StringT, size_t N>
|
|
319
|
+
bool CaseEqualStartWith(const StringT& lhs, const char (&rhs)[N])
|
|
320
|
+
{
|
|
321
|
+
if (lhs.size() < N - 1) return false;
|
|
322
|
+
return cybozu::CaseEqual(&lhs[0], N - 1, rhs, N - 1);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
split inStr into out at splitChar
|
|
327
|
+
@param out [out] ouput vector, which must have clear() and push_back()
|
|
328
|
+
@param inStr [in] input string
|
|
329
|
+
@param splitChar [in] char to split
|
|
330
|
+
@param maxNum [in] max split num
|
|
331
|
+
@return split num
|
|
332
|
+
*/
|
|
333
|
+
template<class Out, class StringT>
|
|
334
|
+
size_t Split(Out& out, const StringT& inStr, typename StringT::value_type splitChar = ',', size_t maxNum = 0x7fffffff, bool doClear = true)
|
|
335
|
+
{
|
|
336
|
+
size_t splitNum = 0;
|
|
337
|
+
size_t cur = 0;
|
|
338
|
+
if (doClear) out.clear();
|
|
339
|
+
for (;;) {
|
|
340
|
+
size_t pos = inStr.find_first_of(splitChar, cur);
|
|
341
|
+
if (pos == StringT::npos || splitNum == maxNum - 1) {
|
|
342
|
+
out.push_back(StringT(&inStr[cur], &inStr[0] + inStr.size()));
|
|
343
|
+
splitNum++;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
out.push_back(StringT(&inStr[cur], &inStr[pos]));
|
|
347
|
+
cur = pos + 1;
|
|
348
|
+
splitNum++;
|
|
349
|
+
}
|
|
350
|
+
return splitNum;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
template<class StringT>
|
|
354
|
+
std::vector<StringT> Split(const StringT& inStr, typename StringT::value_type splitChar = ',', size_t maxNum = 0x7fffffff, bool doClear = true)
|
|
355
|
+
{
|
|
356
|
+
std::vector<StringT> out;
|
|
357
|
+
Split(out, inStr, splitChar, maxNum, doClear);
|
|
358
|
+
return out;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
} // cybozu
|
|
362
|
+
|
|
363
|
+
#ifdef _MSC_VER
|
|
364
|
+
#pragma warning(pop)
|
|
365
|
+
#endif
|