Skip to content

Commit

Permalink
Simplifying dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gershnik committed Jan 18, 2024
1 parent 8cdf609 commit d6647ec
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 267 deletions.
208 changes: 24 additions & 184 deletions Translit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions Translit/src/AboutWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ -(void) windowDidLoad {
error:nil];
auto parent = NSBundle.mainBundle.bundleURL.URLByStandardizingPath.URLByDeletingLastPathComponent;

sys_string dir;
NSString * dir;
if ([userInputMethods isEqualTo:parent]) {
dir = sys_string(userInputMethods.fileSystemRepresentation);
dir = @( userInputMethods.fileSystemRepresentation );
} else if ([systemInputMethods isEqualTo:parent]) {
dir = sys_string(systemInputMethods.fileSystemRepresentation);
dir = @( systemInputMethods.fileSystemRepresentation );
}

if (!dir.empty()) {
sys_string subPath = sys_string(bundle.executablePath).remove_prefix(sys_string(dir + S("/")));
auto command = [NSString stringWithFormat:@"cd \"%@\"<br/>%@ --uninstall", dir.ns_str(), subPath.ns_str()];
if (dir.length > 0) {
auto prefix = [dir stringByAppendingString:@"/"];
auto exePath = bundle.executablePath;
auto subPath = [exePath stringByReplacingOccurrencesOfString:prefix
withString:@""
options:NSAnchoredSearch
range:{0, exePath.length}];
auto command = [NSString stringWithFormat:@"cd \"%@\"<br/>%@ --uninstall", dir, subPath];
html = [html stringByReplacingOccurrencesOfString:@"%COMMAND_VISIBILITY%" withString:@"visible"];
html = [html stringByReplacingOccurrencesOfString:@"%COMMAND%" withString:command];
} else {
Expand Down
29 changes: 15 additions & 14 deletions Translit/src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ -(void) setValue:(id)value forTag:(long)tag client:(id)sender

switch(tag) {
case langTag: {
sys_string val(value);
sys_string prefix = sys_string(NSBundle.mainBundle.bundleIdentifier) + S(".");
_currentLanguage = val.remove_prefix(prefix).ns_str();
auto val = (NSString*)value;
auto prefix = [NSBundle.mainBundle.bundleIdentifier stringByAppendingString:@"."];
_currentLanguage = [val stringByReplacingOccurrencesOfString:prefix withString:@""
options:NSAnchoredSearch range:{0, val.length}];
os_log_info(OS_LOG_DEFAULT, "Setting language to %{public}@", _currentLanguage);
_transliterator = std::make_unique<Transliterator>(_currentLanguage);
auto del = (AppDelegate *)NSApp.delegate;
Expand Down Expand Up @@ -118,11 +119,11 @@ -(void) deactivateServer:(id)sender {
-(void) commitAllToSender:(id<IMKTextInput>)sender {

if (auto all = _transliterator->result(); !all.empty()) {
sys_string text(all);
auto text = makeNSString(all);
#ifndef NDEBUG
os_log_debug(OS_LOG_DEFAULT, "Sending completed: %{public}@", text.ns_str());
os_log_debug(OS_LOG_DEFAULT, "Sending completed: %{public}@", text);
#endif
[sender insertText:text.ns_str() replacementRange:NSRange{NSNotFound, NSNotFound}];
[sender insertText:text replacementRange:NSRange{NSNotFound, NSNotFound}];
_transliterator->clear();
}
}
Expand All @@ -141,22 +142,22 @@ -(BOOL) commitPartialToSender:(id<IMKTextInput>)sender {
assert(!_transliterator->result().empty());

if (auto completedSize = _transliterator->completedSize()) {
sys_string text(_transliterator->result().data(), completedSize);
auto text = makeNSString(_transliterator->result().substr(0, completedSize));
#ifndef NDEBUG
os_log_debug(OS_LOG_DEFAULT, "Sending completed: '%{public}@'", text.ns_str());
os_log_debug(OS_LOG_DEFAULT, "Sending completed: '%{public}@'", text);
#endif
[sender insertText:text.ns_str() replacementRange:NSRange{NSNotFound, NSNotFound}];
[sender insertText:text replacementRange:NSRange{NSNotFound, NSNotFound}];
_transliterator->clearCompleted();
}
//at this point the only remaining thing in impl is incomplete tail
if (auto incomplete = _transliterator->result(); !incomplete.empty()) {
sys_string text(incomplete);
auto text = makeNSString(incomplete);
#ifndef NDEBUG
os_log_debug(OS_LOG_DEFAULT, "Sending incomplete: '%{public}@'", text.ns_str());
os_log_debug(OS_LOG_DEFAULT, "Sending incomplete: '%{public}@'", text);
#endif
[sender setMarkedText:text.ns_str()
selectionRange:NSRange{0, NSUInteger(text.storage_size())}
replacementRange:NSRange{NSNotFound, NSNotFound}];
[sender setMarkedText:text
selectionRange:{0, text.length}
replacementRange:{NSNotFound, NSNotFound}];
}
return YES;
}
Expand Down
4 changes: 2 additions & 2 deletions Translit/src/MappingsWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ -(void) setLanguage:(NSString *)language {
if (!_text)
return;
if (_language) {
sys_string name = S("mapping-") + sys_string(_language);
auto url = [NSBundle.mainBundle URLForResource:name.ns_str() withExtension:@"pdf"];
auto name = [@"mapping-" stringByAppendingString:_language];
auto url = [NSBundle.mainBundle URLForResource:name withExtension:@"pdf"];
auto * image = [[NSImage alloc] initWithContentsOfURL:url];
_text.image = image;
} else {
Expand Down
11 changes: 5 additions & 6 deletions Translit/src/Transliterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
#include "TableRU.hpp"
#include "TableHE.hpp"

auto Transliterator::getMapper(const sys_string & name) -> MappingFunc * {
auto Transliterator::getMapper(const NSStringCharAccess & name) -> MappingFunc * {

static constexpr auto mapNameToMapper = makeMapper<sys_string::char_access,
static constexpr auto mapNameToMapper = makeMapper<NSStringCharAccess,
nullPrefixMapper<Char, Range>,
Mapping{(MappingFunc *)g_mapperRu<Range>, u"ru"},
Mapping{(MappingFunc *)g_mapperHe<Range>, u"he"}
>();

return mapNameToMapper(sys_string::char_access(name));
return mapNameToMapper(name);
}

void Transliterator::append(const sys_string & str) {
sys_string::char_access strAccess(str);
m_prefix.append(strAccess.begin(), strAccess.end());
void Transliterator::append(const NSStringCharAccess & str) {
m_prefix.append(str.begin(), str.end());
m_translit.erase(m_translit.begin() + m_translitCompletedSize, m_translit.end());

const auto begin = m_prefix.cbegin();
Expand Down
6 changes: 3 additions & 3 deletions Translit/src/Transliterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class Transliterator {
using MappingFunc = PrefixMappingResult<Char, Iterator> (const Range &);

public:
Transliterator(const sys_string & name): m_mapper(getMapper(name))
Transliterator(const NSStringCharAccess & name): m_mapper(getMapper(name))
{}

void append(const sys_string & str);
void append(const NSStringCharAccess & str);

auto result() const -> StringView
{ return m_translit; }
Expand All @@ -43,7 +43,7 @@ class Transliterator {
}

private:
static auto getMapper(const sys_string & name) -> MappingFunc *;
static auto getMapper(const NSStringCharAccess & name) -> MappingFunc *;

private:
MappingFunc * m_mapper = nullPrefixMapper<Char, Range>;
Expand Down
3 changes: 1 addition & 2 deletions Translit/src/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef TRANSLIT_HEADER_PCH_HPP_INCLUDED
#define TRANSLIT_HEADER_PCH_HPP_INCLUDED

#include <sys_string/sys_string.h>
#include <objc-helpers/NSStringUtil.h>

#include <memory>
#include <array>
Expand Down Expand Up @@ -32,7 +32,6 @@

#import <os/log.h>

using namespace sysstr;

#endif

28 changes: 14 additions & 14 deletions Translit/tests/TestRu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,55 @@ @implementation TestRu {
}

- (void)setUp {
_tr = std::make_unique<Transliterator>(S("ru"));
_tr = std::make_unique<Transliterator>(NSStringCharAccess(@"ru"));
}

- (void)tearDown {
_tr->clear();
}

- (void)testUnmapped {
_tr->append(S(" "));
_tr->append(NSStringCharAccess(@" "));
XCTAssertTranslit(*_tr, u" "sv, 1, false);
}

- (void)testSingle {

_tr->append(S("a"));
_tr->append(NSStringCharAccess(@"a"));
XCTAssertTranslit(*_tr, u"а"sv, 1, true);
_tr->append(S("b"));
_tr->append(NSStringCharAccess(@"b"));
XCTAssertTranslit(*_tr, u"аб"sv, 2, true);
}

- (void)testDoubleInterrupted {
_tr->append(S("z"));
_tr->append(NSStringCharAccess(@"z"));
XCTAssertTranslit(*_tr, u"з"sv, 0, true);
_tr->append(S("."));
_tr->append(NSStringCharAccess(@"."));
XCTAssertTranslit(*_tr, u"з."sv, 2, true);
}

- (void)testDouble {
_tr->append(S("z"));
_tr->append(NSStringCharAccess(@"z"));
XCTAssertTranslit(*_tr, u"з"sv, 0, true);
_tr->append(S("h"));
_tr->append(NSStringCharAccess(@"h"));
XCTAssertTranslit(*_tr, u"ж"sv, 1, true);
}

- (void)testTripleInterrupted {
_tr->append(S("s"));
_tr->append(NSStringCharAccess(@"s"));
XCTAssertTranslit(*_tr, u"с"sv, 0, true);
_tr->append(S("h"));
_tr->append(NSStringCharAccess(@"h"));
XCTAssertTranslit(*_tr, u"ш"sv, 0, true);
_tr->append(S(" "));
_tr->append(NSStringCharAccess(@" "));
XCTAssertTranslit(*_tr, u"ш "sv, 2, true);
}

- (void)testTriple {
_tr->append(S("s"));
_tr->append(NSStringCharAccess(@"s"));
XCTAssertTranslit(*_tr, u"с"sv, 0, true);
_tr->append(S("h"));
_tr->append(NSStringCharAccess(@"h"));
XCTAssertTranslit(*_tr, u"ш"sv, 0, true);
_tr->append(S("h"));
_tr->append(NSStringCharAccess(@"h"));
XCTAssertTranslit(*_tr, u"щ"sv, 1, true);
}

Expand Down
4 changes: 2 additions & 2 deletions config/Translit.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

#include "sys_string-Exports.xcconfig"
#include "objc-helpers-Exports.xcconfig"


PRODUCT_BUNDLE_IDENTIFIER = $(ROOT_BUNDLE_IDENTIFIER)
Expand All @@ -18,7 +18,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
COMBINE_HIDPI_IMAGES = YES
SWIFT_EMIT_LOC_STRINGS = YES

HEADER_SEARCH_PATHS = $(inherited) $(SYS_STRING_HEADER_SEARCH_PATHS)
HEADER_SEARCH_PATHS = $(inherited) $(OBJC_HELPERS_HEADER_SEARCH_PATHS)
GCC_PREFIX_HEADER = Translit/src/pch.hpp


Expand Down
3 changes: 1 addition & 2 deletions config/TranslitTests.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

#include "sys_string-Exports.xcconfig"
#include "objc-helpers-Exports.xcconfig"

PRODUCT_NAME = $(TARGET_NAME)
ONLY_ACTIVE_ARCH = YES
PRODUCT_BUNDLE_IDENTIFIER = $(ROOT_BUNDLE_IDENTIFIER).tests
GENERATE_INFOPLIST_FILE = YES
SWIFT_EMIT_LOC_STRINGS = NO
HEADER_SEARCH_PATHS = $(inherited) $(SYS_STRING_HEADER_SEARCH_PATHS) $(OBJC_HELPERS_HEADER_SEARCH_PATHS)
HEADER_SEARCH_PATHS = $(inherited) $(OBJC_HELPERS_HEADER_SEARCH_PATHS)
GCC_PREFIX_HEADER = Translit/src/pch.hpp
GCC_PREPROCESSOR_DEFINITIONS = TRANSLIT_TESTING=1 $(inherited)
//TEST_HOST = $(BUILT_PRODUCTS_DIR)/Translit.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Translit
Expand Down
8 changes: 0 additions & 8 deletions config/sys_string-Exports.xcconfig

This file was deleted.

13 changes: 0 additions & 13 deletions config/sys_string.xcconfig

This file was deleted.

12 changes: 1 addition & 11 deletions fetch
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,8 @@ from pathlib import Path
from urllib.request import urlretrieve

components = {
'sys_string': {
'ver': '2.13',
'url': 'https://github.com/gershnik/sys_string/releases/download/v{ver}/sys_string-{ver}.tar.gz',
'unpacker': {
'type': 'tar',
'subst': r'#sys_string/##'
},
'dir': 'sys_string',
'verFile': 'VERSION'
},
'objc-helpers': {
'ver': '2.3',
'ver': '3.0',
'url': 'https://github.com/gershnik/objc-helpers/releases/download/v{ver}/objc-helpers-{ver}.tar.gz',
'unpacker': {
'type': 'tar'
Expand Down

0 comments on commit d6647ec

Please sign in to comment.