mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Stop using STL string in additional_proximity_chars
Change-Id: Ic016fd5983b8855b0fd9506a17b205db86af3a2f
This commit is contained in:
parent
805ac949d2
commit
9e0c711a62
@ -17,7 +17,9 @@
|
||||
#include "additional_proximity_chars.h"
|
||||
|
||||
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] = {
|
||||
'e', 'i', 'o', 'u'
|
||||
|
@ -17,8 +17,8 @@
|
||||
#ifndef LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
||||
#define LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
||||
|
||||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
@ -27,7 +27,7 @@ namespace latinime {
|
||||
class AdditionalProximityChars {
|
||||
private:
|
||||
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 int32_t EN_US_ADDITIONAL_A[];
|
||||
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 int32_t EN_US_ADDITIONAL_U[];
|
||||
|
||||
static bool isEnLocale(const std::string *locale_str) {
|
||||
const size_t LOCALE_EN_US_SIZE = LOCALE_EN_US.size();
|
||||
return locale_str && locale_str->size() >= LOCALE_EN_US_SIZE
|
||||
&& locale_str->compare(0, LOCALE_EN_US_SIZE, LOCALE_EN_US) == 0;
|
||||
static bool isEnLocale(const char *localeStr) {
|
||||
const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US);
|
||||
return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE
|
||||
&& strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0;
|
||||
}
|
||||
|
||||
public:
|
||||
static int getAdditionalCharsSize(const std::string *locale_str, const int32_t c) {
|
||||
if (!isEnLocale(locale_str)) {
|
||||
static int getAdditionalCharsSize(const char *localeStr, const int32_t c) {
|
||||
if (!isEnLocale(localeStr)) {
|
||||
return 0;
|
||||
}
|
||||
switch(c) {
|
||||
@ -66,8 +66,8 @@ class AdditionalProximityChars {
|
||||
}
|
||||
}
|
||||
|
||||
static const int32_t *getAdditionalChars(const std::string *locale_str, const int32_t c) {
|
||||
if (!isEnLocale(locale_str)) {
|
||||
static const int32_t *getAdditionalChars(const char *localeStr, const int32_t c) {
|
||||
if (!isEnLocale(localeStr)) {
|
||||
return 0;
|
||||
}
|
||||
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
|
||||
#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
|
||||
// for better performance.
|
||||
// Holds up to 1 candidate for each word
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#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);
|
||||
}
|
||||
const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr);
|
||||
char localeCStr[localeCStrUtf8Length + 1];
|
||||
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), localeCStr);
|
||||
localeCStr[localeCStrUtf8Length] = '\0';
|
||||
mLocaleStr = new std::string(localeCStr);
|
||||
if (localeCStrUtf8Length >= MAX_LOCALE_STRING_LENGTH) {
|
||||
AKLOGI("Locale string length too long: length=%d", localeCStrUtf8Length);
|
||||
assert(false);
|
||||
}
|
||||
memset(mLocaleStr, 0, sizeof(mLocaleStr));
|
||||
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr);
|
||||
mProximityCharsArray = new int32_t[proximityGridLength];
|
||||
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray);
|
||||
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
|
||||
@ -98,7 +99,6 @@ void ProximityInfo::initializeCodeToKeyIndex() {
|
||||
}
|
||||
|
||||
ProximityInfo::~ProximityInfo() {
|
||||
delete mLocaleStr;
|
||||
delete[] mProximityCharsArray;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#define LATINIME_PROXIMITY_INFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include "defines.h"
|
||||
#include "jni.h"
|
||||
@ -75,8 +74,8 @@ class ProximityInfo {
|
||||
return MOST_COMMON_KEY_WIDTH_SQUARE;
|
||||
}
|
||||
|
||||
std::string getLocaleStr() const {
|
||||
return *mLocaleStr;
|
||||
const char *getLocaleStr() const {
|
||||
return mLocaleStr;
|
||||
}
|
||||
|
||||
int getKeyCount() const {
|
||||
@ -129,7 +128,7 @@ class ProximityInfo {
|
||||
const int CELL_HEIGHT;
|
||||
const int KEY_COUNT;
|
||||
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
||||
const std::string *mLocaleStr;
|
||||
char mLocaleStr[MAX_LOCALE_STRING_LENGTH];
|
||||
int32_t *mProximityCharsArray;
|
||||
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||
int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||
|
Loading…
Reference in New Issue
Block a user