diff --git a/developer/src/kmcmplib/src/kmx_u16.cpp b/common/cpp/km_u16.cpp similarity index 97% rename from developer/src/kmcmplib/src/kmx_u16.cpp rename to common/cpp/km_u16.cpp index 708c82dc04e..84a6c4a75e7 100644 --- a/developer/src/kmcmplib/src/kmx_u16.cpp +++ b/common/cpp/km_u16.cpp @@ -1,16 +1,12 @@ +/* + * Keyman is copyright (C) SIL International. MIT License. + * + * std::u16string functions and string conversion utility functions + */ -//#include "../../kmcompx/include/kmcompx.h" -#include -#include "kmx_u16.h" - -#include -#include -#include -#include -#include #include -#include #include "utfcodec.hpp" +#include "km_u16.h" /** string <- wstring * @brief Obtain a std::string from a std::wstring diff --git a/developer/src/kmcmplib/src/kmx_u16.h b/common/include/km_u16.h similarity index 97% rename from developer/src/kmcmplib/src/kmx_u16.h rename to common/include/km_u16.h index 4ebcdb601dd..f0c2c2d16c1 100644 --- a/developer/src/kmcmplib/src/kmx_u16.h +++ b/common/include/km_u16.h @@ -1,11 +1,8 @@ #pragma once -#include -#include -#include #include #include -#include "kmcompx.h" +#include /** @brief Obtain a std::string from a std::wstring */ std::string string_from_wstring(std::wstring const wstr); diff --git a/developer/src/kmcmplib/include/kmcompx.h b/developer/src/kmcmplib/include/kmcompx.h index 7e7b2704961..9d7ca75508b 100644 --- a/developer/src/kmcmplib/include/kmcompx.h +++ b/developer/src/kmcmplib/include/kmcompx.h @@ -3,11 +3,6 @@ // TODO: merge with kmcmplib.h -typedef wchar_t KMX_WCHART; -typedef KMX_DWORD * PKMX_DWORD; -typedef char * PKMX_STR; -typedef KMX_WCHAR* PKMX_WCHAR ; - // TODO: these defines are copied out of unicode.h, because unicode.h still // has windows-specific types. These should be remerged at a future date diff --git a/developer/src/kmcmplib/src/CasedKeys.cpp b/developer/src/kmcmplib/src/CasedKeys.cpp index 0a0508f11a4..0883c401ce3 100644 --- a/developer/src/kmcmplib/src/CasedKeys.cpp +++ b/developer/src/kmcmplib/src/CasedKeys.cpp @@ -1,13 +1,14 @@ #include "pch.h" +#include "km_u16.h" +#include "../../../../common/windows/cpp/include/vkeys.h" + #include "compfile.h" #include "kmn_compiler_errors.h" -#include "../../../../common/windows/cpp/include/vkeys.h" #include "kmcmplib.h" #include "CharToKeyConversion.h" -#include "kmx_u16.h" #include "xstring.h" namespace kmcmp { diff --git a/developer/src/kmcmplib/src/CheckForDuplicates.cpp b/developer/src/kmcmplib/src/CheckForDuplicates.cpp index 9e5d63b9ef8..e0fa0094bcb 100644 --- a/developer/src/kmcmplib/src/CheckForDuplicates.cpp +++ b/developer/src/kmcmplib/src/CheckForDuplicates.cpp @@ -1,11 +1,11 @@ #include "pch.h" +#include #include "compfile.h" #include #include "kmcmplib.h" #include -#include "kmx_u16.h" #include #include "CheckForDuplicates.h" diff --git a/developer/src/kmcmplib/src/Compiler.cpp b/developer/src/kmcmplib/src/Compiler.cpp index 03f39823667..3893a728559 100644 --- a/developer/src/kmcmplib/src/Compiler.cpp +++ b/developer/src/kmcmplib/src/Compiler.cpp @@ -102,7 +102,7 @@ #include "UnreachableRules.h" #include "CheckForDuplicates.h" -#include "kmx_u16.h" +#include "km_u16.h" /* These macros are adapted from winnt.h and legacy use only */ #define MAKELANGID(p, s) ((((uint16_t)(s)) << 10) | (uint16_t)(p)) diff --git a/developer/src/kmcmplib/src/meson.build b/developer/src/kmcmplib/src/meson.build index 260df09b838..51acf704090 100644 --- a/developer/src/kmcmplib/src/meson.build +++ b/developer/src/kmcmplib/src/meson.build @@ -78,13 +78,13 @@ lib = library('kmcmplib', 'cp1252.cpp', 'DeprecationChecks.cpp', 'Edition.cpp', - 'kmx_u16.cpp', 'NamedCodeConstants.cpp', 'UnreachableRules.cpp', 'uset-api.cpp', 'versioning.cpp', 'virtualcharkeys.cpp', 'xstring.cpp', + '../../../../common/cpp/km_u16.cpp', '../../../../common/cpp/utfcodec.cpp', '../../../../common/windows/cpp/src/ConvertUTF.c', '../../../../common/windows/cpp/src/crc32.cpp', diff --git a/developer/src/kmcmplib/src/pch.h b/developer/src/kmcmplib/src/pch.h index 358e28998ab..80bb639fb8b 100644 --- a/developer/src/kmcmplib/src/pch.h +++ b/developer/src/kmcmplib/src/pch.h @@ -4,7 +4,7 @@ #define USE_CHAR16_T #include -#include "kmx_u16.h" +#include #include #include "../../../../common/windows/cpp/include/crc32.h" diff --git a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp index 22b38dccc67..1c205976452 100644 --- a/developer/src/kmcmplib/tests/gtest-compiler-test.cpp +++ b/developer/src/kmcmplib/tests/gtest-compiler-test.cpp @@ -1,7 +1,7 @@ #include +#include #include "../include/kmcompx.h" #include "../include/kmcmplibapi.h" -#include "../src/kmx_u16.h" #include "../src/compfile.h" #include "../src/CompilerErrors.h" #include "../../common/include/kmn_compiler_errors.h" diff --git a/developer/src/kmcmplib/tests/gtest-kmx_u16-test.cpp b/developer/src/kmcmplib/tests/gtest-km_u16-test.cpp similarity index 94% rename from developer/src/kmcmplib/tests/gtest-kmx_u16-test.cpp rename to developer/src/kmcmplib/tests/gtest-km_u16-test.cpp index aa1dca1de08..b67957bd317 100644 --- a/developer/src/kmcmplib/tests/gtest-kmx_u16-test.cpp +++ b/developer/src/kmcmplib/tests/gtest-km_u16-test.cpp @@ -1,9 +1,9 @@ #include -#include "../src/kmx_u16.h" +#include +#include #include "../src/compfile.h" -#include "../../../../common/include/km_types.h" -TEST(kmx_u16_Test, u16chr) { +TEST(km_u16_Test, u16chr) { KMX_WCHAR str[LINESIZE]; u16cpy(str, u"abc"); @@ -14,7 +14,7 @@ TEST(kmx_u16_Test, u16chr) { EXPECT_EQ(3, u16chr(str, '\0') - str); // locate null terminator } -TEST(kmx_u16_Test, u16chr_compare_to_strchr) { +TEST(km_u16_Test, u16chr_compare_to_strchr) { // Compare behaviour of strchr: char str[LINESIZE]; @@ -26,7 +26,7 @@ TEST(kmx_u16_Test, u16chr_compare_to_strchr) { EXPECT_EQ(3, strchr(str, '\0') - str); // locate null terminator } -TEST(kmx_u16_Test, u16tok_char_delim) { +TEST(km_u16_Test, u16tok_char_delim) { // For char delimiter: KMX_WCHAR * u16tok(KMX_WCHAR *p, const KMX_WCHAR ch, KMX_WCHAR **ctx) ; KMX_WCHAR str[LINESIZE]; @@ -67,7 +67,7 @@ TEST(kmx_u16_Test, u16tok_char_delim) { EXPECT_TRUE(!u16cmp(u"def", ctx)); } -TEST(kmx_u16_Test, u16tok_str_delim) { +TEST(km_u16_Test, u16tok_str_delim) { // For string delimiter: KMX_WCHAR * u16tok(KMX_WCHAR* p, const KMX_WCHAR* ch, KMX_WCHAR** ctx) ; KMX_WCHAR str[LINESIZE]; @@ -126,7 +126,7 @@ TEST(kmx_u16_Test, u16tok_str_delim) { EXPECT_EQ(nullptr, ctx); } -TEST(kmx_u16_Test, u16tok_str_compare_to_strtok) { +TEST(km_u16_Test, u16tok_str_compare_to_strtok) { // Compare behaviour of strtok: char str[LINESIZE]; diff --git a/developer/src/kmcmplib/tests/meson.build b/developer/src/kmcmplib/tests/meson.build index a5b6476c889..65915d1e9d9 100644 --- a/developer/src/kmcmplib/tests/meson.build +++ b/developer/src/kmcmplib/tests/meson.build @@ -168,7 +168,7 @@ gtestcompilertest = executable('gtest-compiler-test', 'gtest-compiler-test.cpp', test('gtest-compiler-test', gtestcompilertest) -gtestkmx_u16test = executable('gtest-kmx_u16-test', 'gtest-kmx_u16-test.cpp', +gtest_km_u16_test = executable('gtest-km_u16-test', 'gtest-km_u16-test.cpp', cpp_args: defns + flags, include_directories: inc, name_suffix: name_suffix, @@ -177,4 +177,4 @@ gtestkmx_u16test = executable('gtest-kmx_u16-test', 'gtest-kmx_u16-test.cpp', dependencies: [ icuuc_dep, gtest_dep, gmock_dep ], ) -test('gtest-kmx_u16-test', gtestkmx_u16test) +test('gtest-km_u16-test', gtest_km_u16_test) diff --git a/developer/src/kmcmplib/tests/util_filesystem.cpp b/developer/src/kmcmplib/tests/util_filesystem.cpp index 4ca210cff93..0873ff13288 100644 --- a/developer/src/kmcmplib/tests/util_filesystem.cpp +++ b/developer/src/kmcmplib/tests/util_filesystem.cpp @@ -117,19 +117,6 @@ FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode) { #endif }; -FILE* Open_File(const KMX_WCHART* Filename, const KMX_WCHART* mode) { -#ifdef _MSC_VER - std::wstring cpath = Filename; //, cmode = mode; - std::replace(cpath.begin(), cpath.end(), '/', '\\'); - return _wfsopen(cpath.c_str(), mode, _SH_DENYWR); -#else - std::string cpath, cmode; - cpath = string_from_wstring(Filename); - cmode = string_from_wstring(mode); - return fopen_wrapper(cpath.c_str(), cmode.c_str()); -#endif -}; - FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode) { #ifdef _MSC_VER std::wstring cpath = wstring_from_u16string(Filename); diff --git a/developer/src/kmcmplib/tests/util_filesystem.h b/developer/src/kmcmplib/tests/util_filesystem.h index 4c94dae6bf4..c35967b05e8 100644 --- a/developer/src/kmcmplib/tests/util_filesystem.h +++ b/developer/src/kmcmplib/tests/util_filesystem.h @@ -1,12 +1,11 @@ #pragma once #include -#include "../src/kmx_u16.h" +#include // Opens files on windows and non-windows platforms. Datatypes for Filename and mode must be the same. // returns FILE* if file could be opened; FILE needs to be closed in calling function FILE* Open_File(const KMX_CHAR* Filename, const KMX_CHAR* mode); -FILE* Open_File(const KMX_WCHART* Filename, const KMX_WCHART* mode); FILE* Open_File(const KMX_WCHAR* Filename, const KMX_WCHAR* mode); KMX_BOOL kmcmp_FileExists(const KMX_CHAR *filename); KMX_BOOL kmcmp_FileExists(const KMX_WCHAR *filename);