am 56ac3bf1: am 9e0c711a: Stop using STL string in additional_proximity_chars
* commit '56ac3bf13d495d856e927bbeb0faafeaf2ee874e': Stop using STL string in additional_proximity_charsmain
commit
86ef75cf79
|
@ -17,7 +17,9 @@
|
||||||
#include "additional_proximity_chars.h"
|
#include "additional_proximity_chars.h"
|
||||||
|
|
||||||
namespace latinime {
|
namespace latinime {
|
||||||
const std::string AdditionalProximityChars::LOCALE_EN_US("en");
|
// TODO: Stop using hardcoded additional proximity characters.
|
||||||
|
// TODO: Have proximity character informations in each language's binary dictionary.
|
||||||
|
const char *AdditionalProximityChars::LOCALE_EN_US = "en";
|
||||||
|
|
||||||
const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_A[EN_US_ADDITIONAL_A_SIZE] = {
|
const int32_t AdditionalProximityChars::EN_US_ADDITIONAL_A[EN_US_ADDITIONAL_A_SIZE] = {
|
||||||
'e', 'i', 'o', 'u'
|
'e', 'i', 'o', 'u'
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#ifndef LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
#ifndef LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
||||||
#define LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
#define LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ namespace latinime {
|
||||||
class AdditionalProximityChars {
|
class AdditionalProximityChars {
|
||||||
private:
|
private:
|
||||||
DISALLOW_IMPLICIT_CONSTRUCTORS(AdditionalProximityChars);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(AdditionalProximityChars);
|
||||||
static const std::string LOCALE_EN_US;
|
static const char *LOCALE_EN_US;
|
||||||
static const int EN_US_ADDITIONAL_A_SIZE = 4;
|
static const int EN_US_ADDITIONAL_A_SIZE = 4;
|
||||||
static const int32_t EN_US_ADDITIONAL_A[];
|
static const int32_t EN_US_ADDITIONAL_A[];
|
||||||
static const int EN_US_ADDITIONAL_E_SIZE = 4;
|
static const int EN_US_ADDITIONAL_E_SIZE = 4;
|
||||||
|
@ -39,15 +39,15 @@ class AdditionalProximityChars {
|
||||||
static const int EN_US_ADDITIONAL_U_SIZE = 4;
|
static const int EN_US_ADDITIONAL_U_SIZE = 4;
|
||||||
static const int32_t EN_US_ADDITIONAL_U[];
|
static const int32_t EN_US_ADDITIONAL_U[];
|
||||||
|
|
||||||
static bool isEnLocale(const std::string *locale_str) {
|
static bool isEnLocale(const char *localeStr) {
|
||||||
const size_t LOCALE_EN_US_SIZE = LOCALE_EN_US.size();
|
const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US);
|
||||||
return locale_str && locale_str->size() >= LOCALE_EN_US_SIZE
|
return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE
|
||||||
&& locale_str->compare(0, LOCALE_EN_US_SIZE, LOCALE_EN_US) == 0;
|
&& strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int getAdditionalCharsSize(const std::string *locale_str, const int32_t c) {
|
static int getAdditionalCharsSize(const char *localeStr, const int32_t c) {
|
||||||
if (!isEnLocale(locale_str)) {
|
if (!isEnLocale(localeStr)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
@ -66,8 +66,8 @@ class AdditionalProximityChars {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int32_t *getAdditionalChars(const std::string *locale_str, const int32_t c) {
|
static const int32_t *getAdditionalChars(const char *localeStr, const int32_t c) {
|
||||||
if (!isEnLocale(locale_str)) {
|
if (!isEnLocale(localeStr)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
|
|
@ -265,6 +265,9 @@ static inline void prof_out(void) {
|
||||||
// This must be equal to ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE in KeyDetector.java
|
// This must be equal to ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE in KeyDetector.java
|
||||||
#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2
|
#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2
|
||||||
|
|
||||||
|
// Assuming locale strings such as en_US, sr-Latn etc.
|
||||||
|
#define MAX_LOCALE_STRING_LENGTH 10
|
||||||
|
|
||||||
// Word limit for sub queues used in WordsPriorityQueuePool. Sub queues are temporary queues used
|
// Word limit for sub queues used in WordsPriorityQueuePool. Sub queues are temporary queues used
|
||||||
// for better performance.
|
// for better performance.
|
||||||
// Holds up to 1 candidate for each word
|
// Holds up to 1 candidate for each word
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#define LOG_TAG "LatinIME: proximity_info.cpp"
|
#define LOG_TAG "LatinIME: proximity_info.cpp"
|
||||||
|
|
||||||
|
@ -68,10 +67,12 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
|
||||||
AKLOGI("Create proximity info array %d", proximityGridLength);
|
AKLOGI("Create proximity info array %d", proximityGridLength);
|
||||||
}
|
}
|
||||||
const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr);
|
const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr);
|
||||||
char localeCStr[localeCStrUtf8Length + 1];
|
if (localeCStrUtf8Length >= MAX_LOCALE_STRING_LENGTH) {
|
||||||
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), localeCStr);
|
AKLOGI("Locale string length too long: length=%d", localeCStrUtf8Length);
|
||||||
localeCStr[localeCStrUtf8Length] = '\0';
|
assert(false);
|
||||||
mLocaleStr = new std::string(localeCStr);
|
}
|
||||||
|
memset(mLocaleStr, 0, sizeof(mLocaleStr));
|
||||||
|
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr);
|
||||||
mProximityCharsArray = new int32_t[proximityGridLength];
|
mProximityCharsArray = new int32_t[proximityGridLength];
|
||||||
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray);
|
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray);
|
||||||
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
|
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
|
||||||
|
@ -98,7 +99,6 @@ void ProximityInfo::initializeCodeToKeyIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProximityInfo::~ProximityInfo() {
|
ProximityInfo::~ProximityInfo() {
|
||||||
delete mLocaleStr;
|
|
||||||
delete[] mProximityCharsArray;
|
delete[] mProximityCharsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#define LATINIME_PROXIMITY_INFO_H
|
#define LATINIME_PROXIMITY_INFO_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
@ -75,8 +74,8 @@ class ProximityInfo {
|
||||||
return MOST_COMMON_KEY_WIDTH_SQUARE;
|
return MOST_COMMON_KEY_WIDTH_SQUARE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getLocaleStr() const {
|
const char *getLocaleStr() const {
|
||||||
return *mLocaleStr;
|
return mLocaleStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getKeyCount() const {
|
int getKeyCount() const {
|
||||||
|
@ -129,7 +128,7 @@ class ProximityInfo {
|
||||||
const int CELL_HEIGHT;
|
const int CELL_HEIGHT;
|
||||||
const int KEY_COUNT;
|
const int KEY_COUNT;
|
||||||
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
||||||
const std::string *mLocaleStr;
|
char mLocaleStr[MAX_LOCALE_STRING_LENGTH];
|
||||||
int32_t *mProximityCharsArray;
|
int32_t *mProximityCharsArray;
|
||||||
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
|
|
Loading…
Reference in New Issue