mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-02-04 04:54:10 +01:00
fix bugs.
Use getDirectionality instead of serchinf areas
This commit is contained in:
parent
5503c562a3
commit
c0f3907e18
@ -197,16 +197,16 @@ public class LanguageUtils {
|
|||||||
RtlUtils.characterType CurRtlType = RtlUtils.isRtl(oldString.charAt(0))? RtlUtils.characterType.rtl : RtlUtils.characterType.ltr;
|
RtlUtils.characterType CurRtlType = RtlUtils.isRtl(oldString.charAt(0))? RtlUtils.characterType.rtl : RtlUtils.characterType.ltr;
|
||||||
RtlUtils.characterType PhraseRtlType = CurRtlType;
|
RtlUtils.characterType PhraseRtlType = CurRtlType;
|
||||||
|
|
||||||
char c;
|
Character c;
|
||||||
// String word = "", phrase = "", line = "";
|
// String word = "", phrase = "", line = "";
|
||||||
StringBuilder word = new StringBuilder();
|
StringBuilder word = new StringBuilder();
|
||||||
StringBuilder phrase = new StringBuilder();
|
StringBuilder phrase = new StringBuilder();
|
||||||
StringBuilder line = new StringBuilder();
|
StringBuilder line = new StringBuilder();
|
||||||
String phraseString = "";
|
String phraseString = "";
|
||||||
|
boolean addCharToWord = false;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
c = oldString.charAt(i);
|
c = oldString.charAt(i);
|
||||||
|
addCharToWord = false;
|
||||||
Log.d("ROIGR", "char: " + c + " :" + Character.getDirectionality(c));
|
Log.d("ROIGR", "char: " + c + " :" + Character.getDirectionality(c));
|
||||||
// Log.d("ROIGR", "hex : " + (int)c);
|
// Log.d("ROIGR", "hex : " + (int)c);
|
||||||
|
|
||||||
@ -216,51 +216,70 @@ public class LanguageUtils {
|
|||||||
CurRtlType = RtlUtils.characterType.rtl;
|
CurRtlType = RtlUtils.characterType.rtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((CurRtlType == PhraseRtlType) || RtlUtils.isPunctuations(c)) {
|
if ((CurRtlType == PhraseRtlType) && !(RtlUtils.isSpaceSign(c) || RtlUtils.isEndLineSign(c))){
|
||||||
|
Log.d("ROIGR", "add: " + c + " to: " + word);
|
||||||
word.append(c);
|
word.append(c);
|
||||||
} else {
|
addCharToWord = true;
|
||||||
if (RtlUtils.isSpaceSign(c)){
|
if (i < length - 1) {
|
||||||
word.append(c);
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (line.length() + phrase.length() + word.length() < line_max_size) {
|
|
||||||
phrase.append(word);
|
|
||||||
word.setLength(0);
|
do {
|
||||||
continue;
|
if (line.length() + phrase.length() + word.length() < line_max_size) {
|
||||||
|
if (RtlUtils.isSpaceSign(c)) {
|
||||||
|
word.append(c);
|
||||||
|
addCharToWord = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
phrase.append(word);
|
||||||
|
word.setLength(0);
|
||||||
|
|
||||||
|
if (RtlUtils.isSpaceSign(c)) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//we either move from rtl to ltr or vice versa or word should move to new line
|
|
||||||
|
|
||||||
phraseString = phrase.toString();
|
phraseString = phrase.toString();
|
||||||
|
Log.d("ROIGR", "phrase: |" + phraseString + "|");
|
||||||
if (PhraseRtlType == RtlUtils.characterType.rtl) {
|
if (PhraseRtlType == RtlUtils.characterType.rtl) {
|
||||||
if(RtlUtils.contextualSupport()){
|
if (RtlUtils.contextualSupport()) {
|
||||||
phraseString = RtlUtils.converToContextual(phraseString);
|
phraseString = RtlUtils.converToContextual(phraseString);
|
||||||
}
|
}
|
||||||
phraseString = RtlUtils.reverse(phraseString);
|
phraseString = RtlUtils.reverse(phraseString);
|
||||||
}
|
}
|
||||||
line.insert(0, phraseString);
|
|
||||||
|
line.insert(0, RtlUtils.fixWhitespace(phraseString));
|
||||||
|
Log.d("ROIGR", "line now: |" + line + "|");
|
||||||
phrase.setLength(0);
|
phrase.setLength(0);
|
||||||
|
|
||||||
Log.d("ROIGR", "word: |" + word + "|");
|
if (word.length() > 0){
|
||||||
if (line.length() + word.length() > line_max_size) {
|
|
||||||
line.append('\n');
|
line.append('\n');
|
||||||
lines.add(line.toString());
|
} else if (RtlUtils.isEndLineSign(c)) {
|
||||||
Log.d("ROIGR", "line: |" + line + "|");
|
line.append(c);
|
||||||
line.setLength(0);
|
} else if (!addCharToWord) {
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (RtlUtils.isEndLineSign(c)) {
|
|
||||||
lines.add(line);
|
|
||||||
Log.d("ROIGR", "line: |" + line + "|");
|
|
||||||
line = "";
|
|
||||||
}
|
|
||||||
if (!RtlUtils.isSpaceSign(c)){
|
|
||||||
word.append(c);
|
word.append(c);
|
||||||
|
if (i == length - 1){
|
||||||
|
addCharToWord = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
PhraseRtlType = PhraseRtlType == RtlUtils.characterType.rtl ? RtlUtils.characterType.ltr : RtlUtils.characterType.rtl;
|
PhraseRtlType = PhraseRtlType == RtlUtils.characterType.rtl ? RtlUtils.characterType.ltr : RtlUtils.characterType.rtl;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
lines.add(line.toString());
|
||||||
|
Log.d("ROIGR", "line: |" + line + "|");
|
||||||
|
line.setLength(0);
|
||||||
|
|
||||||
|
if (word.length() == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.add(line.toString());
|
lines.add(line.toString());
|
||||||
|
@ -20,7 +20,7 @@ class RtlUtils {
|
|||||||
space,
|
space,
|
||||||
}
|
}
|
||||||
|
|
||||||
public static characterType getCharacterType(char c){
|
public static characterType getCharacterType(Character c){
|
||||||
characterType type;
|
characterType type;
|
||||||
switch (Character.getDirectionality(c)) {
|
switch (Character.getDirectionality(c)) {
|
||||||
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
|
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
|
||||||
@ -67,150 +67,60 @@ class RtlUtils {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//list of unicode ranges of rtl chars
|
|
||||||
private static ArrayList<Pair<Character, Character>> hebrewRange = new ArrayList<Pair<Character, Character>>() {
|
|
||||||
{
|
|
||||||
add(new Pair<Character, Character>('\u0590', '\u05F4'));
|
|
||||||
add(new Pair<Character, Character>('\uFB1D', '\uFB4F'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//list of unicode ranges of rtl chars
|
|
||||||
private static ArrayList<Pair<Character, Character>> arabicRange = new ArrayList<Pair<Character, Character>>() {
|
|
||||||
{
|
|
||||||
add(new Pair<Character, Character>('\u0600', '\u06FF'));
|
|
||||||
add(new Pair<Character, Character>('\u0750', '\u077F'));
|
|
||||||
add(new Pair<Character, Character>('\u08A0', '\u08FF'));
|
|
||||||
add(new Pair<Character, Character>('\uFB50', '\uFDFF'));
|
|
||||||
add(new Pair<Character, Character>('\uFE70', '\uFEFF'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//list of unicode ranges of rtl chars
|
|
||||||
private static ArrayList<Pair<Character, Character>> rtlRange = new ArrayList<Pair<Character, Character>>() {
|
|
||||||
{
|
|
||||||
addAll(hebrewRange);
|
|
||||||
addAll(arabicRange);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the rtl range, otherwise false
|
* @return true if the char is in the rtl range, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isHebrew(char c){
|
static boolean isHebrew(Character c){
|
||||||
// for (Pair<Character, Character> rang: hebrewRange) {
|
|
||||||
// if (rang.first <= c && c <= rang.second) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
return getCharacterType(c) == characterType.rtl;
|
return getCharacterType(c) == characterType.rtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the rtl range, otherwise false
|
* @return true if the char is in the rtl range, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isArabic(char c){
|
static boolean isArabic(Character c){
|
||||||
// for (Pair<Character, Character> rang: arabicRange) {
|
|
||||||
// if (rang.first <= c && c <= rang.second) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
return getCharacterType(c) == characterType.rtl_arabic;
|
return getCharacterType(c) == characterType.rtl_arabic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the rtl range, otherwise false
|
* @return true if the char is in the rtl range, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isLtr(char c){
|
static boolean isLtr(Character c){
|
||||||
// for (Pair<Character, Character> rang: rtlRange) {
|
|
||||||
// if (rang.first <= c && c <= rang.second) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
return getCharacterType(c) == characterType.ltr;
|
return getCharacterType(c) == characterType.ltr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the rtl range, otherwise false
|
* @return true if the char is in the rtl range, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isRtl(char c){
|
static boolean isRtl(Character c){
|
||||||
// for (Pair<Character, Character> rang: rtlRange) {
|
|
||||||
// if (rang.first <= c && c <= rang.second) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
return (getCharacterType(c) == characterType.rtl) || (getCharacterType(c) == characterType.rtl_arabic);
|
return (getCharacterType(c) == characterType.rtl) || (getCharacterType(c) == characterType.rtl_arabic);
|
||||||
}
|
}
|
||||||
|
|
||||||
//list of unicode ranges of punctuations chars
|
|
||||||
private static ArrayList <Pair<Character, Character>> punctuationsRange = new ArrayList<Pair<Character, Character>>() {
|
|
||||||
{
|
|
||||||
add(new Pair<Character, Character>('\u0021', '\u002F'));
|
|
||||||
add(new Pair<Character, Character>('\u003A', '\u0040'));
|
|
||||||
add(new Pair<Character, Character>('\u005B', '\u0060'));
|
|
||||||
add(new Pair<Character, Character>('\u007B', '\u007E'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the punctuations range, otherwise false
|
* @return true if the char is in the punctuations range, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isPunctuations(char c){
|
static boolean isPunctuations(Character c){
|
||||||
// for (Pair<Character, Character> rang: punctuationsRange) {
|
|
||||||
// if (rang.first <= c && c <= rang.second) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
return getCharacterType(c) == characterType.punctuation;
|
return getCharacterType(c) == characterType.punctuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
//list of sign that ends a word
|
|
||||||
private static ArrayList<Character> wordEndSigns = new ArrayList<Character>() {
|
|
||||||
{
|
|
||||||
add('\0');
|
|
||||||
add('\n');
|
|
||||||
add(' ');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the end of word list, otherwise false
|
* @return true if the char is in the end of word list, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isSpaceSign(char c){
|
static boolean isSpaceSign(Character c){
|
||||||
// for (char sign: wordEndSigns){
|
|
||||||
// if (c == sign){
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return false;
|
|
||||||
return getCharacterType(c) == characterType.space;
|
return getCharacterType(c) == characterType.space;
|
||||||
}
|
}
|
||||||
|
|
||||||
//list of sign that ends a word
|
|
||||||
private static ArrayList<Character> endLineSigns = new ArrayList<Character>() {
|
|
||||||
{
|
|
||||||
add('\0');
|
|
||||||
add('\n');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the char is in the end of word list, otherwise false
|
* @return true if the char is in the end of word list, otherwise false
|
||||||
*/
|
*/
|
||||||
static boolean isEndLineSign(char c){
|
static boolean isEndLineSign(Character c){
|
||||||
// for (char sign: endLineSigns){
|
|
||||||
// if (c == sign){
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return false;
|
|
||||||
return getCharacterType(c) == characterType.lineEnd;
|
return getCharacterType(c) == characterType.lineEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +280,7 @@ class RtlUtils {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean exceptionAfterLam(char c){
|
private static boolean exceptionAfterLam(Character c){
|
||||||
switch (c){
|
switch (c){
|
||||||
case '\u0622':
|
case '\u0622':
|
||||||
case '\u0623':
|
case '\u0623':
|
||||||
@ -389,7 +299,7 @@ class RtlUtils {
|
|||||||
* @param state - the character state: beginning, middle, end or isolated
|
* @param state - the character state: beginning, middle, end or isolated
|
||||||
* @return the contextual character
|
* @return the contextual character
|
||||||
*/
|
*/
|
||||||
private static char getContextualSymbol(Character c, contextualState state) {
|
private static Character getContextualSymbol(Character c, contextualState state) {
|
||||||
Character newChar;
|
Character newChar;
|
||||||
switch (state){
|
switch (state){
|
||||||
case begin:
|
case begin:
|
||||||
@ -506,10 +416,10 @@ class RtlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remain end-of-word sign at the end
|
// remain end-of-word sign at the end
|
||||||
if (isEndLineSign(s.charAt(s.length() - 1))){
|
// if (isEndLineSign(s.charAt(s.length() - 1))){
|
||||||
isEndLine = 1;
|
// isEndLine = 1;
|
||||||
newWord[--j] = s.charAt(s.length() - 1);
|
// newWord[--j] = s.charAt(s.length() - 1);
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (int i = 0; i < s.length() - isEndLine; i++) {
|
for (int i = 0; i < s.length() - isEndLine; i++) {
|
||||||
if (directionSignsMap.containsKey(s.charAt(i))) {
|
if (directionSignsMap.containsKey(s.charAt(i))) {
|
||||||
@ -521,4 +431,14 @@ class RtlUtils {
|
|||||||
|
|
||||||
return new String(newWord);
|
return new String(newWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String fixWhitespace(String s){
|
||||||
|
int length = s.length();
|
||||||
|
|
||||||
|
if (length > 0 && isSpaceSign(s.charAt(length - 1))){
|
||||||
|
return s.charAt(length - 1) + s.substring(0, length - 1);
|
||||||
|
} else {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user