mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-15 12:17:33 +01:00
test
This commit is contained in:
parent
280a2f56e9
commit
5503c562a3
@ -18,6 +18,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.WordUtils;
|
import org.apache.commons.lang3.text.WordUtils;
|
||||||
|
|
||||||
@ -182,6 +183,8 @@ public class LanguageUtils {
|
|||||||
if (s == null || s.isEmpty()){
|
if (s == null || s.isEmpty()){
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
Log.d("ROIGR", "before: |" + org.apache.commons.lang3.StringEscapeUtils.escapeJava(s) + "|");
|
||||||
|
|
||||||
int length = s.length();
|
int length = s.length();
|
||||||
String oldString = s.substring(0, length);
|
String oldString = s.substring(0, length);
|
||||||
String newString = "";
|
String newString = "";
|
||||||
@ -191,51 +194,81 @@ public class LanguageUtils {
|
|||||||
|
|
||||||
int startPos = 0;
|
int startPos = 0;
|
||||||
int endPos = 0;
|
int endPos = 0;
|
||||||
Boolean isRtlState = RtlUtils.isRtl(oldString.charAt(0));
|
RtlUtils.characterType CurRtlType = RtlUtils.isRtl(oldString.charAt(0))? RtlUtils.characterType.rtl : RtlUtils.characterType.ltr;
|
||||||
|
RtlUtils.characterType PhraseRtlType = CurRtlType;
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
String line = "";
|
// String word = "", phrase = "", line = "";
|
||||||
|
StringBuilder word = new StringBuilder();
|
||||||
|
StringBuilder phrase = new StringBuilder();
|
||||||
|
StringBuilder line = new StringBuilder();
|
||||||
|
String phraseString = "";
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
c = oldString.charAt(i);
|
c = oldString.charAt(i);
|
||||||
if ((RtlUtils.isRtl(c) == isRtlState || RtlUtils.isPunctuations(c)) && i < length - 1) {
|
|
||||||
endPos++;
|
Log.d("ROIGR", "char: " + c + " :" + Character.getDirectionality(c));
|
||||||
|
// Log.d("ROIGR", "hex : " + (int)c);
|
||||||
|
|
||||||
|
if (RtlUtils.isLtr(c)){
|
||||||
|
CurRtlType = RtlUtils.characterType.ltr;
|
||||||
|
} else if (RtlUtils.isRtl(c)) {
|
||||||
|
CurRtlType = RtlUtils.characterType.rtl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((CurRtlType == PhraseRtlType) || RtlUtils.isPunctuations(c)) {
|
||||||
|
word.append(c);
|
||||||
} else {
|
} else {
|
||||||
String word;
|
if (RtlUtils.isSpaceSign(c)){
|
||||||
|
word.append(c);
|
||||||
|
|
||||||
if (RtlUtils.isWordEndSign(c)){
|
if (line.length() + phrase.length() + word.length() < line_max_size) {
|
||||||
endPos++;
|
phrase.append(word);
|
||||||
|
word.setLength(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == length - 1){
|
//we either move from rtl to ltr or vice versa or word should move to new line
|
||||||
endPos = length;
|
|
||||||
}
|
phraseString = phrase.toString();
|
||||||
word = oldString.substring(startPos, endPos);
|
if (PhraseRtlType == RtlUtils.characterType.rtl) {
|
||||||
if (isRtlState) {
|
|
||||||
if(RtlUtils.contextualSupport()){
|
if(RtlUtils.contextualSupport()){
|
||||||
word = RtlUtils.converToContextual(word);
|
phraseString = RtlUtils.converToContextual(phraseString);
|
||||||
}
|
}
|
||||||
word = RtlUtils.reverse(word);
|
phraseString = RtlUtils.reverse(phraseString);
|
||||||
}
|
}
|
||||||
|
line.insert(0, phraseString);
|
||||||
|
phrase.setLength(0);
|
||||||
|
|
||||||
|
Log.d("ROIGR", "word: |" + word + "|");
|
||||||
if (line.length() + word.length() > line_max_size) {
|
if (line.length() + word.length() > line_max_size) {
|
||||||
lines.add(line + "\n");
|
line.append('\n');
|
||||||
line = "";
|
lines.add(line.toString());
|
||||||
|
Log.d("ROIGR", "line: |" + line + "|");
|
||||||
|
line.setLength(0);
|
||||||
}
|
}
|
||||||
line = String.format("%s%s", word, line);
|
|
||||||
if (line.endsWith("\0") || line.endsWith("\n")) {
|
|
||||||
|
|
||||||
|
if (RtlUtils.isEndLineSign(c)) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
Log.d("ROIGR", "line: |" + line + "|");
|
||||||
line = "";
|
line = "";
|
||||||
}
|
}
|
||||||
startPos = endPos;
|
if (!RtlUtils.isSpaceSign(c)){
|
||||||
if (!RtlUtils.isWordEndSign(c)){
|
word.append(c);
|
||||||
endPos++;
|
PhraseRtlType = PhraseRtlType == RtlUtils.characterType.rtl ? RtlUtils.characterType.ltr : RtlUtils.characterType.rtl;
|
||||||
isRtlState = !isRtlState;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.add(line);
|
lines.add(line.toString());
|
||||||
|
|
||||||
newString = TextUtils.join("", lines);
|
newString = TextUtils.join("", lines);
|
||||||
|
|
||||||
|
Log.d("ROIGR", "after : |" + org.apache.commons.lang3.StringEscapeUtils.escapeJava(newString) + "|");
|
||||||
|
|
||||||
return newString;
|
return newString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,45 @@ import java.util.Map;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
|
||||||
class RtlUtils {
|
class RtlUtils {
|
||||||
|
|
||||||
|
enum characterType{
|
||||||
|
ltr,
|
||||||
|
rtl,
|
||||||
|
rtl_arabic,
|
||||||
|
punctuation,
|
||||||
|
lineEnd,
|
||||||
|
space,
|
||||||
|
}
|
||||||
|
|
||||||
|
public static characterType getCharacterType(char c){
|
||||||
|
characterType type;
|
||||||
|
switch (Character.getDirectionality(c)) {
|
||||||
|
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
|
||||||
|
type = characterType.rtl;
|
||||||
|
break;
|
||||||
|
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
|
||||||
|
type = characterType.rtl_arabic;
|
||||||
|
break;
|
||||||
|
case Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR:
|
||||||
|
case Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR:
|
||||||
|
case Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR:
|
||||||
|
case Character.DIRECTIONALITY_OTHER_NEUTRALS:
|
||||||
|
type = characterType.punctuation;
|
||||||
|
break;
|
||||||
|
case Character.DIRECTIONALITY_BOUNDARY_NEUTRAL:
|
||||||
|
case Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR:
|
||||||
|
type = characterType.lineEnd;
|
||||||
|
break;
|
||||||
|
case Character.DIRECTIONALITY_WHITESPACE:
|
||||||
|
type = characterType.space;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
type = characterType.ltr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the status of right-to-left option
|
* Checks the status of right-to-left option
|
||||||
* @return true if right-to-left option is On, and false, if Off or not exist
|
* @return true if right-to-left option is On, and false, if Off or not exist
|
||||||
@ -58,37 +97,53 @@ class RtlUtils {
|
|||||||
/**
|
/**
|
||||||
* @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(char c){
|
||||||
for (Pair<Character, Character> rang: hebrewRange) {
|
// for (Pair<Character, Character> rang: hebrewRange) {
|
||||||
if (rang.first <= c && c <= rang.second) {
|
// if (rang.first <= c && c <= rang.second) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
|
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(char c){
|
||||||
for (Pair<Character, Character> rang: arabicRange) {
|
// for (Pair<Character, Character> rang: arabicRange) {
|
||||||
if (rang.first <= c && c <= rang.second) {
|
// if (rang.first <= c && c <= rang.second) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
|
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 isRtl(char c){
|
static boolean isLtr(char c){
|
||||||
for (Pair<Character, Character> rang: rtlRange) {
|
// for (Pair<Character, Character> rang: rtlRange) {
|
||||||
if (rang.first <= c && c <= rang.second) {
|
// if (rang.first <= c && c <= rang.second) {
|
||||||
return true;
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
return getCharacterType(c) == characterType.ltr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
/**
|
||||||
|
* @return true if the char is in the rtl range, otherwise false
|
||||||
|
*/
|
||||||
|
static boolean isRtl(char 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
//list of unicode ranges of punctuations chars
|
//list of unicode ranges of punctuations chars
|
||||||
@ -104,13 +159,14 @@ class RtlUtils {
|
|||||||
/**
|
/**
|
||||||
* @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(char c){
|
||||||
for (Pair<Character, Character> rang: punctuationsRange) {
|
// for (Pair<Character, Character> rang: punctuationsRange) {
|
||||||
if (rang.first <= c && c <= rang.second) {
|
// if (rang.first <= c && c <= rang.second) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
|
return getCharacterType(c) == characterType.punctuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
//list of sign that ends a word
|
//list of sign that ends a word
|
||||||
@ -125,14 +181,15 @@ class RtlUtils {
|
|||||||
/**
|
/**
|
||||||
* @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 isWordEndSign(char c){
|
static boolean isSpaceSign(char c){
|
||||||
for (char sign: wordEndSigns){
|
// for (char sign: wordEndSigns){
|
||||||
if (c == sign){
|
// if (c == sign){
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return false;
|
// return false;
|
||||||
|
return getCharacterType(c) == characterType.space;
|
||||||
}
|
}
|
||||||
|
|
||||||
//list of sign that ends a word
|
//list of sign that ends a word
|
||||||
@ -146,14 +203,15 @@ class RtlUtils {
|
|||||||
/**
|
/**
|
||||||
* @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(char c){
|
||||||
for (char sign: endLineSigns){
|
// for (char sign: endLineSigns){
|
||||||
if (c == sign){
|
// if (c == sign){
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return false;
|
// return false;
|
||||||
|
return getCharacterType(c) == characterType.lineEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
//map from Arabian characters to their contextual form in the beginning of the word
|
//map from Arabian characters to their contextual form in the beginning of the word
|
||||||
|
Loading…
x
Reference in New Issue
Block a user