Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84a3047e authored by Jean Chalard's avatar Jean Chalard
Browse files

Fix build.

Change-Id: I6d0b572190080e58e95f72856ad39e72a49537b7
parent ee35e69e
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -20,13 +20,16 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.Log;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.AssetFileAddress;
import com.android.inputmethod.latin.BinaryDictionaryGetter;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.makedict.BinaryDictIOUtils;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;

import java.io.File;
import java.util.ArrayList;
@@ -364,4 +367,29 @@ public class DictionaryInfoUtils {

        return dictList;
    }

    @UsedForTesting
    public static boolean looksValidForDictionaryInsertion(final CharSequence text,
            final SpacingAndPunctuations spacingAndPunctuations) {
        if (TextUtils.isEmpty(text)) return false;
        final int length = text.length();
        int i = 0;
        int digitCount = 0;
        while (i < length) {
            final int codePoint = Character.codePointAt(text, i);
            final int charCount = Character.charCount(codePoint);
            i += charCount;
            if (Character.isDigit(codePoint)) {
                // Count digits: see below
                digitCount += charCount;
                continue;
            }
            if (!spacingAndPunctuations.isWordCodePoint(codePoint)) return false;
        }
        // We reject strings entirely comprised of digits to avoid using PIN codes or credit
        // card numbers. It would come in handy for word prediction though; a good example is
        // when writing one's address where the street number is usually quite discriminative,
        // as well as the postal code.
        return digitCount < length;
    }
}
+0 −26
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.text.TextUtils;

import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;

import java.util.ArrayList;
import java.util.Locale;
@@ -265,31 +264,6 @@ public final class StringUtils {
        return true;
    }

    @UsedForTesting
    public static boolean looksValidForDictionaryInsertion(final CharSequence text,
            final SpacingAndPunctuations spacingAndPunctuations) {
        if (TextUtils.isEmpty(text)) return false;
        final int length = text.length();
        int i = 0;
        int digitCount = 0;
        while (i < length) {
            final int codePoint = Character.codePointAt(text, i);
            final int charCount = Character.charCount(codePoint);
            i += charCount;
            if (Character.isDigit(codePoint)) {
                // Count digits: see below
                digitCount += charCount;
                continue;
            }
            if (!spacingAndPunctuations.isWordCodePoint(codePoint)) return false;
        }
        // We reject strings entirely comprised of digits to avoid using PIN codes or credit
        // card numbers. It would come in handy for word prediction though; a good example is
        // when writing one's address where the street number is usually quite discriminative,
        // as well as the postal code.
        return digitCount < length;
    }

    public static boolean isIdenticalAfterCapitalizeEachWord(final String text,
            final String separators) {
        boolean needCapsNext = true;
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.latin.utils;

import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.inputmethod.latin.settings.SpacingAndPunctuations;

import java.util.Locale;

@SmallTest
public class DictionaryInfoUtilsTests extends AndroidTestCase {
    public void testLooksValidForDictionaryInsertion() {
        final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
            @Override
            protected SpacingAndPunctuations job(final Resources res) {
                return new SpacingAndPunctuations(res);
            }
        };
        final Resources res = getContext().getResources();
        final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
        assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("aochaueo", sp));
        assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("", sp));
        assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("ao-ch'aueo", sp));
        assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("2908743256", sp));
        assertTrue(DictionaryInfoUtils.looksValidForDictionaryInsertion("31aochaueo", sp));
        assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("akeo  raeoch oerch .",
                sp));
        assertFalse(DictionaryInfoUtils.looksValidForDictionaryInsertion("!!!", sp));
    }
}
+0 −21
Original line number Diff line number Diff line
@@ -16,12 +16,9 @@

package com.android.inputmethod.latin.utils;

import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.inputmethod.latin.settings.SpacingAndPunctuations;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@@ -209,24 +206,6 @@ public class StringAndJsonUtilsTests extends AndroidTestCase {
        assertTrue(StringUtils.isIdenticalAfterDowncase(""));
    }

    public void testLooksValidForDictionaryInsertion() {
        final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
            @Override
            protected SpacingAndPunctuations job(final Resources res) {
                return new SpacingAndPunctuations(res);
            }
        };
        final Resources res = getContext().getResources();
        final SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
        assertTrue(StringUtils.looksValidForDictionaryInsertion("aochaueo", sp));
        assertFalse(StringUtils.looksValidForDictionaryInsertion("", sp));
        assertTrue(StringUtils.looksValidForDictionaryInsertion("ao-ch'aueo", sp));
        assertFalse(StringUtils.looksValidForDictionaryInsertion("2908743256", sp));
        assertTrue(StringUtils.looksValidForDictionaryInsertion("31aochaueo", sp));
        assertFalse(StringUtils.looksValidForDictionaryInsertion("akeo  raeoch oerch .", sp));
        assertFalse(StringUtils.looksValidForDictionaryInsertion("!!!", sp));
    }

    private static void checkCapitalize(final String src, final String dst, final String separators,
            final Locale locale) {
        assertEquals(dst, StringUtils.capitalizeEachWord(src, separators, locale));
+0 −23
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.inputmethod.latin.settings;

public class SettingsValues {
    public boolean isWordCodePoint(final int code) {
        return Character.isLetter(code);
    }
}