Repository navigation
Expand file tree
/
Copy pathutil.cpp
More file actions
executable file
·116 lines (98 loc) · 1.94 KB
/
Copy pathutil.cpp
File metadata and controls
executable file
·116 lines (98 loc) · 1.94 KB
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
#include "stdio.h"
#include "string.h"
#include "iconv.h"
#include "util.h"
char strIDV2Encode[][15] = {
"UTF-8",
"UTF-16",
"UTF-16BE",
"ISO-8859-1",
"ASCII",
"gbk" //my computer is gbk
};
enCodeType GetUnicodeTypeByBeg(char *src, int len)
{
enCodeType uniType = ASCII;
if (null == src)
{
return uniType;
}
if (len <2)
{
return uniType;
}
if (0xFE == src[0])
{
if (0xFF == src[1])
{
return UTF16;
}
else if (0xFF == src[1])
{
return UTF16BE;
}
}
if (len < 3)
{
return uniType;
}
if ((0xEF == src[0]) && (0xBB == src[1]) && (0xBF == src[2]))
{
return UTF8;
}
//others:
//FE FE 00 00 for UTF-32/little endian
//00 00 FE FF for UTF-32/big-endian
return uniType;
}
int switchEncodeToUTF8(char *des, int outlen, char *src, int inlen, char *srcType)
{
iconv_t cd;
char *curdes = des;
char *cursrc = src;
size_t iLen = inlen;
size_t oLen = outlen;
if (null == des || (null == src) || (0 == inlen) || (0==outlen))
{
return -1;
}
if (null == srcType)
{
return -2;
}
cd = iconv_open("UTF-8", srcType);
if (0 == cd )
{
return -3;
}
memset(des, 0, outlen);
if (-1 == iconv(cd, &cursrc, &iLen, &curdes, &oLen))
{
return -4;
}
iconv_close(cd);
return curdes-des;
}
char *getDir(char *pfile)
{
char *strDir = null;
if (null == pfile)
{
return null;
}
int len = strlen(pfile);
char *cur = pfile+len-1;
while ((*cur != '/') && (*cur != '\\') && (len>0))
{
cur--;
len--;
}
if (len>0)
{
int dirLen = cur-pfile+1;
strDir = new char[dirLen+1];
memset(strDir, 0, dirLen+1);
strncpy(strDir, pfile, dirLen);
}
return strDir;
}