Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
18184eac
Commit
18184eac
authored
11 years ago
by
Tadashi G. Takaoka
Browse files
Options
Downloads
Patches
Plain Diff
Support regular expression for condition pattern
Bug: 8556975 Change-Id: Iffc53d6a40dd77860434c5f7f4f59af5cd1ba92b
parent
ec83457d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/latin/ResourceUtils.java
+6
-6
6 additions, 6 deletions
java/src/com/android/inputmethod/latin/ResourceUtils.java
tests/src/com/android/inputmethod/latin/ResourceUtilsTests.java
+36
-0
36 additions, 0 deletions
...src/com/android/inputmethod/latin/ResourceUtilsTests.java
with
42 additions
and
6 deletions
java/src/com/android/inputmethod/latin/ResourceUtils.java
+
6
−
6
View file @
18184eac
...
...
@@ -103,12 +103,12 @@ public final class ResourceUtils {
/**
* Find the condition that fulfills specified key value pairs from an array of
* "condition,constant", and return the corresponding string constant. A condition is
* "pattern1[:pattern2...] (or an empty string for the default). A pattern is
"key=value"
* string. The condition matches only if all patterns of the condition
are true for the
* specified key value pairs.
* "pattern1[:pattern2...] (or an empty string for the default). A pattern is
*
"key=regexp_value"
string. The condition matches only if all patterns of the condition
*
are true for the
specified key value pairs.
*
* For example, "condition,constant" has the following format.
* (See {@link ResourceUtilsTests#testFindConstantForKeyValuePairs
Combined
()})
* (See {@link ResourceUtilsTests#testFindConstantForKeyValuePairs
Regexp
()})
* - HARDWARE=mako,constantForNexus4
* - MODEL=Nexus 4:MANUFACTURER=LGE,constantForNexus4
* - ,defaultConstant
...
...
@@ -156,8 +156,8 @@ public final class ResourceUtils {
if
(
value
==
null
)
{
throw
new
RuntimeException
(
"Found unknown key: "
+
condition
);
}
final
String
patternValue
=
pattern
.
substring
(
posEqual
+
1
);
if
(!
value
.
equal
s
(
patternValue
))
{
final
String
pattern
Regexp
Value
=
pattern
.
substring
(
posEqual
+
1
);
if
(!
value
.
matche
s
(
pattern
Regexp
Value
))
{
return
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/com/android/inputmethod/latin/ResourceUtilsTests.java
+
36
−
0
View file @
18184eac
...
...
@@ -137,4 +137,40 @@ public class ResourceUtilsTests extends AndroidTestCase {
assertNull
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
));
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
failArray
),
"0.2"
);
}
public
void
testFindConstantForKeyValuePairsRegexp
()
{
final
String
HARDWARE_KEY
=
"HARDWARE"
;
final
String
MODEL_KEY
=
"MODEL"
;
final
String
MANUFACTURER_KEY
=
"MANUFACTURER"
;
final
String
[]
array
=
{
",defaultValue"
,
"HARDWARE=grouper|tilapia:MANUFACTURER=asus,0.3"
,
"HARDWARE=[mM][aA][kK][oO]:MODEL=Nexus 4,0.4"
,
"HARDWARE=manta.*:MODEL=Nexus 10:MANUFACTURER=samsung,0.2"
};
final
HashMap
<
String
,
String
>
keyValues
=
CollectionUtils
.
newHashMap
();
keyValues
.
put
(
HARDWARE_KEY
,
"grouper"
);
keyValues
.
put
(
MODEL_KEY
,
"Nexus 7"
);
keyValues
.
put
(
MANUFACTURER_KEY
,
"asus"
);
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
),
"0.3"
);
keyValues
.
put
(
HARDWARE_KEY
,
"tilapia"
);
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
),
"0.3"
);
keyValues
.
clear
();
keyValues
.
put
(
HARDWARE_KEY
,
"mako"
);
keyValues
.
put
(
MODEL_KEY
,
"Nexus 4"
);
keyValues
.
put
(
MANUFACTURER_KEY
,
"LGE"
);
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
),
"0.4"
);
keyValues
.
put
(
HARDWARE_KEY
,
"MAKO"
);
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
),
"0.4"
);
keyValues
.
clear
();
keyValues
.
put
(
HARDWARE_KEY
,
"manta"
);
keyValues
.
put
(
MODEL_KEY
,
"Nexus 10"
);
keyValues
.
put
(
MANUFACTURER_KEY
,
"samsung"
);
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
),
"0.2"
);
keyValues
.
put
(
HARDWARE_KEY
,
"mantaray"
);
assertEquals
(
ResourceUtils
.
findConstantForKeyValuePairs
(
keyValues
,
array
),
"0.2"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment