Skip to content

Commit

Permalink
Merge pull request #12177 from keymanapp/refactor/kmcmplib/make-kmx_u…
Browse files Browse the repository at this point in the history
…16-common

refactor: move kmx_u16 to common and rename to km_u16
  • Loading branch information
mcdurdin authored Aug 14, 2024
2 parents bad54e4 + dde4e2b commit 50468f0
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 50 deletions.
16 changes: 6 additions & 10 deletions developer/src/kmcmplib/src/kmx_u16.cpp → common/cpp/km_u16.cpp
Original file line number Diff line number Diff line change
@@ -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 <kmcompx.h>
#include "kmx_u16.h"

#include <xstring.h>
#include <km_types.h>
#include <kmx_file.h>
#include <codecvt>
#include <locale>
#include <stdarg.h>
#include <algorithm>
#include "utfcodec.hpp"
#include "km_u16.h"

/** string <- wstring
* @brief Obtain a std::string from a std::wstring
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once

#include <cmath>
#include <vector>
#include <ctype.h>
#include <string>
#include <cstring>
#include "kmcompx.h"
#include <km_types.h>

/** @brief Obtain a std::string from a std::wstring */
std::string string_from_wstring(std::wstring const wstr);
Expand Down
5 changes: 0 additions & 5 deletions developer/src/kmcmplib/include/kmcompx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions developer/src/kmcmplib/src/CasedKeys.cpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmcmplib/src/CheckForDuplicates.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#include "pch.h"

#include <km_u16.h>
#include "compfile.h"
#include <kmn_compiler_errors.h>
#include "kmcmplib.h"
#include <xstring.h>
#include "kmx_u16.h"
#include <kmcompx.h>

#include "CheckForDuplicates.h"
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmcmplib/src/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmcmplib/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmcmplib/src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define USE_CHAR16_T
#include <kmx_file.h>
#include "kmx_u16.h"
#include <km_u16.h>
#include <kmcompx.h>

#include "../../../../common/windows/cpp/include/crc32.h"
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmcmplib/tests/gtest-compiler-test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <km_u16.h>
#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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <gtest/gtest.h>
#include "../src/kmx_u16.h"
#include <km_u16.h>
#include <km_types.h>
#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");
Expand All @@ -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];

Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions developer/src/kmcmplib/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
13 changes: 0 additions & 13 deletions developer/src/kmcmplib/tests/util_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions developer/src/kmcmplib/tests/util_filesystem.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once

#include <stdio.h>
#include "../src/kmx_u16.h"
#include <km_u16.h>

// 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);
Expand Down

0 comments on commit 50468f0

Please sign in to comment.