|
19 | 19 | #define TSTRING_PADDING 0 |
20 | 20 | #endif |
21 | 21 |
|
| 22 | +#include "ntcvt/ntcvt.hpp" |
| 23 | + |
22 | 24 | namespace DM |
23 | 25 | { |
24 | 26 | __pragma(warning(push)) |
@@ -1676,74 +1678,6 @@ namespace DM |
1676 | 1678 | typedef CStringA CStringT; |
1677 | 1679 | #endif |
1678 | 1680 |
|
1679 | | - static CStringW DMA2W(const CStringA &str, UINT CodePage=CP_ACP) |
1680 | | - { |
1681 | | - int nSize = ::MultiByteToWideChar(CodePage, 0, str, str.GetLength(), NULL, 0); |
1682 | | - if (nSize>0) |
1683 | | - { |
1684 | | - wchar_t *pBuf=new wchar_t[nSize]; |
1685 | | - ::MultiByteToWideChar(CodePage, 0, str, str.GetLength(), pBuf, nSize); |
1686 | | - CStringW strw(pBuf, nSize); |
1687 | | - delete []pBuf; |
1688 | | - pBuf = NULL; |
1689 | | - return strw; |
1690 | | - } |
1691 | | - return L""; |
1692 | | - } |
1693 | | - |
1694 | | - /// <summary> |
1695 | | - /// 用于脚本中char*直接转CStringW |
1696 | | - /// </summary> |
1697 | | - static CStringW DMCA2W(LPCSTR lpsz, UINT CodePage=CP_ACP) |
1698 | | - { |
1699 | | - CStringA str = lpsz; |
1700 | | - CStringW strw = DMA2W(str, CodePage); |
1701 | | - return strw; |
1702 | | - } |
1703 | | - |
1704 | | - static CStringA DMW2A(const CStringW &str, UINT CodePage=CP_ACP) |
1705 | | - { |
1706 | | - int nSize = ::WideCharToMultiByte(CodePage,0,str, str.GetLength(), NULL, 0, NULL, NULL); |
1707 | | - if (nSize>0) |
1708 | | - { |
1709 | | - char *pBuf = new char[nSize]; |
1710 | | - ::WideCharToMultiByte(CodePage,0,str, str.GetLength(), pBuf, nSize, NULL, NULL); |
1711 | | - CStringA stra(pBuf,nSize); |
1712 | | - delete []pBuf; |
1713 | | - pBuf = NULL; |
1714 | | - return stra; |
1715 | | - } |
1716 | | - return ""; |
1717 | | - } |
1718 | | - |
1719 | | - static CStringW DMW2W(const CStringW &str) |
1720 | | - { |
1721 | | - return str; |
1722 | | - } |
1723 | | - |
1724 | | - static CStringA DMA2A(const CStringA &str, UINT CodePageFrom=CP_UTF8, UINT CodePageTo=CP_ACP) |
1725 | | - { |
1726 | | - if (CodePageFrom == CodePageTo) |
1727 | | - { |
1728 | | - return str; |
1729 | | - } |
1730 | | - CStringW strw = DMA2W(str,CodePageFrom); |
1731 | | - return DMW2A(strw, CodePageTo); |
1732 | | - } |
1733 | | - |
1734 | | - |
1735 | | -#ifdef UNICODE |
1736 | | -#define DMA2T DMA2W |
1737 | | -#define DMW2T DMW2W |
1738 | | -#define DMT2A DMW2A |
1739 | | -#define DMT2W DMW2W |
1740 | | -#else |
1741 | | -#define DMA2T DMA2A |
1742 | | -#define DMW2T DMW2A |
1743 | | -#define DMT2A DMA2A |
1744 | | -#define DMT2W DMA2W |
1745 | | -#endif |
1746 | | - |
1747 | 1681 | template< typename T > |
1748 | 1682 | class SStringElementTraits |
1749 | 1683 | { |
@@ -1807,3 +1741,68 @@ namespace DM |
1807 | 1741 |
|
1808 | 1742 | }//end of namespace |
1809 | 1743 |
|
| 1744 | +namespace ntcvt { |
| 1745 | + namespace buffer_traits { |
| 1746 | + inline char* inplaced(DM::CStringA& str, int size) { |
| 1747 | + return str.GetBufferSetLength(size); |
| 1748 | + } |
| 1749 | + inline wchar_t* inplaced(DM::CStringW& str, int size) { |
| 1750 | + return str.GetBufferSetLength(size); |
| 1751 | + } |
| 1752 | + } |
| 1753 | + inline std::string from_chars(const DM::CStringW& wcb, UINT cp = CP_ACP) |
| 1754 | + { |
| 1755 | + return wcbs2a<std::string>((LPCWSTR)wcb, wcb.GetLength(), cp); |
| 1756 | + } |
| 1757 | +} |
| 1758 | + |
| 1759 | +namespace DM { |
| 1760 | + /// <summary> |
| 1761 | + /// 用于脚本中char*直接转CStringW |
| 1762 | + /// </summary> |
| 1763 | + static CStringW DMCA2W(LPCSTR lpsz, int len /*=-1*/, UINT CodePage/* = CP_ACP*/) |
| 1764 | + { |
| 1765 | + return ntcvt::mcbs2w<CStringW>(lpsz, len, CodePage); |
| 1766 | + } |
| 1767 | + |
| 1768 | + static CStringW DMA2W(const CStringA& str, UINT CodePage = CP_ACP) |
| 1769 | + { |
| 1770 | + return DMCA2W((LPCSTR)str, str.GetLength(), CodePage); |
| 1771 | + } |
| 1772 | + |
| 1773 | + static CStringA DMWC2A(LPCWSTR lpsz, int len /*=-1*/, UINT CodePage /*=CP_ACP*/) |
| 1774 | + { |
| 1775 | + return ntcvt::wcbs2a<CStringA>(lpsz, len, CodePage); |
| 1776 | + } |
| 1777 | + |
| 1778 | + static CStringA DMW2A(const CStringW& str, UINT CodePage = CP_ACP) |
| 1779 | + { |
| 1780 | + return DMWC2A((LPCWSTR)str, str.GetLength(), CodePage); |
| 1781 | + } |
| 1782 | + |
| 1783 | + static CStringW DMW2W(const CStringW& str) |
| 1784 | + { |
| 1785 | + return str; |
| 1786 | + } |
| 1787 | + |
| 1788 | + static CStringA DMA2A(const CStringA& str, UINT CodePageFrom = CP_UTF8, UINT CodePageTo = CP_ACP) |
| 1789 | + { |
| 1790 | + if (CodePageFrom == CodePageTo) |
| 1791 | + return str; |
| 1792 | + CStringW strw = DMA2W(str, CodePageFrom); |
| 1793 | + return DMW2A(strw, CodePageTo); |
| 1794 | + } |
| 1795 | + |
| 1796 | + |
| 1797 | +#ifdef UNICODE |
| 1798 | +#define DMA2T DMA2W |
| 1799 | +#define DMW2T DMW2W |
| 1800 | +#define DMT2A DMW2A |
| 1801 | +#define DMT2W DMW2W |
| 1802 | +#else |
| 1803 | +#define DMA2T DMA2A |
| 1804 | +#define DMW2T DMW2A |
| 1805 | +#define DMT2A DMA2A |
| 1806 | +#define DMT2W DMA2W |
| 1807 | +#endif |
| 1808 | +} |
0 commit comments