From ac569a5d7411bd2e92a5b2988b1180b9b01a8d07 Mon Sep 17 00:00:00 2001 From: David Mott Date: Sun, 31 Jul 2016 07:46:05 -0500 Subject: [PATCH] - download wordnet during cmake - cleanup string formatting --- CMakeLists.txt | 6 +- include/xtd/mapped_file.hpp | 2 +- include/xtd/nlp/wordnet.hpp | 3 +- include/xtd/string.hpp | 207 +++++++++++++++++++++--------------- include/xtd/xtd.hpp.in | 1 + 5 files changed, 129 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdccf2c..b25cf93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,7 +240,11 @@ endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/xtd/xtd.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/xtd/xtd.hpp) - +file(DOWNLOAD http://wordnetcode.princeton.edu/3.0/WordNet-3.0.tar.bz2 ${CMAKE_BINARY_DIR}/WordNet-3.0.tar.bz2) +execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_BINARY_DIR}/WordNet-3.0.tar.bz2 + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ +) if(NOT GTEST_FOUND) message("Google test framework will be downloaded") diff --git a/include/xtd/mapped_file.hpp b/include/xtd/mapped_file.hpp index b63c494..f633f89 100644 --- a/include/xtd/mapped_file.hpp +++ b/include/xtd/mapped_file.hpp @@ -9,7 +9,7 @@ namespace xtd{ int _FileNum; public: mapped_file(const path& Path) - : _FileNum(xtd::crt_exception::throw_if(open(Path. ), [](int i){ return -1==i; })) + : _FileNum(xtd::crt_exception::throw_if(open(Path.string().c_str(), O_CREAT), [](int i){ return -1==i; })) {} template class mapped_page{ diff --git a/include/xtd/nlp/wordnet.hpp b/include/xtd/nlp/wordnet.hpp index aaa94cc..97dae85 100644 --- a/include/xtd/nlp/wordnet.hpp +++ b/include/xtd/nlp/wordnet.hpp @@ -44,7 +44,7 @@ namespace xtd using map = std::map; size_t file_offset; std::string lemma, pos, synset_cnt, p_cnt, ptr_symbol, sense_cnt, tagsense_cnt, synset_offset; - bool load(const std::string& sFile, size_t & i) { + bool load(const std::string& , size_t & ) { return false; } }; @@ -227,7 +227,6 @@ namespace xtd t6.get(); t7.get(); t8.get(); - auto x = _index_verb.records.size(); } database(const database&) = delete; diff --git a/include/xtd/string.hpp b/include/xtd/string.hpp index feae24b..fb5a6f1 100644 --- a/include/xtd/string.hpp +++ b/include/xtd/string.hpp @@ -42,11 +42,19 @@ namespace xtd{ @param oArgs variable elements appended together */ - template - static xstring format(_ArgsT&&...oArgs){ - return _::xstring_format<_ChT, _ArgsT...>::format(std::forward<_ArgsT>(oArgs)...); + static xstring format(){ + return xstring((_ChT*)""); + } + + + template + static xstring format(_Ty val, _ArgsT&&...oArgs){ + xstring sRet = _::xstring_format<_ChT, const _Ty&>::format(static_cast(val)); + sRet += format(std::forward<_ArgsT>(oArgs)...); + return sRet; } + /** Converts the string to lower case @param loc The locale to use during conversion @@ -183,39 +191,35 @@ namespace xtd{ #endif }; -#if (!DOXY_INVOKED) - namespace _{ - //empty + namespace _{ template class xstring_format<_ChT>{ public: - template static xstring<_ChT> format(_ArgTs...){ return xstring<_ChT>(); } + static xstring<_ChT> format(){ return xstring<_ChT>(); } }; - -#if (XTD_HAS_CODECVT || XTD_HAS_EXP_CODECVT) - - template class xstring_format{ + #if (XTD_HAS_CODECVT || XTD_HAS_EXP_CODECVT) + template <> class xstring_format{ public: - static inline string format(const wchar_t * src, _ArgTs...oArgs){ + static inline string format(const wchar_t * const & src){ std::wstring_convert, wchar_t> oConv; - return oConv.to_bytes(src) + xstring_format::format(std::forward<_ArgTs>(oArgs)...); + return oConv.to_bytes(src); } }; - template class xstring_format{ + template <> class xstring_format{ public: - static inline wstring format(const char * src, _ArgTs...oArgs){ + static inline wstring format(const char * const & src){ std::wstring_convert, wchar_t> oConv; - return oConv.from_bytes(src) + xstring_format::format(std::forward<_ArgTs>(oArgs)...); + return oConv.from_bytes(src); } }; -#elif (XTD_HAS_ICONV) + #elif (XTD_HAS_ICONV) - template class xstring_format{ + template <> class xstring_format{ public: - static string format(const wchar_t * src, _ArgTs...oArgs){ + static string format(const wchar_t * const & src){ static iconv_helper oIconv("UTF-8", "WCHAR_T"); size_t srclen = wcslen(src); string sRet(srclen, 0); @@ -223,24 +227,24 @@ namespace xtd{ iconv(oIconv, nullptr, nullptr, nullptr, &retlen); forever{ retlen = sRet.size(); - auto pSrc = reinterpret_cast(src); - auto iSrcLen = srclen * sizeof(wchar_t); - auto sRetPtr = &sRet[0]; - auto iRet = iconv(oIconv, const_cast(&pSrc), &iSrcLen, &sRetPtr, &retlen); - if (static_cast(-1) != iRet){ - return sRet; - } - if (errno != E2BIG){ - throw std::runtime_error("A string conversion error occurred"); - } - sRet.resize(sRet.size() * 2); + auto pSrc = reinterpret_cast(src); + auto iSrcLen = srclen * sizeof(wchar_t); + auto sRetPtr = &sRet[0]; + auto iRet = iconv(oIconv, const_cast(&pSrc), &iSrcLen, &sRetPtr, &retlen); + if (static_cast(-1) != iRet){ + return sRet; + } + if (errno != E2BIG){ + throw std::runtime_error("A string conversion error occurred"); + } + sRet.resize(sRet.size() * 2); } } }; - template class xstring_format{ + template <> class xstring_format{ public: - static inline wstring format(const char * src, _ArgTs...oArgs){ + static inline wstring format(const char * const & src){ static iconv_helper oIconv("WCHAR_T", "UTF-8"); size_t srclen = strlen(src); wstring sRet(srclen, 0); @@ -248,65 +252,117 @@ namespace xtd{ iconv(oIconv, nullptr, nullptr, nullptr, &retlen); forever{ retlen = sRet.size() * sizeof(wchar_t); - auto pSrc = const_cast(src); - auto iSrcLen = srclen; - auto sRetPtr = reinterpret_cast(&sRet[0]); - auto iRet = iconv(oIconv, &pSrc, &iSrcLen, &sRetPtr, &retlen); - if (static_cast(-1) != iRet) { - return sRet; - } - if (errno != E2BIG){ - throw std::runtime_error("A string conversion error occurred"); - } - sRet.resize(sRet.size() * 2); + auto pSrc = const_cast(src); + auto iSrcLen = srclen; + auto sRetPtr = reinterpret_cast(&sRet[0]); + auto iRet = iconv(oIconv, &pSrc, &iSrcLen, &sRetPtr, &retlen); + if (static_cast(-1) != iRet){ + return sRet; + } + if (errno != E2BIG){ + throw std::runtime_error("A string conversion error occurred"); + } + sRet.resize(sRet.size() * 2); } } }; -#else + #else - template class xstring_format { + template <> class xstring_format{ public: - static string format(const wchar_t *src, _ArgTs...oArgs) { + static string format(const wchar_t * const & src){ size_t srclen = wcslen(src); string sRet(srclen, 0); - forever { + forever{ srclen = wcstombs(&sRet[0], src, sRet.size()); - if (static_cast(-1) == srclen) { - throw std::runtime_error("A string conversion error occurred"); - } - if (srclen < sRet.size()) { - break; - } - sRet.resize(srclen * 2); + if (static_cast(-1) == srclen){ + throw std::runtime_error("A string conversion error occurred"); + } + if (srclen < sRet.size()){ + break; + } + sRet.resize(srclen * 2); } sRet.resize(srclen); return sRet; } }; - template class xstring_format { + template <> class xstring_format{ public: - static inline wstring format(const char *src, _ArgTs...oArgs) { + static inline wstring format(const char * const & src){ size_t srclen = strlen(src); wstring sRet(srclen, 0); - forever { + forever{ srclen = mbstowcs(&sRet[0], src, sRet.size()); - if (static_cast(-1) == srclen) { - throw std::runtime_error("A string conversion error occurred"); - } - if (srclen < sRet.size()) { - break; - } - sRet.resize(srclen * 2); + if (static_cast(-1) == srclen){ + throw std::runtime_error("A string conversion error occurred"); + } + if (srclen < sRet.size()){ + break; + } + sRet.resize(srclen * 2); } sRet.resize(srclen); return sRet; } }; -#endif + #endif + + template class xstring_format<_ChT, const _ChT * const &>{ + public: + inline static xstring<_ChT> format(const _ChT * const & src){ + return xstring<_ChT>(src); + } + }; + + template class xstring_format<_ChT, const xtd::xstring<_Ch2> &>{ + public: + inline static xstring<_ChT> format(const xtd::xstring<_Ch2> & src){ + return xstring<_ChT>::format(src.c_str()); + } + }; + + + template <> class xstring_format{ + public: + inline static string format(const void * const & value){ + return std::to_string(reinterpret_cast(value)); + } + }; + + + template <> class xstring_format{ + public: + inline static string format(const int32_t & value){ + return std::to_string(value); + } + }; + + + template <> class xstring_format{ + public: + inline static string format(const DWORD & value){ + return std::to_string(value); + } + }; + + + } + +#if (0) + namespace _{ + + //empty + template class xstring_format<_ChT>{ + public: + static xstring<_ChT> format(){ return xstring<_ChT>(); } + }; + + template class xstring_format{ @@ -420,21 +476,6 @@ namespace xtd{ return std::to_wstring(value) + xstring_format::format(std::forward<_ArgTs>(oArgs)...); } }; - #if ((XTD_OS_WINDOWS | XTD_OS_MINGW) & XTD_OS) - template class xstring_format{ - public: - inline static string format(DWORD& value, _ArgTs&&...oArgs){ - return std::to_string(value) + xstring_format::format(std::forward<_ArgTs>(oArgs)...); - } - }; - - template class xstring_format{ - public: - inline static wstring format(DWORD& value, _ArgTs&&...oArgs){ - return std::to_wstring(value) + xstring_format::format(std::forward<_ArgTs>(oArgs)...); - } - }; - #endif template class xstring_format{ public: @@ -480,12 +521,6 @@ namespace xtd{ }; - template class xstring_format<_ChT, const _ChT*&, _ArgTs...>{ - public: - inline static xstring<_ChT> format(const _ChT*&src, _ArgTs&&...oArgs){ - return xstring<_ChT>(src) + xstring_format<_ChT, _ArgTs...>::format(std::forward<_ArgTs>(oArgs)...); - } - }; template class xstring_format<_ChT, const _ChT*, _ArgTs...>{ public: diff --git a/include/xtd/xtd.hpp.in b/include/xtd/xtd.hpp.in index 0a9c95a..232d37c 100644 --- a/include/xtd/xtd.hpp.in +++ b/include/xtd/xtd.hpp.in @@ -306,6 +306,7 @@ namespace xtd{ #include #include #include + using DWORD = unsigned long; #endif #if (XTD_OS_LINUX & XTD_OS)