comparison horori/searcher/src/utils.cpp @ 0:aaaa401818a1 draft

first commit.
author pyon <pyon@macmini>
date Mon, 24 May 2021 21:32:58 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:aaaa401818a1
1 // Filename : utils.cpp
2 // Last Change: 2020-06-26 金 09:16:48.
3 //
4 #include <wx/wx.h>
5 #include <wx/dir.h>
6 #include <wx/wfstream.h>
7 #include <wx/zstream.h>
8 #include <wx/tarstrm.h>
9 #include <wx/regex.h>
10 #include "utils.h"
11
12 wxRect Geo2Rect(wxString geo)
13 {
14 long w, h, x, y;
15 wxString sw = geo.BeforeFirst('x');
16 wxString sh = geo.AfterFirst('x').BeforeFirst('+');
17 wxString sx = geo.AfterFirst('+').BeforeFirst('+');
18 wxString sy = geo.AfterLast('+');
19
20 sw.ToLong(&w, 10);
21 sh.ToLong(&h, 10);
22 sx.ToLong(&x, 10);
23 sy.ToLong(&y, 10);
24
25 return wxRect((int)x, (int)y, (int)w, (int)h);
26 }
27
28 wxRect ZeroRect()
29 {
30 wxRect rect(wxPoint(0, 0), wxPoint(0, 0));
31 return rect;
32 }
33
34 bool TarDir(wxString dir, wxString tarfile)
35 {
36 if (!wxDirExists(dir)) {
37 wxMessageBox(wxT("bad directoy"));
38 return false;
39 }
40
41 wxDir d(dir);
42 if (!d.IsOpened()) return false;
43
44 wxFFileOutputStream out(tarfile);
45 wxTarOutputStream tar(out);
46
47 wxString filename;
48 bool cont = d.GetFirst(&filename, wxEmptyString, wxDIR_FILES);
49 while (cont) {
50 wxFFileInputStream in(dir + wxFILE_SEP_PATH + filename);
51 tar.PutNextEntry(filename);
52 tar.Write(in);
53 cont = d.GetNext(&filename);
54 }
55 tar.Close();
56 return true;
57 }
58
59 bool Gzip(wxString infile, wxString gzfile)
60 {
61 wxFileInputStream istream(infile);
62 wxFileOutputStream ostream(gzfile);
63 wxZlibOutputStream zstream(ostream, -1, wxZLIB_GZIP);
64
65 zstream.Write(istream);
66 zstream.Close();
67 return true;
68 }
69
70 wxString XoR(wxString s, int x)
71 {
72 wxString t;
73 for (int i = 0; i < s.Len(); i++) {
74 t += wxString::Format(wxT("%c"), s[i].GetValue() ^ x);
75 }
76 return t;
77 }
78
79 bool IsHiragana(wxString s)
80 {
81 wxString hiragana = wxT("あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉゃゅょっ ");
82 wxRegEx reHiragana(wxT("^[") + hiragana + wxT("]+$"));
83
84 if (reHiragana.Matches(s)) return true;
85 return false;
86 }
87
88 bool IsKatakana(wxString s)
89 {
90 wxString katakana = wxT("アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンガギグゲコザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッ ");
91 wxRegEx reKatakana(wxT("^[") + katakana + wxT("]+$"));
92
93 if (reKatakana.Matches(s)) return true;
94 return false;
95 }
96
97 wxString Hiragara2Katakana(wxString s)
98 {
99 wxString hiragana = wxT("あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをんがぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽぁぃぅぇぉゃゅょっ ");
100 wxString katakana = wxT("アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンガギグゲコザジズゼゾダヂヅデドバビブベボパピプペポァィゥェォャュョッ ");
101 for (int i = 0; i < hiragana.Len(); i++)
102 s.Replace(hiragana[i], katakana[i], true);
103 return s;
104 }
105