forked from ennorehling/csmapfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fxhelper.cpp
133 lines (109 loc) · 2.63 KB
/
fxhelper.cpp
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
#include <iostream>
#include <string>
#include <cctype>
#include <fx.h>
#include <FX88591Codec.h>
#ifdef WIN32
#include "shlobj.h" // SHGetSpecialFolderPath
#endif
#include "version.h"
#include "fxhelper.h"
FX::FXString utf2iso(const FX::FXString& s)
{
static FX::FX88591Codec codec;
return codec.utf2mb(s);
}
FX::FXString iso2utf(const FX::FXString& s)
{
static FX::FX88591Codec codec;
return codec.mb2utf(s);
}
// flatten strings: Removed spaces,
// german umlauts to ae,oe,ue,ss and
// all letters to lower case.
// ---------------------------------
std::string flatten(const std::string& str)
{
std::string out;
for (std::string::size_type i = 0; i < str.size(); i++)
{
unsigned char c = str[i];
if (c == 0xdf)
out += "ss";
else if (c == 0xef || c == 0xc4)
out += "ae";
else if (c == 0xd6 || c == 0xf6)
out += "oe";
else if (c == 0xdc || c == 0xfc)
out += "ue";
else if (isalnum(c))
out += (char)std::tolower(c);
}
return out;
}
FXString flatten(const FXString& str)
{
FXString out;
for (int i = 0; i < str.length(); i = str.inc(i))
{
FXwchar wc = str.wc(i);
if (wc == L"\u00df"[0])
out += "ss";
else if (wc == L"\u00c4"[0] || wc == L"\u00e4"[0])
out += "ae";
else if (wc == L"\u00d6"[0] || wc == L"\u00f6"[0])
out += "oe";
else if (wc == L"\u00dc"[0] || wc == L"\u00fc"[0])
out += "ue";
else
out += (char)std::tolower(wc);
}
return out;
}
// Small error function
// --------------------
void showError(const FXString& str)
{
#ifdef WIN32
FXMessageBox::information(FXApp::instance(), MBOX_OK, CSMAP_APP_TITLE, str.text());
#else
showError((std::string)utf2iso(str).text()); // caution: cross forwarding!
#endif
}
void showError(const std::string& str)
{
#ifdef WIN32
showError((FXString)FXString(str.c_str())); // caution: cross forwarding!
#else
std::cerr << str << std::endl;
#endif
}
// get search path for app config data
// -----------------------------------
std::vector<FXString> getSearchPath()
{
std::vector<FXString> searchPath;
// add path to .exe file
#ifdef WIN32
char pathName[MAX_PATH];
DWORD length = ::GetModuleFileName(NULL, pathName, MAX_PATH);
FXString exePath = FXString(pathName, length).rbefore('\\');
if (!exePath.empty())
searchPath.push_back(exePath + "\\");
#endif
// add app path / home directory
#ifdef WIN32
BOOL res = SHGetSpecialFolderPath(NULL, pathName, CSIDL_LOCAL_APPDATA, false);
if (res)
{
// Z.B. "C:\Users\Phygon\AppData\Local\CSMap\"
FXString appPath(pathName);
searchPath.push_back(appPath + "\\CSMap\\");
}
#else
searchPath.push_back("~/.");
#endif
// add current directory
searchPath.push_back(".\\");
return searchPath;
}