Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
3380dbb4
Commit
3380dbb4
authored
Sep 27, 2017
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
3751fb7a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
20 deletions
+106
-20
.gitignore
.gitignore
+3
-0
mem_tool.h
mem_tool.h
+33
-0
string_tool.h
string_tool.h
+26
-0
clipboard.h
win32/clipboard.h
+44
-20
No files found.
.gitignore
View file @
3380dbb4
.vscode/
# Compiled Object files
*.slo
*.lo
...
...
mem_tool.h
0 → 100644
View file @
3380dbb4
#pragma once
#include <memory>
#include <functional>
namespace
jlib
{
//template <typename T>
//struct deleter : public std::default_delete<T>
//{};
template
<
typename
T
>
class
auto_free
{
public
:
typedef
std
::
function
<
void
(
T
*
)
>
deleter
;
explicit
auto_free
(
T
*
data
,
deleter
dter
=
{})
:
data_
(
data
),
deleter_
(
dter
)
{}
~
auto_free
()
{
if
(
data_
&&
deleter_
)
{
deleter_
(
data_
);
}
}
protected
:
T
*
data_
=
nullptr
;
deleter
deleter_
=
nullptr
;
};
}
string_tool.h
0 → 100644
View file @
3380dbb4
#pragma once
#include <vector>
#include <string>
namespace
jlib
{
template
<
class
V
,
class
T
>
bool
is_contain
(
const
V
&
v
,
const
T
&
t
)
{
for
(
auto
i
:
v
)
{
if
(
i
==
t
)
{
return
true
;
}
}
return
false
;
}
template
<
class
V
>
std
::
vector
<
std
::
wstring
>
get_other
(
const
V
&
v
,
const
std
::
wstring
&
t
)
{
std
::
vector
<
std
::
wstring
>
ret
=
{};
for
(
auto
i
:
v
)
{
if
(
i
!=
t
)
{
ret
.
push_back
(
t
);
}
}
return
ret
;
}
template
<
class
V
>
std
::
vector
<
std
::
string
>
get_other
(
const
V
&
v
,
const
std
::
string
&
t
)
{
std
::
vector
<
std
::
string
>
ret
=
{};
for
(
auto
i
:
v
)
{
if
(
i
!=
t
)
{
ret
.
push_back
(
t
);
}
}
return
ret
;
}
}
win32/clipboard.h
View file @
3380dbb4
...
...
@@ -4,11 +4,12 @@
namespace
jlib
{
inline
bool
to
Clipboard
(
HWND
hwnd
,
const
std
::
string
&
s
)
inline
bool
to
_clipboard
(
const
std
::
wstring
&
s
)
{
if
(
!
OpenClipboard
(
hwnd
))
return
false
;
if
(
!
OpenClipboard
(
nullptr
))
return
false
;
if
(
!
EmptyClipboard
())
return
false
;
HGLOBAL
hg
=
GlobalAlloc
(
GMEM_DDESHARE
,
s
.
size
()
+
1
);
size_t
sz
=
(
s
.
length
()
+
1
)
*
2
;
HGLOBAL
hg
=
GlobalAlloc
(
GMEM_MOVEABLE
,
sz
);
if
(
!
hg
)
{
CloseClipboard
();
return
false
;
...
...
@@ -18,13 +19,36 @@ inline bool toClipboard(HWND hwnd, const std::string &s)
CloseClipboard
();
return
false
;
}
memcpy
(
hMem
,
s
.
c_str
(),
s
.
size
()
+
1
);
memset
(
hMem
,
0
,
sz
);
memcpy
(
hMem
,
s
.
data
(),
s
.
size
()
*
2
);
GlobalUnlock
(
hg
);
SetClipboardData
(
CF_
TEXT
,
hg
);
SetClipboardData
(
CF_UNICODE
TEXT
,
hg
);
CloseClipboard
();
GlobalFree
(
hg
);
return
true
;
}
inline
std
::
wstring
from_clipboard
()
{
std
::
wstring
text
;
do
{
if
(
!
OpenClipboard
(
nullptr
))
break
;
HANDLE
hData
=
GetClipboardData
(
CF_UNICODETEXT
);
if
(
hData
==
nullptr
)
break
;
auto
pszText
=
static_cast
<
const
wchar_t
*>
(
GlobalLock
(
hData
));
if
(
pszText
==
nullptr
)
break
;
text
=
pszText
;
GlobalUnlock
(
hData
);
CloseClipboard
();
}
while
(
false
);
return
text
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment