mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-09 16:17:44 +00:00
rename package
introduces weird bugs for some reason
This commit is contained in:
parent
8c40d4f3e8
commit
a91a90bfbd
312 changed files with 1620 additions and 1612 deletions
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
* modified
|
||||
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||
*/
|
||||
|
||||
package helium314.keyboard.latin.settings;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import helium314.keyboard.compat.ConfigurationCompatKt;
|
||||
import helium314.keyboard.keyboard.internal.MoreKeySpec;
|
||||
import helium314.keyboard.latin.PunctuationSuggestions;
|
||||
import helium314.keyboard.latin.R;
|
||||
import helium314.keyboard.latin.common.Constants;
|
||||
import helium314.keyboard.latin.common.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class SpacingAndPunctuations {
|
||||
private final int[] mSortedSymbolsPrecededBySpace;
|
||||
private final int[] mSortedSymbolsFollowedBySpace;
|
||||
private final int[] mSortedSymbolsClusteringTogether;
|
||||
private final int[] mSortedWordConnectors;
|
||||
private final int[] mSortedSometimesWordConnectors; // maybe rename... they are some sort of glue for words containing separators
|
||||
public final int[] mSortedWordSeparators;
|
||||
public final PunctuationSuggestions mSuggestPuncList;
|
||||
private final int mSentenceSeparator;
|
||||
private final int mAbbreviationMarker;
|
||||
private final int[] mSortedSentenceTerminators;
|
||||
public final String mSentenceSeparatorAndSpace;
|
||||
public final boolean mCurrentLanguageHasSpaces;
|
||||
public final boolean mUsesAmericanTypography;
|
||||
public final boolean mUsesGermanRules;
|
||||
|
||||
public SpacingAndPunctuations(final Resources res, final Boolean urlDetection) {
|
||||
// To be able to binary search the code point. See {@link #isUsuallyPrecededBySpace(int)}.
|
||||
mSortedSymbolsPrecededBySpace = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_preceded_by_space));
|
||||
// To be able to binary search the code point. See {@link #isUsuallyFollowedBySpace(int)}.
|
||||
mSortedSymbolsFollowedBySpace = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_followed_by_space));
|
||||
mSortedSymbolsClusteringTogether = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_clustering_together));
|
||||
// To be able to binary search the code point. See {@link #isWordConnector(int)}.
|
||||
mSortedWordConnectors = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_word_connectors));
|
||||
mSortedWordSeparators = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_word_separators));
|
||||
mSortedSentenceTerminators = StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_sentence_terminators));
|
||||
mSentenceSeparator = res.getInteger(R.integer.sentence_separator);
|
||||
mAbbreviationMarker = res.getInteger(R.integer.abbreviation_marker);
|
||||
mSentenceSeparatorAndSpace = new String(new int[] {
|
||||
mSentenceSeparator, Constants.CODE_SPACE }, 0, 2);
|
||||
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
|
||||
// make it empty if language doesn't have spaces, to avoid weird glitches
|
||||
mSortedSometimesWordConnectors = (urlDetection && mCurrentLanguageHasSpaces) ? StringUtils.toSortedCodePointArray(res.getString(R.string.symbols_sometimes_word_connectors)) : new int[0];
|
||||
final Locale locale = ConfigurationCompatKt.locale(res.getConfiguration());
|
||||
// Heuristic: we use American Typography rules because it's the most common rules for all
|
||||
// English variants. German rules (not "German typography") also have small gotchas.
|
||||
mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage());
|
||||
mUsesGermanRules = Locale.GERMAN.getLanguage().equals(locale.getLanguage());
|
||||
final String[] suggestPuncsSpec = MoreKeySpec.splitKeySpecs(
|
||||
res.getString(R.string.suggested_punctuations));
|
||||
mSuggestPuncList = PunctuationSuggestions.newPunctuationSuggestions(suggestPuncsSpec);
|
||||
}
|
||||
|
||||
public boolean isWordSeparator(final int code) {
|
||||
return Arrays.binarySearch(mSortedWordSeparators, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean isWordConnector(final int code) {
|
||||
return Arrays.binarySearch(mSortedWordConnectors, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean isSometimesWordConnector(final int code) {
|
||||
return Arrays.binarySearch(mSortedSometimesWordConnectors, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean containsSometimesWordConnector(final CharSequence word) {
|
||||
// todo: this only works if all mSortedSometimesWordConnectors are simple chars
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
if (isSometimesWordConnector(word.charAt(i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isWordCodePoint(final int code) {
|
||||
return Character.isLetter(code) || isWordConnector(code);
|
||||
}
|
||||
|
||||
public boolean isUsuallyPrecededBySpace(final int code) {
|
||||
return Arrays.binarySearch(mSortedSymbolsPrecededBySpace, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean isUsuallyFollowedBySpace(final int code) {
|
||||
return Arrays.binarySearch(mSortedSymbolsFollowedBySpace, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean isClusteringSymbol(final int code) {
|
||||
return Arrays.binarySearch(mSortedSymbolsClusteringTogether, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean isSentenceTerminator(final int code) {
|
||||
return Arrays.binarySearch(mSortedSentenceTerminators, code) >= 0;
|
||||
}
|
||||
|
||||
public boolean isAbbreviationMarker(final int code) {
|
||||
return code == mAbbreviationMarker;
|
||||
}
|
||||
|
||||
public boolean isSentenceSeparator(final int code) {
|
||||
return code == mSentenceSeparator;
|
||||
}
|
||||
|
||||
public String dump() {
|
||||
return "mSortedSymbolsPrecededBySpace = " +
|
||||
"" + Arrays.toString(mSortedSymbolsPrecededBySpace) +
|
||||
"\n mSortedSymbolsFollowedBySpace = " +
|
||||
"" + Arrays.toString(mSortedSymbolsFollowedBySpace) +
|
||||
"\n mSortedWordConnectors = " +
|
||||
"" + Arrays.toString(mSortedWordConnectors) +
|
||||
"\n mSortedWordSeparators = " +
|
||||
"" + Arrays.toString(mSortedWordSeparators) +
|
||||
"\n mSuggestPuncList = " +
|
||||
"" + mSuggestPuncList +
|
||||
"\n mSentenceSeparator = " +
|
||||
"" + mSentenceSeparator +
|
||||
"\n mSentenceSeparatorAndSpace = " +
|
||||
"" + mSentenceSeparatorAndSpace +
|
||||
"\n mCurrentLanguageHasSpaces = " +
|
||||
"" + mCurrentLanguageHasSpaces +
|
||||
"\n mUsesAmericanTypography = " +
|
||||
"" + mUsesAmericanTypography +
|
||||
"\n mUsesGermanRules = " +
|
||||
"" + mUsesGermanRules;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue