ooxml_crypt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,340 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <vector>
|
3
|
+
#include <sstream>
|
4
|
+
#include <cybozu/test.hpp>
|
5
|
+
#include <cybozu/string.hpp>
|
6
|
+
#include <cybozu/string_operation.hpp>
|
7
|
+
|
8
|
+
#ifdef _MSC_VER
|
9
|
+
#pragma warning(disable : 4309)
|
10
|
+
#endif
|
11
|
+
|
12
|
+
CYBOZU_TEST_AUTO(ascii_space)
|
13
|
+
{
|
14
|
+
for (int i = 0; i < 256; i++) {
|
15
|
+
if (i == ' ' || i == '\t') {
|
16
|
+
CYBOZU_TEST_ASSERT(cybozu::IsSpace((char)i));
|
17
|
+
} else {
|
18
|
+
CYBOZU_TEST_ASSERT(!cybozu::IsSpace((char)i));
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
CYBOZU_TEST_AUTO(skipSpace)
|
24
|
+
{
|
25
|
+
const struct {
|
26
|
+
const char *in;
|
27
|
+
const char *out;
|
28
|
+
} tbl[] = {
|
29
|
+
{ "abc", "abc" },
|
30
|
+
{ " abc", "abc" },
|
31
|
+
{ " ", "" },
|
32
|
+
};
|
33
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
34
|
+
const char *begin = tbl[i].in;
|
35
|
+
const char *end = begin + strlen(begin);
|
36
|
+
const char *p = cybozu::SkipSpace(begin, end);
|
37
|
+
CYBOZU_TEST_EQUAL(p, tbl[i].out);
|
38
|
+
std::string str(begin, end);
|
39
|
+
CYBOZU_TEST_EQUAL(cybozu::SkipSpace(str.begin(), str.end()) - str.begin(), p - begin);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
bool is_space_normal(cybozu::Char c)
|
44
|
+
{
|
45
|
+
static const cybozu::Char spaceTbl[] = {
|
46
|
+
0x09, 0x0a, 0x0b, 0x0c, 0x0d,
|
47
|
+
0x20,
|
48
|
+
0x85,
|
49
|
+
0xa0,
|
50
|
+
0x1680,
|
51
|
+
0x180e,
|
52
|
+
0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a,
|
53
|
+
0x2028,
|
54
|
+
0x2029,
|
55
|
+
0x202f,
|
56
|
+
0x205f,
|
57
|
+
0x3000,
|
58
|
+
0xfeff, // zero width no-break space
|
59
|
+
};
|
60
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(spaceTbl); i++) {
|
61
|
+
if (c == spaceTbl[i]) return true;
|
62
|
+
}
|
63
|
+
return false;
|
64
|
+
}
|
65
|
+
|
66
|
+
CYBOZU_TEST_AUTO(unicode_space)
|
67
|
+
{
|
68
|
+
for (cybozu::Char c = 0; c <= 0x10ffff; c++) {
|
69
|
+
if (cybozu::IsSpace(c) != is_space_normal(c)) {
|
70
|
+
printf("c=%x\n", c);
|
71
|
+
CYBOZU_TEST_FAIL("bad space");
|
72
|
+
}
|
73
|
+
}
|
74
|
+
CYBOZU_TEST_ASSERT(1);
|
75
|
+
}
|
76
|
+
|
77
|
+
CYBOZU_TEST_AUTO(trim)
|
78
|
+
{
|
79
|
+
const struct {
|
80
|
+
const char *in;
|
81
|
+
const char *out;
|
82
|
+
} tbl[] = {
|
83
|
+
{ "", "" },
|
84
|
+
{ " \t", "" },
|
85
|
+
{ " abc xyz\t\t\t", "abc xyz" },
|
86
|
+
{ "abc ddd ", "abc ddd" },
|
87
|
+
{ "\t\t\txxx", "xxx" },
|
88
|
+
};
|
89
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
90
|
+
{
|
91
|
+
std::string in(tbl[i].in);
|
92
|
+
std::string out = cybozu::TrimCopy(in);
|
93
|
+
CYBOZU_TEST_EQUAL(out, tbl[i].out);
|
94
|
+
}
|
95
|
+
{
|
96
|
+
cybozu::String in(tbl[i].in);
|
97
|
+
cybozu::String out = cybozu::TrimCopy(in);
|
98
|
+
CYBOZU_TEST_EQUAL(out, tbl[i].out);
|
99
|
+
}
|
100
|
+
{
|
101
|
+
std::string in(tbl[i].in);
|
102
|
+
cybozu::Trim(in);
|
103
|
+
CYBOZU_TEST_EQUAL(in, tbl[i].out);
|
104
|
+
}
|
105
|
+
{
|
106
|
+
cybozu::String in(tbl[i].in);
|
107
|
+
cybozu::Trim(in);
|
108
|
+
CYBOZU_TEST_EQUAL(in, tbl[i].out);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
cybozu::String str("\x20\x20""doremi\x20\xe3\x80\x80\x20\xe3\x80\x80");
|
112
|
+
cybozu::Trim(str);
|
113
|
+
CYBOZU_TEST_EQUAL(str, "doremi");
|
114
|
+
}
|
115
|
+
|
116
|
+
CYBOZU_TEST_AUTO(casecmp)
|
117
|
+
{
|
118
|
+
const struct {
|
119
|
+
const char *lhs;
|
120
|
+
size_t lhsSize;
|
121
|
+
const char *rhs;
|
122
|
+
size_t rhsSize;
|
123
|
+
int ret;
|
124
|
+
} tbl[] = {
|
125
|
+
{ "", 0, "", 0, 0 },
|
126
|
+
{ "abc", 3, "abc", 3, 0 },
|
127
|
+
{ "abcd", 4, "abc", 3, 1 },
|
128
|
+
{ "abc", 3, "abcd", 4, -1 },
|
129
|
+
{ "abc\0xyz", 7, "abc", 3, 1 },
|
130
|
+
{ "abc\0xyz", 3, "abcd", 4, -1 },
|
131
|
+
{ "AAA", 3, "aaa", 3, 0 },
|
132
|
+
{ "012345678ABCDEFGHIJKLMNOPQRSTUVWXYZaVN#)(WV#N(WRUW#VRW", 55
|
133
|
+
,"012345678abcdefghijklmnopqrstuvwxyzaVN#)(WV#N(WRUW#VRW", 55, 0 },
|
134
|
+
{ "AAAbbB", 3, "aaabbb", 3, 0 },
|
135
|
+
};
|
136
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
137
|
+
{
|
138
|
+
std::string lhs(tbl[i].lhs, tbl[i].lhs + tbl[i].lhsSize);
|
139
|
+
std::string rhs(tbl[i].rhs, tbl[i].rhs + tbl[i].rhsSize);
|
140
|
+
int ret = cybozu::CaseCompare(lhs, rhs);
|
141
|
+
ret = (ret > 0) ? 1 : (ret < 0) ? -1 : 0;
|
142
|
+
CYBOZU_TEST_EQUAL(ret, tbl[i].ret);
|
143
|
+
}
|
144
|
+
{
|
145
|
+
cybozu::String lhs(tbl[i].lhs, tbl[i].lhs + tbl[i].lhsSize);
|
146
|
+
cybozu::String rhs(tbl[i].rhs, tbl[i].rhs + tbl[i].rhsSize);
|
147
|
+
int ret = cybozu::CaseCompare(lhs, rhs);
|
148
|
+
ret = (ret > 0) ? 1 : (ret < 0) ? -1 : 0;
|
149
|
+
CYBOZU_TEST_EQUAL(ret, tbl[i].ret);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
CYBOZU_TEST_AUTO(caseEqualStart)
|
155
|
+
{
|
156
|
+
CYBOZU_TEST_ASSERT(cybozu::CaseEqualStartWith(std::string("abcdef"), "abC"));
|
157
|
+
CYBOZU_TEST_ASSERT(cybozu::CaseEqualStartWith(std::string("ABC"), "aBc"));
|
158
|
+
CYBOZU_TEST_ASSERT(!cybozu::CaseEqualStartWith(std::string("AB"), "abc"));
|
159
|
+
|
160
|
+
CYBOZU_TEST_ASSERT(cybozu::CaseEqualStartWith(cybozu::String("abcdef"), "abC"));
|
161
|
+
CYBOZU_TEST_ASSERT(cybozu::CaseEqualStartWith(cybozu::String("ABC"), "aBc"));
|
162
|
+
CYBOZU_TEST_ASSERT(!cybozu::CaseEqualStartWith(cybozu::String("AB"), "abc"));
|
163
|
+
}
|
164
|
+
|
165
|
+
CYBOZU_TEST_AUTO(caseEqaul)
|
166
|
+
{
|
167
|
+
const struct {
|
168
|
+
const char *lhs;
|
169
|
+
const char *rhs;
|
170
|
+
bool ret;
|
171
|
+
} tbl[] = {
|
172
|
+
{ "abcdef", "abC", false },
|
173
|
+
{ "ABC", "aBc", true },
|
174
|
+
{ "AB", "abc", false },
|
175
|
+
};
|
176
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
177
|
+
{
|
178
|
+
std::string lhs(tbl[i].lhs);
|
179
|
+
std::string rhs(tbl[i].rhs);
|
180
|
+
CYBOZU_TEST_EQUAL(cybozu::CaseEqual(lhs, rhs), tbl[i].ret);
|
181
|
+
}
|
182
|
+
{
|
183
|
+
cybozu::String lhs(tbl[i].lhs);
|
184
|
+
cybozu::String rhs(tbl[i].rhs);
|
185
|
+
CYBOZU_TEST_EQUAL(cybozu::CaseEqual(lhs, rhs), tbl[i].ret);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
CYBOZU_TEST_AUTO(tolower)
|
191
|
+
{
|
192
|
+
const struct {
|
193
|
+
const char *str;
|
194
|
+
const char *up;
|
195
|
+
const char *low;
|
196
|
+
} tbl[] = {
|
197
|
+
{ "", "", "" },
|
198
|
+
{ "ab23dc5\0def", "AB23DC5\0DEF", "ab23dc5\0def" },
|
199
|
+
{ "#$%%#$(%')#($&", "#$%%#$(%')#($&", "#$%%#$(%')#($&" },
|
200
|
+
{ "AbCdEfGHijklmnOPQRSTUvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz" },
|
201
|
+
};
|
202
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
203
|
+
{
|
204
|
+
std::string str(tbl[i].str);
|
205
|
+
cybozu::ToUpper(str);
|
206
|
+
CYBOZU_TEST_EQUAL(str, tbl[i].up);
|
207
|
+
str = tbl[i].str;
|
208
|
+
cybozu::ToLower(str);
|
209
|
+
CYBOZU_TEST_EQUAL(str, tbl[i].low);
|
210
|
+
}
|
211
|
+
{
|
212
|
+
cybozu::String str(tbl[i].str);
|
213
|
+
cybozu::ToUpper(str);
|
214
|
+
CYBOZU_TEST_EQUAL(str, tbl[i].up);
|
215
|
+
str = tbl[i].str;
|
216
|
+
cybozu::ToLower(str);
|
217
|
+
CYBOZU_TEST_EQUAL(str, tbl[i].low);
|
218
|
+
}
|
219
|
+
{
|
220
|
+
std::string up;
|
221
|
+
cybozu::ToUpper(up, std::string(tbl[i].str));
|
222
|
+
CYBOZU_TEST_EQUAL(up, tbl[i].up);
|
223
|
+
std::string low;
|
224
|
+
cybozu::ToLower(low, std::string(tbl[i].str));
|
225
|
+
CYBOZU_TEST_EQUAL(low, tbl[i].low);
|
226
|
+
}
|
227
|
+
{
|
228
|
+
cybozu::String up;
|
229
|
+
cybozu::ToUpper(up, std::string(tbl[i].str));
|
230
|
+
CYBOZU_TEST_EQUAL(up, tbl[i].up);
|
231
|
+
cybozu::String low;
|
232
|
+
cybozu::ToLower(low, std::string(tbl[i].str));
|
233
|
+
CYBOZU_TEST_EQUAL(low, tbl[i].low);
|
234
|
+
}
|
235
|
+
const std::string pre = "aBc";
|
236
|
+
{
|
237
|
+
std::string up = pre;
|
238
|
+
cybozu::ToUpper(up, std::string(tbl[i].str), cybozu::string::DoAppend);
|
239
|
+
CYBOZU_TEST_EQUAL(up, pre + tbl[i].up);
|
240
|
+
std::string low = pre;
|
241
|
+
cybozu::ToLower(low, std::string(tbl[i].str), cybozu::string::DoAppend);
|
242
|
+
CYBOZU_TEST_EQUAL(low, pre + tbl[i].low);
|
243
|
+
}
|
244
|
+
{
|
245
|
+
cybozu::String up = pre;
|
246
|
+
cybozu::ToUpper(up, std::string(tbl[i].str), cybozu::string::DoAppend);
|
247
|
+
CYBOZU_TEST_EQUAL(up, pre + tbl[i].up);
|
248
|
+
cybozu::String low = pre;
|
249
|
+
cybozu::ToLower(low, std::string(tbl[i].str), cybozu::string::DoAppend);
|
250
|
+
CYBOZU_TEST_EQUAL(low, pre + tbl[i].low);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
CYBOZU_TEST_AUTO(CaseFind)
|
256
|
+
{
|
257
|
+
const struct {
|
258
|
+
const char *in;
|
259
|
+
const char *target;
|
260
|
+
int pos;
|
261
|
+
} tbl [] = {
|
262
|
+
{ "", "", 0 },
|
263
|
+
{ "abc", "", 0 },
|
264
|
+
{ "", "a", -1 },
|
265
|
+
{ "", "abc", -1 },
|
266
|
+
{ "abc", "abcd", -1 },
|
267
|
+
{ "abcdef", "def", 3 },
|
268
|
+
{ "abcDEF", "def", 3 },
|
269
|
+
{ "abcDef", "dEF", 3 },
|
270
|
+
{ "abcDef", "dEFg", -1 },
|
271
|
+
{ "abcDef", "dEFg", -1 },
|
272
|
+
{ "abcAB%%cde$$%sdf", "ab%%CDE$$%S", 3 },
|
273
|
+
};
|
274
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
275
|
+
std::string in(tbl[i].in);
|
276
|
+
const char *p = cybozu::CaseFind(in.c_str(), in.c_str() + in.size(), tbl[i].target);
|
277
|
+
int pos = tbl[i].pos;
|
278
|
+
if (pos == -1) {
|
279
|
+
CYBOZU_TEST_EQUAL_POINTER(p, 0);
|
280
|
+
} else {
|
281
|
+
CYBOZU_TEST_EQUAL_POINTER(p, in.c_str() + pos);
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
CYBOZU_TEST_AUTO(split)
|
287
|
+
{
|
288
|
+
typedef std::vector<std::string> StrVec;
|
289
|
+
const struct {
|
290
|
+
const char *in;
|
291
|
+
char splitChar;
|
292
|
+
size_t maxNum;
|
293
|
+
const char *out[5];
|
294
|
+
size_t splitNum;
|
295
|
+
} tbl [] = {
|
296
|
+
{ "abc,def", ',', 3, { "abc", "def" }, 2 },
|
297
|
+
{ "abc,def,ghi,jkl", ',', 3, { "abc", "def", "ghi,jkl" }, 3 },
|
298
|
+
{ "abc,def,ghi,jkl", ',', 5, { "abc", "def", "ghi", "jkl" }, 4},
|
299
|
+
{ "abc,def,ghi,jkl", ',', 2, { "abc", "def,ghi,jkl" }, 2},
|
300
|
+
{ "abc,def,ghi,jkl", ',', 1, { "abc,def,ghi,jkl" }, 1},
|
301
|
+
|
302
|
+
{ "abc=def", '=', 2, { "abc", "def" }, 2 },
|
303
|
+
{ ",", ',', 5, { "", "" }, 2 },
|
304
|
+
{ "xyz", ',', 5, { "xyz" }, 1 },
|
305
|
+
};
|
306
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
307
|
+
StrVec out;
|
308
|
+
size_t splitNum = cybozu::Split(out, std::string(tbl[i].in), tbl[i].splitChar, tbl[i].maxNum);
|
309
|
+
std::vector<std::string> r = cybozu::Split(std::string(tbl[i].in), tbl[i].splitChar, tbl[i].maxNum);
|
310
|
+
CYBOZU_TEST_ASSERT(r == out);
|
311
|
+
CYBOZU_TEST_EQUAL(splitNum, tbl[i].splitNum);
|
312
|
+
if (splitNum == tbl[i].splitNum) {
|
313
|
+
for (size_t j = 0; j < splitNum; j++) {
|
314
|
+
CYBOZU_TEST_EQUAL(out[j], tbl[i].out[j]);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
CYBOZU_TEST_AUTO(Strip)
|
321
|
+
{
|
322
|
+
const struct {
|
323
|
+
const char *in;
|
324
|
+
const char *out;
|
325
|
+
} tbl[] = {
|
326
|
+
{ "", "" },
|
327
|
+
{ "abc", "abc" },
|
328
|
+
{ "abc\n", "abc" },
|
329
|
+
{ "abc\ndef\n\r\n\r", "abc\ndef" },
|
330
|
+
{ "\r\n\r\n", "" },
|
331
|
+
};
|
332
|
+
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
|
333
|
+
std::string s1(tbl[i].in);
|
334
|
+
cybozu::Strip(s1);
|
335
|
+
CYBOZU_TEST_EQUAL(s1, tbl[i].out);
|
336
|
+
cybozu::String s2(tbl[i].in);
|
337
|
+
cybozu::Strip(s2);
|
338
|
+
CYBOZU_TEST_EQUAL(s2, tbl[i].out);
|
339
|
+
}
|
340
|
+
}
|