Format ObjC code with clang-format, WebKit style
This commit is contained in:
parent
ca2f4bf8fd
commit
2091c1dc7d
|
@ -29,16 +29,17 @@ extern unsigned short vxSC2TCTable[];
|
||||||
const size_t vxTC2SCTableSize = 3059;
|
const size_t vxTC2SCTableSize = 3059;
|
||||||
extern unsigned short vxTC2SCTable[];
|
extern unsigned short vxTC2SCTable[];
|
||||||
|
|
||||||
struct VXHCData
|
struct VXHCData {
|
||||||
{
|
|
||||||
unsigned short key, value;
|
unsigned short key, value;
|
||||||
};
|
};
|
||||||
|
|
||||||
int VXHCCompare(const void *a, const void *b)
|
int VXHCCompare(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
unsigned short x = ((const struct VXHCData *)a)->key, y = ((const struct VXHCData *)b)->key;
|
unsigned short x = ((const struct VXHCData *)a)->key, y = ((const struct VXHCData *)b)->key;
|
||||||
if (x==y) return 0;
|
if (x == y)
|
||||||
if (x<y) return -1;
|
return 0;
|
||||||
|
if (x < y)
|
||||||
|
return -1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ unsigned short VXHCFind(unsigned key, unsigned short *table, size_t size)
|
||||||
struct VXHCData k;
|
struct VXHCData k;
|
||||||
k.key = key;
|
k.key = key;
|
||||||
struct VXHCData *d = (struct VXHCData *)bsearch(&k, table, size, sizeof(struct VXHCData), VXHCCompare);
|
struct VXHCData *d = (struct VXHCData *)bsearch(&k, table, size, sizeof(struct VXHCData), VXHCCompare);
|
||||||
if (!d) return 0;
|
if (!d)
|
||||||
|
return 0;
|
||||||
return d->value;
|
return d->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
// OTHER DEALINGS IN THE SOFTWARE.
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#import "Mandarin.h"
|
#import "KeyHandler.h"
|
||||||
#import "Gramambular.h"
|
#import "Gramambular.h"
|
||||||
|
#import "LanguageModelManager+Privates.h"
|
||||||
|
#import "Mandarin.h"
|
||||||
|
#import "McBopomofo-Swift.h"
|
||||||
#import "McBopomofoLM.h"
|
#import "McBopomofoLM.h"
|
||||||
#import "UserOverrideModel.h"
|
#import "UserOverrideModel.h"
|
||||||
#import "LanguageModelManager+Privates.h"
|
|
||||||
#import "KeyHandler.h"
|
|
||||||
#import "McBopomofo-Swift.h"
|
|
||||||
#import <string>
|
#import <string>
|
||||||
|
|
||||||
@import CandidateUI;
|
@import CandidateUI;
|
||||||
|
@ -44,7 +44,8 @@ InputMode InputModePlainBopomofo = @"org.openvanilla.inputmethod.McBopomofo.Plai
|
||||||
|
|
||||||
static const double kEpsilon = 0.000001;
|
static const double kEpsilon = 0.000001;
|
||||||
|
|
||||||
static double FindHighestScore(const vector<NodeAnchor> &nodes, double epsilon) {
|
static double FindHighestScore(const vector<NodeAnchor> &nodes, double epsilon)
|
||||||
|
{
|
||||||
double highestScore = 0.0;
|
double highestScore = 0.0;
|
||||||
for (auto ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) {
|
for (auto ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) {
|
||||||
double score = ni->node->highestUnigramScore();
|
double score = ni->node->highestUnigramScore();
|
||||||
|
@ -56,10 +57,10 @@ static double FindHighestScore(const vector<NodeAnchor> &nodes, double epsilon)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort helper
|
// sort helper
|
||||||
class NodeAnchorDescendingSorter
|
class NodeAnchorDescendingSorter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
bool operator()(const NodeAnchor &a, const NodeAnchor &b) const {
|
bool operator()(const NodeAnchor &a, const NodeAnchor &b) const
|
||||||
|
{
|
||||||
return a.node->key().length() > b.node->key().length();
|
return a.node->key().length() > b.node->key().length();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -70,9 +71,7 @@ public:
|
||||||
static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot";
|
static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@implementation KeyHandler {
|
||||||
@implementation KeyHandler
|
|
||||||
{
|
|
||||||
// the reading buffer that takes user input
|
// the reading buffer that takes user input
|
||||||
Formosa::Mandarin::BopomofoReadingBuffer *_bpmfReadingBuffer;
|
Formosa::Mandarin::BopomofoReadingBuffer *_bpmfReadingBuffer;
|
||||||
|
|
||||||
|
@ -218,8 +217,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
}
|
}
|
||||||
[self _walk];
|
[self _walk];
|
||||||
|
|
||||||
if (Preferences.selectPhraseAfterCursorAsCandidate &&
|
if (Preferences.selectPhraseAfterCursorAsCandidate && Preferences.moveCursorAfterSelectingCandidate) {
|
||||||
Preferences.moveCursorAfterSelectingCandidate) {
|
|
||||||
size_t nextPosition = 0;
|
size_t nextPosition = 0;
|
||||||
for (auto node : _walkedNodes) {
|
for (auto node : _walkedNodes) {
|
||||||
if (nextPosition >= cursorIndex) {
|
if (nextPosition >= cursorIndex) {
|
||||||
|
@ -260,9 +258,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
|
|
||||||
// if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it
|
// if the composing buffer is empty and there's no reading, and there is some function key combination, we ignore it
|
||||||
BOOL isFunctionKey = ([input isCommandHold] || [input isOptionHold] || [input isNumericPad]) || [input isControlHotKey];
|
BOOL isFunctionKey = ([input isCommandHold] || [input isOptionHold] || [input isNumericPad]) || [input isControlHotKey];
|
||||||
if (![state isKindOfClass:[InputStateNotEmpty class]] &&
|
if (![state isKindOfClass:[InputStateNotEmpty class]] && ![state isKindOfClass:[InputStateAssociatedPhrases class]] && isFunctionKey) {
|
||||||
![state isKindOfClass:[InputStateAssociatedPhrases class]] &&
|
|
||||||
isFunctionKey) {
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,8 +367,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
NSString *poppedText = [self _popOverflowComposingTextAndWalk];
|
NSString *poppedText = [self _popOverflowComposingTextAndWalk];
|
||||||
|
|
||||||
// get user override model suggestion
|
// get user override model suggestion
|
||||||
string overrideValue = (_inputMode == InputModePlainBopomofo) ? "" :
|
string overrideValue = (_inputMode == InputModePlainBopomofo) ? "" : _userOverrideModel->suggest(_walkedNodes, _builder->cursorIndex(), [[NSDate date] timeIntervalSince1970]);
|
||||||
_userOverrideModel->suggest(_walkedNodes, _builder->cursorIndex(), [[NSDate date] timeIntervalSince1970]);
|
|
||||||
|
|
||||||
if (!overrideValue.empty()) {
|
if (!overrideValue.empty()) {
|
||||||
size_t cursorIndex = [self _actualCandidateCursorIndex];
|
size_t cursorIndex = [self _actualCandidateCursorIndex];
|
||||||
|
@ -420,8 +415,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
// MARK: Space and Down
|
// MARK: Space and Down
|
||||||
// keyCode 125 = Down, charCode 32 = Space
|
// keyCode 125 = Down, charCode 32 = Space
|
||||||
if (_bpmfReadingBuffer->isEmpty() &&
|
if (_bpmfReadingBuffer->isEmpty() &&
|
||||||
[state isKindOfClass:[InputStateNotEmpty class]] &&
|
[state isKindOfClass:[InputStateNotEmpty class]] && ([input isExtraChooseCandidateKey] || charCode == 32 || (input.useVerticalMode && ([input isVerticalModeOnlyChooseCandidateKey])))) {
|
||||||
([input isExtraChooseCandidateKey] || charCode == 32 || (input.useVerticalMode && ([input isVerticalModeOnlyChooseCandidateKey])))) {
|
|
||||||
if (charCode == 32) {
|
if (charCode == 32) {
|
||||||
// if the spacebar is NOT set to be a selection key
|
// if the spacebar is NOT set to be a selection key
|
||||||
if ([input isShiftHold] || !Preferences.chooseCandidateUsingSpace) {
|
if ([input isShiftHold] || !Preferences.chooseCandidateUsingSpace) {
|
||||||
|
@ -444,7 +438,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
stateCallback(inputting);
|
stateCallback(inputting);
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InputStateChoosingCandidate *choosingCandidates = [self _buildCandidateState:(InputStateNotEmpty *)state useVerticalMode:input.useVerticalMode];
|
InputStateChoosingCandidate *choosingCandidates = [self _buildCandidateState:(InputStateNotEmpty *)state useVerticalMode:input.useVerticalMode];
|
||||||
|
@ -809,7 +802,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)_handleEnterWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
|
- (BOOL)_handleEnterWithState:(InputState *)state stateCallback:(void (^)(InputState *))stateCallback errorCallback:(void (^)(void))errorCallback
|
||||||
{
|
{
|
||||||
if (![state isKindOfClass:[InputStateInputting class]]) {
|
if (![state isKindOfClass:[InputStateInputting class]]) {
|
||||||
|
@ -863,7 +855,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)_handleMarkingState:(InputStateMarking *)state
|
- (BOOL)_handleMarkingState:(InputStateMarking *)state
|
||||||
input:(KeyHandlerInput *)input
|
input:(KeyHandlerInput *)input
|
||||||
stateCallback:(void (^)(InputState *))stateCallback
|
stateCallback:(void (^)(InputState *))stateCallback
|
||||||
|
@ -933,7 +924,6 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)_handleCandidateState:(InputState *)state
|
- (BOOL)_handleCandidateState:(InputState *)state
|
||||||
input:(KeyHandlerInput *)input
|
input:(KeyHandlerInput *)input
|
||||||
stateCallback:(void (^)(InputState *))stateCallback
|
stateCallback:(void (^)(InputState *))stateCallback
|
||||||
|
@ -950,8 +940,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
[self clear];
|
[self clear];
|
||||||
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
|
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
|
||||||
stateCallback(empty);
|
stateCallback(empty);
|
||||||
}
|
} else if (_inputMode == InputModePlainBopomofo) {
|
||||||
else if (_inputMode == InputModePlainBopomofo) {
|
|
||||||
[self clear];
|
[self clear];
|
||||||
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
|
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
|
||||||
stateCallback(empty);
|
stateCallback(empty);
|
||||||
|
@ -1143,8 +1132,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
string customPunctuation = punctuationNamePrefix + layout + string(1, (char)charCode);
|
string customPunctuation = punctuationNamePrefix + layout + string(1, (char)charCode);
|
||||||
string punctuation = punctuationNamePrefix + string(1, (char)charCode);
|
string punctuation = punctuationNamePrefix + string(1, (char)charCode);
|
||||||
|
|
||||||
BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char) charCode) || _languageModel->hasUnigramsForKey(customPunctuation) ||
|
BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char)charCode) || _languageModel->hasUnigramsForKey(customPunctuation) || _languageModel->hasUnigramsForKey(punctuation);
|
||||||
_languageModel->hasUnigramsForKey(punctuation);
|
|
||||||
|
|
||||||
if (!shouldAutoSelectCandidate && (char)charCode >= 'A' && (char)charCode <= 'Z') {
|
if (!shouldAutoSelectCandidate && (char)charCode >= 'A' && (char)charCode <= 'Z') {
|
||||||
string letter = string("_letter_") + string(1, (char)charCode);
|
string letter = string("_letter_") + string(1, (char)charCode);
|
||||||
|
|
|
@ -116,8 +116,7 @@ static void LTLoadAssociatedPhrases(McBopomofoLM &lm)
|
||||||
NSString *text = [NSString stringWithUTF8String:input.c_str()];
|
NSString *text = [NSString stringWithUTF8String:input.c_str()];
|
||||||
if (Preferences.chineseConversionEngine == 1) {
|
if (Preferences.chineseConversionEngine == 1) {
|
||||||
text = [VXHanConvert convertToSimplifiedFrom:text];
|
text = [VXHanConvert convertToSimplifiedFrom:text];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
text = [OpenCCBridge convertToSimplified:text];
|
text = [OpenCCBridge convertToSimplified:text];
|
||||||
}
|
}
|
||||||
return string(text.UTF8String);
|
return string(text.UTF8String);
|
||||||
|
|
Loading…
Reference in New Issue