FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leanify/utils.cpp at master · JayXon/Leanify · GitHub
JayXon
/
Leanify
Public
Notifications
You must be signed in to change notification settings
Fork
80
Star
851
Code
Issues
20
Pull requests
0
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Leanify
/
utils.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (45 loc) · 1.24 KB
Breadcrumbs
Leanify
/
utils.cpp
Copy path
File metadata and controls
51 lines (45 loc) · 1.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
utils.h
"
#
ifdef
_WIN32
#
include
<
Windows.h
>
//
WideCharToMultiByte
#
else
#
include
<
iconv.h
>
//
convert UTF16 to UTF8 on non Windows
#
include
<
cstdio
>
#
endif
using
std::cout;
using
std::endl;
using
std::string;
//
convert UNICODE string aka UTF16 string
//
to multi byte string aka UTF8 string
void
UTF16toMBS
(
const
wchar_t
* u,
size_t
srclen,
char
* mbs,
size_t
dstlen) {
#
ifdef
_WIN32
WideCharToMultiByte
(
CP_ACP
,
0
, u, srclen /
2
, mbs, dstlen,
nullptr
,
nullptr
);
#
else
iconv_t
conv =
iconv_open
(
"
UTF-8
"
,
"
UTF-16
"
);
if
(
iconv
(conv, (
char
**)&u, &srclen, &mbs, &dstlen) == (
size_t
)-
1
)
perror
(
"
iconv
"
);
iconv_close
(conv);
#
endif
//
_WIN32
}
void
PrintFileName
(
const
string& name) {
for
(
int
i =
1
; i < depth; i++)
cout <<
"
->
"
;
cout << name << endl;
}
//
Shrink consecutive space, newline and tab in the given string to one space
//
also removes preceding and trailing spaces
string
ShrinkSpace
(
const
char
* str) {
string out_str;
while
(*str) {
if
(*str ==
'
'
|| *str ==
'
\n
'
|| *str ==
'
\t
'
) {
do
{
str++;
}
while
(*str ==
'
'
|| *str ==
'
\n
'
|| *str ==
'
\t
'
);
if
(*str ==
0
)
break
;
if
(!out_str.
empty
())
out_str +=
'
'
;
}
out_str += *str++;
}
return
out_str;
}
Back
|
FazBrowse Home
|
New Git URL