mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 05:08:45 +08:00
update
This commit is contained in:
13
cpp2c.cpp
13
cpp2c.cpp
@@ -24,3 +24,16 @@ bool cpp2c::string2char(std::string inp, char*& out) {
|
|||||||
out = temp;
|
out = temp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cpp2c::string2char(std::wstring inp, wchar_t*& out) {
|
||||||
|
size_t le = inp.length();
|
||||||
|
wchar_t* temp = (wchar_t*)malloc((le + 1) * sizeof(wchar_t));
|
||||||
|
if (!temp) {
|
||||||
|
printf("Out of memory.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memcpy(temp, inp.c_str(), le * sizeof(wchar_t));
|
||||||
|
temp[le] = 0;
|
||||||
|
out = temp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
8
cpp2c.h
8
cpp2c.h
@@ -2,6 +2,7 @@
|
|||||||
#define _UTILS_CPP2C_H
|
#define _UTILS_CPP2C_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
namespace cpp2c {
|
namespace cpp2c {
|
||||||
/**
|
/**
|
||||||
@@ -11,6 +12,13 @@ namespace cpp2c {
|
|||||||
* @return true if succeeded.
|
* @return true if succeeded.
|
||||||
*/
|
*/
|
||||||
bool string2char(std::string inp, char*& out);
|
bool string2char(std::string inp, char*& out);
|
||||||
|
/**
|
||||||
|
* @brief Convert wstring to wchar_t*
|
||||||
|
* @param inp Input string
|
||||||
|
* @param out The pointer to output buffer. Need free memory by using free.
|
||||||
|
* @return true if succeeded.
|
||||||
|
*/
|
||||||
|
bool string2char(std::wstring inp, wchar_t*& out);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user