From f3daab445e2e3ee88f8b94c6b46d380777035051 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Tue, 19 Sep 2023 18:39:05 -0500 Subject: [PATCH] CLDR-17078 rename ldmlKeyboard.dtd to ldmlKeyboard3.dtd (#3274) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CLDR-17078 rename ldmlKeyboard.dtd to ldmlKeyboard3.dtd - also rename root element to , etc - also, restore prior ldmlKeyboard.dtd and ldmlPlatform.dtd but marked deprecated - test/tool fixes as needed - CLDR APIs won't attempt to read prior keyboard files - remove prior-version Keyboard code Co-authored-by: Jan Kučera <10546952+miloush@users.noreply.github.com> * CLDR-17078 keyboard to keyboard3: test fix --------- Co-authored-by: Jan Kučera <10546952+miloush@users.noreply.github.com> --- .../supplemental/attributeValueValidity.xml | 18 +- docs/ldml/tr35-keyboards.md | 108 +- keyboards/3.0/fr-t-k0-azerty.xml | 6 +- keyboards/3.0/ja-Latn.xml | 6 +- keyboards/3.0/mt-t-k0-47key.xml | 6 +- keyboards/3.0/mt.xml | 6 +- keyboards/3.0/pt-t-k0-abnt2.xml | 6 +- keyboards/dtd/ldmlKeyboard.dtd | 270 ++-- keyboards/dtd/ldmlKeyboard3.dtd | 266 ++++ .../{ldmlKeyboard.xsd => ldmlKeyboard3.xsd} | 4 +- ...KeyboardTest.dtd => ldmlKeyboardTest3.dtd} | 4 +- ...KeyboardTest.xsd => ldmlKeyboardTest3.xsd} | 2 +- keyboards/dtd/ldmlPlatform.dtd | 23 + keyboards/import/keys-Latn-implied.xml | 2 +- keyboards/import/keys-Zyyy-currency.xml | 2 +- keyboards/import/keys-Zyyy-punctuation.xml | 2 +- keyboards/test/fr-t-k0-azerty-test.xml | 6 +- keyboards/test/ja-Latn-test.xml | 6 +- keyboards/test/pt-t-k0-abnt2-test.xml | 6 +- .../java/org/unicode/cldr/draft/Keyboard.java | 756 ----------- .../cldr/draft/KeyboardModifierSet.java | 289 ----- .../cldr/draft/keyboard/CharacterMap.java | 109 -- .../draft/keyboard/IsoLayoutPosition.java | 140 --- .../unicode/cldr/draft/keyboard/KeyMap.java | 85 -- .../unicode/cldr/draft/keyboard/Keyboard.java | 104 -- .../cldr/draft/keyboard/KeyboardBuilder.java | 128 -- .../cldr/draft/keyboard/KeyboardId.java | 174 --- .../cldr/draft/keyboard/KeyboardIdMap.java | 82 -- .../cldr/draft/keyboard/KeyboardSettings.java | 119 -- .../cldr/draft/keyboard/KeyboardTool.java | 109 -- .../cldr/draft/keyboard/KeycodeMap.java | 73 -- .../cldr/draft/keyboard/ModifierKey.java | 136 -- .../keyboard/ModifierKeyCombination.java | 200 --- .../keyboard/ModifierKeyCombinationSet.java | 108 -- .../draft/keyboard/ModifierKeySimplifier.java | 457 ------- .../cldr/draft/keyboard/Transform.java | 74 -- .../draft/keyboard/osx/KeylayoutParser.java | 219 ---- .../draft/keyboard/osx/TransformTree.java | 3 - .../draft/keyboard/out/KeyboardToXml.java | 208 --- .../draft/keyboard/out/KeycodeMapToXml.java | 43 - .../cldr/draft/keyboard/out/XmlWriter.java | 122 -- .../draft/keyboard/test/CharacterMapTest.java | 59 - .../keyboard/test/IsoLayoutPositionTest.java | 57 - .../cldr/draft/keyboard/test/KeyMapTest.java | 120 -- .../draft/keyboard/test/KeyboardIdTest.java | 50 - .../keyboard/test/KeyboardSettingsTest.java | 50 - .../draft/keyboard/test/KeyboardTest.java | 209 ---- .../draft/keyboard/test/KeycodeMapTest.java | 34 - .../test/ModifierKeyCombinationSetTest.java | 290 ----- .../test/ModifierKeyCombinationTest.java | 324 ----- .../test/ModifierKeySimplifierTest.java | 455 ------- .../draft/keyboard/test/ModifierKeyTest.java | 44 - .../cldr/draft/keyboard/test/RunTests.java | 26 - .../draft/keyboard/test/TransformTest.java | 29 - .../keyboard/test/windows/KlcParserTest.java | 18 - .../draft/keyboard/windows/KlcParser.java | 369 ------ .../org/unicode/cldr/tool/ChartDtdDelta.java | 2 +- .../unicode/cldr/tool/GenerateAllCharts.java | 3 - .../unicode/cldr/tool/KeyboardFlatten.java | 2 +- .../org/unicode/cldr/tool/KeymanCheck.java | 199 --- .../org/unicode/cldr/tool/ShowDtdDiffs.java | 2 +- .../org/unicode/cldr/tool/ShowKeyboards.java | 1114 ----------------- .../java/org/unicode/cldr/util/CLDRFile.java | 2 +- .../java/org/unicode/cldr/util/DtdData.java | 2 +- .../java/org/unicode/cldr/util/DtdType.java | 38 +- .../cldr/util/ElementAttributeInfo.java | 8 +- .../cldr/util/SupplementalDataInfo.java | 2 +- .../org/unicode/cldr/util/XPathParts.java | 2 +- .../cldr/draft/keyboard/osx/osx-keycodes.csv | 53 - .../cldr/draft/keyboard/osx/osx-locales.csv | 134 -- .../keyboard/test/windows/test_layout.txt | 41 - .../keyboard/windows/windows-keycodes.csv | 51 - .../keyboard/windows/windows-locales.csv | 208 --- .../cldr/unittest/TestAttributeValues.java | 4 +- .../org/unicode/cldr/unittest/TestBasic.java | 3 +- .../cldr/unittest/TestComparisonBuilder.java | 2 +- .../unicode/cldr/unittest/TestDtdData.java | 14 +- .../unicode/cldr/unittest/TestKeyboard.java | 188 --- .../unittest/TestKeyboardModifierSet.java | 109 -- .../unicode/cldr/unittest/TestPathHeader.java | 4 +- .../org/unicode/cldr/unittest/TestPaths.java | 2 +- .../KeyboardFlatten/broken-import-missing.xml | 6 +- .../broken-import-unknownbase.xml | 6 +- .../broken-import-unknownver.xml | 6 +- .../broken-import-wrongparent.xml | 6 +- 85 files changed, 539 insertions(+), 8295 deletions(-) create mode 100644 keyboards/dtd/ldmlKeyboard3.dtd rename keyboards/dtd/{ldmlKeyboard.xsd => ldmlKeyboard3.xsd} (99%) rename keyboards/dtd/{ldmlKeyboardTest.dtd => ldmlKeyboardTest3.dtd} (95%) rename keyboards/dtd/{ldmlKeyboardTest.xsd => ldmlKeyboardTest3.xsd} (99%) create mode 100644 keyboards/dtd/ldmlPlatform.dtd delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/Keyboard.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/KeyboardModifierSet.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Transform.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/KeylayoutParser.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/TransformTree.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeyboardToXml.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeycodeMapToXml.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/XmlWriter.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/CharacterMapTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/IsoLayoutPositionTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyMapTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardIdTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardSettingsTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeycodeMapTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationSetTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeySimplifierTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/RunTests.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/TransformTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/windows/KlcParserTest.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/windows/KlcParser.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeymanCheck.java delete mode 100644 tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowKeyboards.java delete mode 100644 tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-keycodes.csv delete mode 100644 tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-locales.csv delete mode 100644 tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/test/windows/test_layout.txt delete mode 100644 tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-keycodes.csv delete mode 100644 tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-locales.csv delete mode 100644 tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboard.java delete mode 100644 tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboardModifierSet.java diff --git a/common/supplemental/attributeValueValidity.xml b/common/supplemental/attributeValueValidity.xml index c35eb372c0a..33e9ee45a3c 100644 --- a/common/supplemental/attributeValueValidity.xml +++ b/common/supplemental/attributeValueValidity.xml @@ -449,15 +449,15 @@ pluralOrdinal pluralOrdinal pluralOrdinal - - - - - - simple - 28 - + + + + + + simple + 28 + diff --git a/docs/ldml/tr35-keyboards.md b/docs/ldml/tr35-keyboards.md index f94c9fe0d60..ea66b4c94b5 100644 --- a/docs/ldml/tr35-keyboards.md +++ b/docs/ldml/tr35-keyboards.md @@ -297,13 +297,13 @@ Attribute values escaped in this manner are annotated with the ` - + - + ``` * * * @@ -450,7 +450,7 @@ Element used to keep track of the source data version. > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: _none_ > @@ -469,11 +469,11 @@ _Attribute:_ `cldrVersion` (fixed by DTD) **Example** ```xml - + … - + ``` * * * @@ -493,7 +493,7 @@ Element containing informative properties about the layout, for displaying in us > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: _none_ > @@ -542,7 +542,7 @@ These names are not currently localized. > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [name](#Element_name), [_special_](tr35.md#special) > @@ -578,13 +578,13 @@ _Attribute:_ `value` (required) **Example** ```xml - + … - + ``` * * * @@ -601,7 +601,7 @@ An element used to keep track of layout specific settings. This element may or m > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: _none_ > @@ -619,11 +619,11 @@ If this attribute is present, it must have a value of omit. **Example** ```xml - + … - + ``` Indicates that: @@ -657,7 +657,7 @@ There is only a single `` element in each layout. > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > Children: [key](#Element_key), [flicks](#Element_flicks) > Occurrence: optional, single > @@ -867,11 +867,11 @@ These implied keys are available in a data file named `keyboards/import/keys-Lat Thus, the implied keys behave as if the following import were present. ```xml - + - + ``` **Note:** All implied keys may be overridden, as with all other imported data items. See the [`import`](#Element_import) element for more details. @@ -964,7 +964,7 @@ If two identical elements are defined, the later element will take precedence, t ``` > > -> Parents: [displays](#Element_displays), [keyboard](#Element_keyboard), [keys](#Element_keys), [layers](#Element_layers), [names](#Element_names), [reorders](#Element_reorders), [transformGroup](#Element_transformGroup), [transforms](#Element_transforms), [variables](#Element_variables), [vkeys](#Element_vkeys) +> Parents: [displays](#Element_displays), [keyboard3](#Element_keyboard), [keys](#Element_keys), [layers](#Element_layers), [names](#Element_names), [reorders](#Element_reorders), [transformGroup](#Element_transformGroup), [transforms](#Element_transforms), [variables](#Element_variables), [vkeys](#Element_vkeys) > > Children: _none_ > @@ -999,7 +999,7 @@ _Attribute:_ `path` (required) - + @@ -1069,7 +1069,7 @@ See [``](#Element_displayOptions). > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [display](#Element_display), [displayOptions](#Element_displayOptions), [_special_](tr35.md#special) > @@ -1122,7 +1122,7 @@ This attribute may be escaped with `\u` notation, see [Escaping](#Escaping). **Example** ```xml - + @@ -1133,7 +1133,7 @@ This attribute may be escaped with `\u` notation, see [Escaping](#Escaping). - + ``` To allow `displays` elements to be shared across keyboards, there is no requirement that `@to` in a `display` element matches any `@to`/`@id` in any `keys/key` element in the keyboard description. @@ -1186,7 +1186,7 @@ This element represents a set of `form` elements which define the layout of a pa > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [import](#Element_import), [form](#Element_form), [_special_](tr35.md#special) > @@ -1249,11 +1249,11 @@ _Attribute:_ `id` (required) There is an implied set of `
` elements corresponding to the default forms, thus implementations must behave as if there was the following import statement: ```xml - + - + ``` Here is a summary of the implied form elements. Keyboards included in the CLDR Repository must only use these `form=` values and may not override the scanCodes. @@ -1299,7 +1299,7 @@ hardware or touch layout. > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [import](#Element_import), [layer](#Element_layer), [_special_](tr35.md#special) > @@ -1353,7 +1353,7 @@ A `layer` element describes the configuration of keys on a particular layer of a > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [row](#Element_row), [_special_](tr35.md#special) > @@ -1452,7 +1452,7 @@ On some architectures, applications may directly interact with keys before they > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [import](#Element_import), [_special_](tr35.md#special), [vkey](#Element_vkey) > @@ -1499,14 +1499,14 @@ _Attribute:_ `to` (required) This example shows some of the mappings for a French keyboard layout: ```xml - + - + ``` * * * @@ -1515,7 +1515,7 @@ This example shows some of the mappings for a French keyboard layout: > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [import](#Element_import), [_special_](tr35.md#special), [string](#element-string), [set](#element-set), [unicodeSet](#element-unicodeSet) > @@ -1718,7 +1718,7 @@ There can be multiple `` elements, but only one for each `type`. > > -> Parents: [keyboard](#Element_keyboard) +> Parents: [keyboard3](#Element_keyboard) > > Children: [import](#Element_import), [_special_](tr35.md#special), [transformGroup](#Element_transformGroup) > @@ -2555,32 +2555,32 @@ The following are the design principles for the IDs. ```xml - + ``` ```xml - + ``` ```xml - + - + ``` ```xml - + - + ``` * * * @@ -2662,7 +2662,7 @@ Footnotes: Keyboard Test Data allows the keyboard author to provide regression test data to validate the repertoire and behavior of a keyboard. Tooling can run these regression tests against an implementation, and can also be used as part of the development cycle to validate that keyboard changes do not deviate from expected behavior. In the interest of complete coverage, tooling could also indicate whether all keys and gestures in a layout are exercised by the test data. -Test data files have a separate DTD, named `ldmlKeyboardTest.dtd`. Note that multiple test data files can refer to the same keyboard. Test files should be named similarly to the keyboards which they test, such as `fr_test.xml` to test `fr.xml`. +Test data files have a separate DTD, named `ldmlKeyboardTest3.dtd`. Note that multiple test data files can refer to the same keyboard. Test files should be named similarly to the keyboards which they test, such as `fr_test.xml` to test `fr.xml`. Sample test data files are located in the `keyboards/test` subdirectory. @@ -2672,7 +2672,7 @@ The following describes the structure of a keyboard test file. ```xml - + ``` The top level element is named `keyboardTest`. @@ -2688,14 +2688,14 @@ This is the top level element. _Attribute:_ `conformsTo` (required) -The `conformsTo` attribute here is the same as on the [``](#Element_Keyboard) element. +The `conformsTo` attribute here is the same as on the [``](#Element_Keyboard) element. ```xml - - + + … - + ``` ### Test Element: info diff --git a/keyboards/3.0/fr-t-k0-azerty.xml b/keyboards/3.0/fr-t-k0-azerty.xml index b7162f6e01b..4ccedc062f3 100644 --- a/keyboards/3.0/fr-t-k0-azerty.xml +++ b/keyboards/3.0/fr-t-k0-azerty.xml @@ -1,5 +1,5 @@ - + - + @@ -209,4 +209,4 @@ - + diff --git a/keyboards/3.0/ja-Latn.xml b/keyboards/3.0/ja-Latn.xml index a381fca2309..8b5b845bf25 100644 --- a/keyboards/3.0/ja-Latn.xml +++ b/keyboards/3.0/ja-Latn.xml @@ -1,6 +1,6 @@ - - + + @@ -31,4 +31,4 @@ - + diff --git a/keyboards/3.0/mt-t-k0-47key.xml b/keyboards/3.0/mt-t-k0-47key.xml index 99a6b39d7b3..02db33accc6 100644 --- a/keyboards/3.0/mt-t-k0-47key.xml +++ b/keyboards/3.0/mt-t-k0-47key.xml @@ -1,6 +1,6 @@ - - + + @@ -81,4 +81,4 @@ - + diff --git a/keyboards/3.0/mt.xml b/keyboards/3.0/mt.xml index d52184fcc1d..a5a415d8745 100644 --- a/keyboards/3.0/mt.xml +++ b/keyboards/3.0/mt.xml @@ -1,12 +1,12 @@ - + - + @@ -84,4 +84,4 @@ - + diff --git a/keyboards/3.0/pt-t-k0-abnt2.xml b/keyboards/3.0/pt-t-k0-abnt2.xml index ddd35bcd684..6de82a8f9d3 100644 --- a/keyboards/3.0/pt-t-k0-abnt2.xml +++ b/keyboards/3.0/pt-t-k0-abnt2.xml @@ -1,6 +1,6 @@ - - + + @@ -62,4 +62,4 @@ - + diff --git a/keyboards/dtd/ldmlKeyboard.dtd b/keyboards/dtd/ldmlKeyboard.dtd index 42cf438c3be..49eaef96201 100644 --- a/keyboards/dtd/ldmlKeyboard.dtd +++ b/keyboards/dtd/ldmlKeyboard.dtd @@ -4,262 +4,162 @@ For terms of use, see http://www.unicode.org/copyright.html SPDX-License-Identifier: Unicode-DFS-2016 CLDR data files are interpreted according to the LDML specification (http://unicode.org/reports/tr35/) --> - -The CLDR Keyboard Subcommittee is currently developing major changes to the CLDR keyboard specification. -Please view the subcommittee page for the most recent information. - --> - - - + + - - - - - - - - - - - - - - - - - - - + + - - - + + - - - + + + + + + + + + + + - - - - - - + - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + - - - - - - - + + - - + + + - - - - - + + + + - - + - - - - - - - - - - - - - + + - - - - + - - + + - - - - + + + - - - - - - - - - - - + - - - - + + + - - - - - - - - - - - - - + + - - - - - - - - + - - - - - + + + - - - - - - - + - - - - - - - + + + - - - - + + + + + + + - - + + + - + - - - + + - + + + + - - - - - - - - + - - - - + - - + + + + + + + + + + + + diff --git a/keyboards/dtd/ldmlKeyboard3.dtd b/keyboards/dtd/ldmlKeyboard3.dtd new file mode 100644 index 00000000000..25d03368f86 --- /dev/null +++ b/keyboards/dtd/ldmlKeyboard3.dtd @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/keyboards/dtd/ldmlKeyboard.xsd b/keyboards/dtd/ldmlKeyboard3.xsd similarity index 99% rename from keyboards/dtd/ldmlKeyboard.xsd rename to keyboards/dtd/ldmlKeyboard3.xsd index e610f45941e..f3a7b8bed8e 100644 --- a/keyboards/dtd/ldmlKeyboard.xsd +++ b/keyboards/dtd/ldmlKeyboard3.xsd @@ -16,7 +16,7 @@ Note: DTD @-annotations are not currently converted to .xsd. For full CLDR file Please view the subcommittee page for the most recent information. --> - + @@ -192,6 +192,7 @@ Note: DTD @-annotations are not currently converted to .xsd. For full CLDR file + @@ -345,6 +346,7 @@ Note: DTD @-annotations are not currently converted to .xsd. For full CLDR file + diff --git a/keyboards/dtd/ldmlKeyboardTest.dtd b/keyboards/dtd/ldmlKeyboardTest3.dtd similarity index 95% rename from keyboards/dtd/ldmlKeyboardTest.dtd rename to keyboards/dtd/ldmlKeyboardTest3.dtd index 39a3310c5f7..992e83a7559 100644 --- a/keyboards/dtd/ldmlKeyboardTest.dtd +++ b/keyboards/dtd/ldmlKeyboardTest3.dtd @@ -13,9 +13,9 @@ This DTD is a work in progress. Please see CLDR-15034 for the latest information. --> - + - + diff --git a/keyboards/dtd/ldmlKeyboardTest.xsd b/keyboards/dtd/ldmlKeyboardTest3.xsd similarity index 99% rename from keyboards/dtd/ldmlKeyboardTest.xsd rename to keyboards/dtd/ldmlKeyboardTest3.xsd index 612ab789c10..1c61ec482ff 100644 --- a/keyboards/dtd/ldmlKeyboardTest.xsd +++ b/keyboards/dtd/ldmlKeyboardTest3.xsd @@ -19,7 +19,7 @@ Note: DTD @-annotations are not currently converted to .xsd. For full CLDR file Please see CLDR-15034 for the latest information. --> - + diff --git a/keyboards/dtd/ldmlPlatform.dtd b/keyboards/dtd/ldmlPlatform.dtd new file mode 100644 index 00000000000..d1c56a9a609 --- /dev/null +++ b/keyboards/dtd/ldmlPlatform.dtd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/keyboards/import/keys-Latn-implied.xml b/keyboards/import/keys-Latn-implied.xml index 8de55e41851..eed84d38f82 100644 --- a/keyboards/import/keys-Latn-implied.xml +++ b/keyboards/import/keys-Latn-implied.xml @@ -9,7 +9,7 @@ CLDR data files are interpreted according to the LDML specification (http://unic This is the implied import for implied keys. Please note that any implied keys may be overridden by keyboard layouts. --> - + diff --git a/keyboards/import/keys-Zyyy-currency.xml b/keyboards/import/keys-Zyyy-currency.xml index e5e87c9a765..778cad451ad 100644 --- a/keyboards/import/keys-Zyyy-currency.xml +++ b/keyboards/import/keys-Zyyy-currency.xml @@ -11,7 +11,7 @@ CLDR data files are interpreted according to the LDML specification (http://unic This file is subject to change. Please see https://cldr.unicode.org/index/keyboard-workgroup for the latest information. --> - + diff --git a/keyboards/import/keys-Zyyy-punctuation.xml b/keyboards/import/keys-Zyyy-punctuation.xml index 91f8f9dfaf5..1e540cf024e 100644 --- a/keyboards/import/keys-Zyyy-punctuation.xml +++ b/keyboards/import/keys-Zyyy-punctuation.xml @@ -5,7 +5,7 @@ This file is subject to change. Please see https://cldr.unicode.org/index/keyboard-workgroup for the latest information. --> - + diff --git a/keyboards/test/fr-t-k0-azerty-test.xml b/keyboards/test/fr-t-k0-azerty-test.xml index 5c827d6b878..0228dae7c14 100644 --- a/keyboards/test/fr-t-k0-azerty-test.xml +++ b/keyboards/test/fr-t-k0-azerty-test.xml @@ -1,6 +1,6 @@ - - + + @@ -19,4 +19,4 @@ - + diff --git a/keyboards/test/ja-Latn-test.xml b/keyboards/test/ja-Latn-test.xml index a1e3a185ebf..c4d950f8d90 100644 --- a/keyboards/test/ja-Latn-test.xml +++ b/keyboards/test/ja-Latn-test.xml @@ -1,6 +1,6 @@ - - + + @@ -24,4 +24,4 @@ - + diff --git a/keyboards/test/pt-t-k0-abnt2-test.xml b/keyboards/test/pt-t-k0-abnt2-test.xml index 4eb59db813b..c9f7148438b 100644 --- a/keyboards/test/pt-t-k0-abnt2-test.xml +++ b/keyboards/test/pt-t-k0-abnt2-test.xml @@ -1,6 +1,6 @@ - - + + - + diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Keyboard.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Keyboard.java deleted file mode 100644 index 5876398f6db..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/Keyboard.java +++ /dev/null @@ -1,756 +0,0 @@ -package org.unicode.cldr.draft; - -import com.google.common.base.Joiner; -import com.ibm.icu.text.UnicodeSet; -import java.io.File; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import org.unicode.cldr.util.CLDRPaths; -import org.unicode.cldr.util.LanguageTagParser; -import org.unicode.cldr.util.LanguageTagParser.Status; -import org.unicode.cldr.util.XMLFileReader; -import org.unicode.cldr.util.XMLFileReader.SimpleHandler; -import org.unicode.cldr.util.XPathParts; - -/** - * A first, very rough cut at reading the keyboard data. Every public structure is immutable, eg all - * returned maps, sets. - * - * @author markdavis - */ -public class Keyboard { - - private static final boolean DEBUG = false; - - private static final String BASE = CLDRPaths.BASE_DIRECTORY + "keyboards/"; - - public enum IsoRow { - E, - D, - C, - B, - A; - } - - public enum Iso { - E00, - E01, - E02, - E03, - E04, - E05, - E06, - E07, - E08, - E09, - E10, - E11, - E12, - E13, - D00, - D01, - D02, - D03, - D04, - D05, - D06, - D07, - D08, - D09, - D10, - D11, - D12, - D13, - C00, - C01, - C02, - C03, - C04, - C05, - C06, - C07, - C08, - C09, - C10, - C11, - C12, - C13, - B00, - B01, - B02, - B03, - B04, - B05, - B06, - B07, - B08, - B09, - B10, - B11, - B12, - B13, - A00, - A01, - A02, - A03, - A04, - A05, - A06, - A07, - A08, - A09, - A10, - A11, - A12, - A13; - public final IsoRow isoRow; - - Iso() { - isoRow = IsoRow.valueOf(name().substring(0, 1)); - } - } - - // add whatever is needed - - public enum Modifier { - cmd, - ctrlL, - ctrlR, - caps, - altL, - altR, - optL, - optR, - shiftL, - shiftR; - } - - // public static class ModifierSet { - // private String temp; // later on expand into something we can use. - // @Override - // public String toString() { - // return temp; - // } - // @Override - // public boolean equals(Object obj) { - // final ModifierSet other = (ModifierSet)obj; - // return temp.equals(other.temp); - // } - // @Override - // public int hashCode() { - // return temp.hashCode(); - // }; - // - // /** - // * Parses string like "AltCapsCommand? RShiftCtrl" and returns a set of modifier sets, like: - // * {{RAlt, LAlt, Caps}, {RAlt, LAlt, Caps, Command}, {RShift, LCtrl, RCtrl}} - // */ - // public static Set parseSet(String input) { - // //ctrl+opt?+caps?+shift? ctrl+cmd?+opt?+shift? ctrl+cmd?+opt?+caps? cmd+ctrl+caps+shift+optL? - // ... - // Set results = new HashSet(); // later, Treeset - // if (input != null) { - // for (String ms : input.trim().split(" ")) { - // ModifierSet temp = new ModifierSet(); - // temp.temp = ms; - // results.add(temp); - // } - // } - // return results; - // // Set current = new LinkedHashSet();EnumSet.noneOf(Modifier.class); - // // for (String mod : input.trim().split("\\+")) { - // // boolean optional = mod.endsWith("?"); - // // if (optional) { - // // mod = mod.substring(0,mod.length()-1); - // // } - // // Modifier m = Modifier.valueOf(mod); - // // if (optional) { - // // temp = EnumSet.copyOf(current); - // // } else { - // // for (Modifier m2 : current) { - // // m2.a - // // } - // // } - // // } - // } - // /** - // * Format a set of modifier sets like {{RAlt, LAlt, Caps}, {RAlt, LAlt, Caps, Command}, - // {RShift, LCtrl, RCtrl}} - // * and return a string like "AltCapsCommand? RShiftCtrl". The exact compaction may vary. - // */ - // public static String formatSet(Set input) { - // return input.toString(); - // } - // } - - public static Set getPlatformIDs() { - Set results = new LinkedHashSet<>(); - File file = new File(BASE); - for (String f : file.list()) { - if (!f.equals("dtd") - && !f.startsWith(".") - && !f.startsWith("_") - && !f.equals("README.md")) { - results.add(f); - } - } - return results; - } - - public static Set getKeyboardIDs(String platformId) { - Set results = new LinkedHashSet<>(); - File base = new File(BASE + platformId + "/"); - for (String f : base.list()) { - if (f.endsWith(".xml") - && !f.startsWith(".") - && !f.startsWith("_") - && !f.equals("README.md")) { - results.add(f.substring(0, f.length() - 4)); - } - } - return results; - } - - public static Platform getPlatform(String platformId) { - final String fileName = BASE + platformId + "/_platform.xml"; - try { - final PlatformHandler platformHandler = new PlatformHandler(); - new XMLFileReader().setHandler(platformHandler).read(fileName, -1, true); - return platformHandler.getPlatform(); - } catch (Exception e) { - throw new KeyboardException(fileName, e); - } - } - - public Keyboard( - String locale, - String version, - String platformVersion, - Set names, - Fallback fallback, - Set keyMaps, - Map transforms) { - this.locale = locale; - this.version = version; - this.platformVersion = platformVersion; - this.fallback = fallback; - this.names = Collections.unmodifiableSet(names); - this.keyMaps = Collections.unmodifiableSet(keyMaps); - this.transforms = Collections.unmodifiableMap(transforms); - } - - // public static Keyboard getKeyboard(String keyboardId, Set errors) { - // int pos = keyboardId.indexOf("-t-k0-") + 6; - // int pos2 = keyboardId.indexOf('-', pos); - // if (pos2 < 0) { - // pos2 = keyboardId.length(); - // } - // return getKeyboard(keyboardId.substring(pos, pos2), keyboardId, errors); - // } - - public static String getPlatformId(String keyboardId) { - int pos = keyboardId.indexOf("-t-k0-") + 6; - int pos2 = keyboardId.indexOf('-', pos); - if (pos2 < 0) { - pos2 = keyboardId.length(); - } - return keyboardId.substring(pos, pos2); - } - - public static Keyboard getKeyboard( - String platformId, String keyboardId, Set errors) { - final String fileName = BASE + platformId + "/" + keyboardId + ".xml"; - try { - final KeyboardHandler keyboardHandler = new KeyboardHandler(errors); - new XMLFileReader().setHandler(keyboardHandler).read(fileName, -1, true); - return keyboardHandler.getKeyboard(); - } catch (Exception e) { - throw new KeyboardException(fileName + "\n" + Joiner.on(", ").join(errors), e); - } - } - - public static Keyboard getKeyboard(String id, Reader r, Set errors) { - // final String fileName = BASE + platformId + "/" + keyboardId + ".xml"; - try { - final KeyboardHandler keyboardHandler = new KeyboardHandler(errors); - new XMLFileReader().setHandler(keyboardHandler).read(id, r, -1, true); - return keyboardHandler.getKeyboard(); - } catch (Exception e) { - errors.add(e); - return null; - } - } - - public static class Platform { - final String id; - final Map hardwareMap; - - public String getId() { - return id; - } - - public Map getHardwareMap() { - return hardwareMap; - } - - public Platform(String id, Map hardwareMap) { - super(); - this.id = id; - this.hardwareMap = Collections.unmodifiableMap(hardwareMap); - } - } - - public enum Gesture { - LONGPRESS; - - public static Gesture fromString(String string) { - return Gesture.valueOf(string.toUpperCase(Locale.ENGLISH)); - } - } - - public enum TransformStatus { - DEFAULT, - NO; - - public static TransformStatus fromString(String string) { - return string == null - ? TransformStatus.DEFAULT - : TransformStatus.valueOf(string.toUpperCase(Locale.ENGLISH)); - } - } - - public enum TransformType { - SIMPLE; - - public static TransformType forString(String string) { - return string == null - ? TransformType.SIMPLE - : TransformType.valueOf(string.toUpperCase(Locale.ENGLISH)); - } - } - - public static class Output { - final String output; - final TransformStatus transformStatus; - final Map> gestures; - - public Output( - String output, - Map> gestures, - TransformStatus transformStatus) { - this.output = output; - this.transformStatus = transformStatus; - this.gestures = Collections.unmodifiableMap(gestures); // TODO make lists unmodifiable - } - - public String getOutput() { - return output; - } - - public TransformStatus getTransformStatus() { - return transformStatus; - } - - public Map> getGestures() { - return gestures; - } - - @Override - public String toString() { - return "{" + output + "," + transformStatus + ", " + gestures + "}"; - } - } - - public static class KeyMap { - private final KeyboardModifierSet modifiers; - final Map iso2output; - - public KeyMap(KeyboardModifierSet keyMapModifiers, Map data) { - this.modifiers = keyMapModifiers; - this.iso2output = Collections.unmodifiableMap(data); - } - - public KeyboardModifierSet getModifiers() { - return modifiers; - } - - public Map getIso2Output() { - return iso2output; - } - - @Override - public String toString() { - return "{" + modifiers + "," + iso2output + "}"; - } - } - - public static class Transforms { - final Map string2string; - - public Transforms(Map data) { - this.string2string = data; - } - - public Map getMatch(String prefix) { - Map results = new LinkedHashMap<>(); - for (Entry entry : string2string.entrySet()) { - String key = entry.getKey(); - if (key.startsWith(prefix)) { - results.put(key.substring(prefix.length()), entry.getValue()); - } - } - return results; - } - } - - private final String locale; - private final String version; - private final String platformVersion; - private final Fallback fallback; - private final Set names; - private final Set keyMaps; - private final Map transforms; - - public String getLocaleId() { - return locale; - } - - public String getVersion() { - return version; - } - - public String getPlatformVersion() { - return platformVersion; - } - - public Fallback getFallback() { - return fallback; - } - - public Set getNames() { - return names; - } - - public Set getKeyMaps() { - return keyMaps; - } - - public Map getTransforms() { - return transforms; - } - - /** - * Return all possible results. Could be external utility. WARNING: doesn't account for - * transform='no' or failure='omit'. - */ - public UnicodeSet getPossibleResults() { - UnicodeSet results = new UnicodeSet(); - for (KeyMap keymap : getKeyMaps()) { - addOutput(keymap.iso2output.values(), results); - } - for (Transforms transforms : getTransforms().values()) { - // loop, to catch empty case - for (String result : transforms.string2string.values()) { - if (!result.isEmpty()) { - results.add(result); - } - } - } - return results; - } - - private void addOutput(Collection values, UnicodeSet results) { - for (Output value : values) { - if (value.output != null && !value.output.isEmpty()) { - results.add(value.output); - } - for (List outputList : value.gestures.values()) { - results.addAll(outputList); - } - } - } - - private static class PlatformHandler extends SimpleHandler { - String id; - Map hardwareMap = new HashMap<>(); - - @Override - public void handlePathValue(String path, @SuppressWarnings("unused") String value) { - XPathParts parts = XPathParts.getFrozenInstance(path); - // - id = parts.getAttributeValue(0, "id"); - if (parts.size() > 1) { - String element1 = parts.getElement(1); - // - if (element1.equals("hardwareMap")) { - hardwareMap.put( - parts.getAttributeValue(2, "keycode"), - Iso.valueOf(parts.getAttributeValue(2, "iso"))); - } - } - } - - public Platform getPlatform() { - return new Platform(id, hardwareMap); - } - } - - public enum Fallback { - BASE, - OMIT; - - public static Fallback forString(String string) { - return string == null - ? Fallback.BASE - : Fallback.valueOf(string.toUpperCase(Locale.ENGLISH)); - } - } - - private static class KeyboardHandler extends SimpleHandler { - Set errors; // = new LinkedHashSet(); - Set errors2 = new LinkedHashSet<>(); - // doesn't do any error checking for collisions, etc. yet. - String locale; // TODO - String version; // TODO - String platformVersion; // TODO - - Set names = new LinkedHashSet<>(); - Fallback fallback = Fallback.BASE; - - KeyboardModifierSet keyMapModifiers = null; - Map iso2output = new EnumMap<>(Iso.class); - Set keyMaps = new LinkedHashSet<>(); - - TransformType currentType = null; - Map currentTransforms = null; - Map transformMap = new EnumMap<>(TransformType.class); - - LanguageTagParser ltp = new LanguageTagParser(); - - public KeyboardHandler(Set errorsOutput) { - errors = errorsOutput; - errors.clear(); - } - - public Keyboard getKeyboard() { - // finish everything off - addToKeyMaps(); - if (currentType != null) { - transformMap.put(currentType, new Transforms(currentTransforms)); - } - return new Keyboard( - locale, version, platformVersion, names, fallback, keyMaps, transformMap); - } - - @Override - public void handlePathValue(String path, @SuppressWarnings("unused") String value) { - try { - XPathParts parts = XPathParts.getFrozenInstance(path); - if (locale == null) { - // - locale = parts.getAttributeValue(0, "locale"); - ltp.set(locale); - Map extensions = ltp.getExtensions(); - LanguageTagParser.Status status = ltp.getStatus(errors2); - if (errors2.size() != 0 || !ltp.hasT()) { - errors.add( - new KeyboardException( - "Bad locale tag: " + locale + ", " + errors2.toString())); - } else if (status != Status.MINIMAL) { - errors.add( - new KeyboardWarningException("Non-minimal locale tag: " + locale)); - } - } - String element1 = parts.getElement(1); - if (element1.equals("baseMap")) { - // / - Iso iso = Iso.valueOf(parts.getAttributeValue(2, "iso")); - if (DEBUG) { - System.out.println("baseMap: iso=" + iso + ";"); - } - final Output output = getOutput(parts); - if (output != null) { - iso2output.put(iso, output); - } - } else if (element1.equals("keyMap")) { - // - final String modifiers = parts.getAttributeValue(1, "modifiers"); - KeyboardModifierSet newMods = - KeyboardModifierSet.parseSet(modifiers == null ? "" : modifiers); - if (!newMods.equals(keyMapModifiers)) { - if (keyMapModifiers != null) { - addToKeyMaps(); - } - iso2output = new LinkedHashMap<>(); - keyMapModifiers = newMods; - } - String isoString = parts.getAttributeValue(2, "iso"); - if (DEBUG) { - System.out.println("keyMap: base=" + isoString + ";"); - } - final Output output = getOutput(parts); - if (output != null) { - iso2output.put(Iso.valueOf(isoString), output); - } - } else if (element1.equals("transforms")) { - // - TransformType type = - TransformType.forString(parts.getAttributeValue(1, "type")); - if (type != currentType) { - if (currentType != null) { - transformMap.put(currentType, new Transforms(currentTransforms)); - } - currentType = type; - currentTransforms = new LinkedHashMap<>(); - } - final String from = fixValue(parts.getAttributeValue(2, "from")); - final String to = fixValue(parts.getAttributeValue(2, "to")); - if (from.equals(to)) { - errors.add( - new KeyboardException( - "Illegal transform from:" + from + " to:" + to)); - } - if (DEBUG) { - System.out.println("transform: from=" + from + ";\tto=" + to + ";"); - } - // if (result.isEmpty()) { - // System.out.println("**Empty result at " + path); - // } - currentTransforms.put(from, to); - } else if (element1.equals("version")) { - // - platformVersion = parts.getAttributeValue(1, "platform"); - version = parts.getAttributeValue(1, "number"); - } else if (element1.equals("names")) { - // - names.add(parts.getAttributeValue(2, "value")); - } else if (element1.equals("settings")) { - // - fallback = Fallback.forString(parts.getAttributeValue(1, "fallback")); - } else { - throw new KeyboardException("Unexpected element: " + element1); - } - } catch (Exception e) { - throw new KeyboardException("Unexpected error in: " + path, e); - } - } - - public void addToKeyMaps() { - for (KeyMap item : keyMaps) { - if (item.modifiers.containsSome(keyMapModifiers)) { - errors.add( - new KeyboardException( - "Modifier overlap: " - + item.modifiers - + " already contains " - + keyMapModifiers)); - } - if (item.iso2output.equals(iso2output)) { - errors.add( - new KeyboardException( - "duplicate keyboard: " - + item.modifiers - + " has same layout as " - + keyMapModifiers)); - } - } - keyMaps.add(new KeyMap(keyMapModifiers, iso2output)); - } - - private String fixValue(String value) { - StringBuilder b = new StringBuilder(); - int last = 0; - while (true) { - int pos = value.indexOf("\\u{", last); - if (pos < 0) { - break; - } - int posEnd = value.indexOf("}", pos + 3); - if (posEnd < 0) { - break; - } - b.append(value.substring(last, pos)) - .appendCodePoint(Integer.parseInt(value.substring(pos + 3, posEnd), 16)); - last = posEnd + 1; - } - b.append(value.substring(last)); - return b.toString(); - } - - public Output getOutput(XPathParts parts) { - String chars = null; - TransformStatus transformStatus = TransformStatus.DEFAULT; - Map> gestures = new EnumMap<>(Gesture.class); - - for (Entry attributeAndValue : parts.getAttributes(-1).entrySet()) { - String attribute = attributeAndValue.getKey(); - String attributeValue = attributeAndValue.getValue(); - if (attribute.equals("to")) { - chars = fixValue(attributeValue); - if (DEBUG) { - System.out.println("\tchars=" + chars + ";"); - } - if (chars.isEmpty()) { - errors.add(new KeyboardException("**Empty result at " + parts.toString())); - } - } else if (attribute.equals("transform")) { - transformStatus = TransformStatus.fromString(attributeValue); - } else if (attribute.equals("iso") || attribute.equals("base")) { - // ignore, handled above - } else { - LinkedHashSet list = new LinkedHashSet<>(); - for (String item : attributeValue.trim().split(" ")) { - final String fixedValue = fixValue(item); - if (fixedValue.isEmpty()) { - // throw new KeyboardException("Null string in list. " + parts); - continue; - } - list.add(fixedValue); - } - gestures.put( - Gesture.fromString(attribute), - Collections.unmodifiableList(new ArrayList<>(list))); - if (DEBUG) { - System.out.println("\tgesture=" + attribute + ";\tto=" + list + ";"); - } - } - } - return new Output(chars, gestures, transformStatus); - } - } - - public static class KeyboardException extends RuntimeException { - private static final long serialVersionUID = 3802627982169201480L; - - public KeyboardException(String string) { - super(string); - } - - public KeyboardException(String string, Exception e) { - super(string, e); - } - } - - public static class KeyboardWarningException extends KeyboardException { - private static final long serialVersionUID = 3802627982169201480L; - - public KeyboardWarningException(String string) { - super(string); - } - - public KeyboardWarningException(String string, Exception e) { - super(string, e); - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/KeyboardModifierSet.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/KeyboardModifierSet.java deleted file mode 100644 index 153f25f745c..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/KeyboardModifierSet.java +++ /dev/null @@ -1,289 +0,0 @@ -package org.unicode.cldr.draft; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import org.unicode.cldr.util.SetComparator; - -/** - * A class which represents a particular modifier combination (or combinations of combinations). - * - *

For example {@code alt+cmd?} gets transformed into a native format consisting of sets of ON - * modifiers. In this case it would get transformed into {@code altL+cmd, altR+cmd, altL+altR+cmd, - * altL, altR, altL+altR} . - * - *

This definition can be expanded across multiple combinations. For example {@code optR+caps? - * cmd+shift} gets transformed into {@code optR+caps, optR, cmd+shiftL, cmd+shiftR, - * cmd+shiftL+shiftR} . - * - *

Usage

- * - *

There is a 1 to 1 relationship between a {@link KeyboardModifierSet} and a particular key map - * (a mapping from physical keys to their output). - * - *

{@code
- * // Create the set from the XML modifier=".." attribute
- * ModifierSet modifierSet = ModifierSet.parseSet();
- * // Test if this set is active for a particular input combination provided by the keyboard
- * modifierSet.contains();
- * }
- * - * @author rwainman@google.com (Raymond Wainman) - */ -public class KeyboardModifierSet { - /** Enum of all possible modifier keys. */ - public enum Modifier { - cmd, - ctrlL, - ctrlR, - caps, - altL, - altR, - optL, - optR, - shiftL, - shiftR; - } - - static final SetComparator SINGLETON_COMPARATOR = new SetComparator<>(); - - /** Initial input string */ - private final String input; - /** Internal representation of all the possible combination variants */ - private final Set> variants; - - /** - * Private constructor. See factory {@link #parseSet} method. - * - * @param variants A set containing all possible variants of the combination provided in the - * input string. - */ - private KeyboardModifierSet(String input, Set> variants) { - this.input = input; - Set> safe = new TreeSet<>(SINGLETON_COMPARATOR); - for (EnumSet item : variants) { - safe.add(Collections.unmodifiableSet(item)); - } - this.variants = safe; - } - - /** - * Return all possible variants for this combination. - * - * @return Set containing all possible variants. - */ - public Set> getVariants() { - return variants; - } - - /** - * Determines if the given combination is valid within this set. - * - * @param combination A combination of Modifier elements. - * @return True if the combination is valid, false otherwise. - */ - public boolean contains(EnumSet combination) { - return variants.contains(combination); - } - - public String getInput() { - return input; - } - - @Override - public String toString() { - return input + " => " + variants; - } - - @Override - public boolean equals(Object arg0) { - return arg0 == null ? false : variants.equals(((KeyboardModifierSet) arg0).variants); - } - - @Override - public int hashCode() { - return variants.hashCode(); - } - - /** - * Parse a set containing one or more modifier sets. Each modifier set is separated by a single - * space and modifiers within a modifier set are separated by a '+'. For example {@code - * "ctrl+opt?+caps?+shift? alt+caps+cmd?"} has two modifier sets, namely: - * - *
    - *
  • {@code "ctrl+opt?+caps?+shift?"} - *
  • {@code "alt+caps+cmd?"} - *
- * - *

The '?' symbol appended to some modifiers indicates that this modifier is optional (it can - * be ON or OFF). - * - * @param input String representing the sets of modifier sets. This string must match the format - * defined in the LDML Keyboard Standard. - * @return A {@link KeyboardModifierSet} containing all possible variants of the specified - * combinations. - * @throws IllegalArgumentException if the input string is incorrectly formatted. - */ - public static KeyboardModifierSet parseSet(String input) { - if (input == null) { - throw new IllegalArgumentException("Input string cannot be null"); - } - - String modifierSetInputs[] = input.trim().split(" "); - Set> variants = new HashSet<>(); - for (String modifierSetInput : modifierSetInputs) { - variants.addAll(parseSingleSet(modifierSetInput)); - } - return new KeyboardModifierSet(input, variants); - } - - /** - * Parse a modifier set. The set typically looks something like {@code ctrl+opt?+caps?+shift?} - * or {@code alt+caps+cmd?} and return a set containing all possible variants for that - * particular modifier set. - * - *

For example {@code alt+caps+cmd?} gets expanded into {@code alt+caps+cmd?, alt+caps} . - * - * @param input The input string representing the modifiers. This String must match the format - * defined in the LDML Keyboard Standard. - * @return {@link KeyboardModifierSet}. - * @throws IllegalArgumentException if the input string is incorrectly formatted. - */ - private static Set> parseSingleSet(String input) { - if (input == null) { - throw new IllegalArgumentException("Input string cannot be null"); - } - if (input.contains(" ")) { - throw new IllegalArgumentException("Input string contains more than one combination"); - } - - String modifiers[] = input.trim().split("\\+"); - - List> variants = new ArrayList<>(); - variants.add(EnumSet.noneOf(Modifier.class)); // Add an initial set - // which is empty - - // Trivial case - if (input.isEmpty()) { - return new HashSet<>(variants); - } - - for (String modifier : modifiers) { - String modifierElementString = modifier.replace("?", ""); - - // Attempt to parse the modifier as a parent - if (ModifierParent.isParentModifier(modifierElementString)) { - ModifierParent parentModifier = ModifierParent.valueOf(modifierElementString); - - // Keep a collection of the new variants that need to be added - // while iterating over the - // existing ones - Set> newVariants = new HashSet<>(); - for (EnumSet variant : variants) { - // A parent key gets exploded into {Left, Right, Left+Right} - // or {Left, Right, Left+Right, - // (empty)} if it is a don't care - - // {Left} - EnumSet leftVariant = EnumSet.copyOf(variant); - leftVariant.add(parentModifier.leftChild); - newVariants.add(leftVariant); - - // {Right} - EnumSet rightVariant = EnumSet.copyOf(variant); - rightVariant.add(parentModifier.rightChild); - newVariants.add(rightVariant); - - // {Left+Right} - // If it is a don't care, we need to leave the empty case - // {(empty)} - if (modifier.contains("?")) { - EnumSet bothChildrenVariant = EnumSet.copyOf(variant); - bothChildrenVariant.add(parentModifier.rightChild); - bothChildrenVariant.add(parentModifier.leftChild); - newVariants.add(bothChildrenVariant); - } - // No empty case, it is safe to add to the existing variants - else { - variant.add(parentModifier.rightChild); - variant.add(parentModifier.leftChild); - } - } - variants.addAll(newVariants); - } - // Otherwise, parse as a regular modifier - else { - Modifier modifierElement = Modifier.valueOf(modifierElementString); - // On case, add the modifier to all existing variants - if (!modifier.contains("?")) { - for (EnumSet variant : variants) { - variant.add(modifierElement); - } - } - // Don't care case, make a copy of the existing variants and add - // the new key to it. - else { - List> newVariants = new ArrayList<>(); - for (EnumSet variant : variants) { - EnumSet newVariant = EnumSet.copyOf(variant); - newVariant.add(modifierElement); - newVariants.add(newVariant); - } - variants.addAll(newVariants); - } - } - } - - return new HashSet<>(variants); - } - - /** Enum of all parent modifier keys. Defines the relationships with their children. */ - private enum ModifierParent { - ctrl(Modifier.ctrlL, Modifier.ctrlR), - alt(Modifier.altL, Modifier.altR), - opt(Modifier.optL, Modifier.optR), - shift(Modifier.shiftL, Modifier.shiftR); - - private final Modifier leftChild; - private final Modifier rightChild; - - private ModifierParent(Modifier leftChild, Modifier rightChild) { - this.leftChild = leftChild; - this.rightChild = rightChild; - } - - /** - * Determines if the String passed in is a valid parent key. - * - * @param modifier The modifier string to verify. - * @return True if it is a parent key, false otherwise. - */ - private static boolean isParentModifier(String modifier) { - try { - ModifierParent.valueOf(modifier); - return true; - } catch (IllegalArgumentException e) { - return false; - } - } - } - - public boolean containsSome(KeyboardModifierSet keyMapModifiers) { - for (Set item : keyMapModifiers.variants) { - if (variants.contains(item)) { - return true; - } - } - return false; - } - - public String getShortInput() { - int pos = input.indexOf(' '); - if (pos < 0) return input; - return input.substring(0, pos) + "…"; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java deleted file mode 100644 index 44e36a55375..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/CharacterMap.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import com.google.common.base.Function; -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; - -/** - * Object representing a 1 to 1 mapping between an ISO Position ({@link IsoLayoutPosition}) and the - * provided output that is received when pressing that particular key. This object also includes any - * keys that are available by "long-pressing" on the key (prominent on mobile phones). - */ -public final class CharacterMap implements Comparable { - private final IsoLayoutPosition position; - private final String output; - private final ImmutableList longPressKeys; - private final boolean transformNo; - - private CharacterMap( - IsoLayoutPosition position, - String output, - ImmutableList longPressKeys, - boolean transformNo) { - this.position = Preconditions.checkNotNull(position); - this.output = Preconditions.checkNotNull(output); - this.longPressKeys = Preconditions.checkNotNull(longPressKeys); - this.transformNo = transformNo; - } - - /** Creates a new character map from the given position and output. */ - public static CharacterMap of(IsoLayoutPosition position, String output) { - return new CharacterMap(position, output, ImmutableList.of(), false); - } - - /** Creates a new character map from the given position, output and long press keys. */ - public static CharacterMap of( - IsoLayoutPosition position, String output, ImmutableList longPressKeys) { - return new CharacterMap(position, output, longPressKeys, false); - } - - public IsoLayoutPosition position() { - return position; - } - - public String output() { - return output; - } - - public ImmutableList longPressKeys() { - return longPressKeys; - } - - public CharacterMap markAsTransformNo() { - return new CharacterMap(position, output, longPressKeys, true); - } - - public boolean isTransformNo() { - return transformNo; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("position", position) - .add("output", output) - .add("longPressKeys", longPressKeys) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof CharacterMap) { - CharacterMap other = (CharacterMap) o; - return position.equals(other.position) - && output.equals(other.output) - && longPressKeys.equals(other.longPressKeys); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(position, output, longPressKeys); - } - - /** Sort character maps based on their ISO layout positions. */ - @Override - public int compareTo(CharacterMap o) { - return position.compareTo(o.position); - } - - static Function isoLayoutPositionFunction() { - return CharacterMapToIsoLayoutFunction.INSTANCE; - } - - private enum CharacterMapToIsoLayoutFunction - implements Function { - INSTANCE; - - @Override - public IsoLayoutPosition apply(CharacterMap character) { - return character.position; - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java deleted file mode 100644 index 2bd467a5118..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/IsoLayoutPosition.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Enum which represents the corresponding position of a key using the ISO layout convention where - * rows are identified by letters and columns are identified by numbers. For example, "D01" - * corresponds to the “Q” key on a US keyboard. For the purposes of this enum, we depict an ISO - * layout position by a one-letter row identifier followed by a two digit column number (like "B03", - * "E12" or "C00"). - * - *

It is important to note that the physical placement of the keys is not encoded in this enum, - * rather what is important is their logical placement using the ISO convention. - * - *

We can also extend the ISO Layout convention by adding rows as we please (such as adding an F - * row) or adding columns (going beyond 13 or before 0, in which case we would introduce negative - * column numbers). This extension can be used to map almost any key to the convention for our - * purposes. - * - *

More information about the ISO layout positions can be found in the LDML - * XML Keyboard Specification - */ -public enum IsoLayoutPosition { - /* Row 1 */ - E00('E', 0, "`"), - E01('E', 1, "1"), - E02('E', 2, "2"), - E03('E', 3, "3"), - E04('E', 4, "4"), - E05('E', 5, "5"), - E06('E', 6, "6"), - E07('E', 7, "7"), - E08('E', 8, "8"), - E09('E', 9, "9"), - E10('E', 10, "0"), - E11('E', 11, "-"), - E12('E', 12, "="), - E13('E', 13, "(key to right of =)"), // Additional key in 106 keyboards (like Japanese - // keyboards) - - /* Row 2 */ - D01('D', 1, "Q"), - D02('D', 2, "W"), - D03('D', 3, "E"), - D04('D', 4, "R"), - D05('D', 5, "T"), - D06('D', 6, "Y"), - D07('D', 7, "U"), - D08('D', 8, "I"), - D09('D', 9, "O"), - D10('D', 10, "P"), - D11('D', 11, "["), - D12('D', 12, "]"), - D13('D', 13, "\\"), - - /* Row 3 */ - C01('C', 1, "A"), - C02('C', 2, "S"), - C03('C', 3, "D"), - C04('C', 4, "F"), - C05('C', 5, "G"), - C06('C', 6, "H"), - C07('C', 7, "J"), - C08('C', 8, "K"), - C09('C', 9, "L"), - C10('C', 10, ";"), - C11('C', 11, "'"), - C12('C', 12, "(key to right of ')"), // Additional key in 102+ layouts, typically is present - // when D13 is not - - /* Row 4 */ - B00('B', 0, "(key to left of Z)"), // Additional key in 102 and 103 keyboards (like European - // keyboards) - B01('B', 1, "Z"), - B02('B', 2, "X"), - B03('B', 3, "C"), - B04('B', 4, "V"), - B05('B', 5, "B"), - B06('B', 6, "N"), - B07('B', 7, "M"), - B08('B', 8, ","), - B09('B', 9, "."), - B10('B', 10, "/"), - B11('B', 11, "(key to right of /)"), - B12('B', 12, "(2 keys to right of /)"), // Additional key for Android - - /* Row 5 */ - A01('A', 1, "(2 keys to left of space)"), // Additional key for Android - A02('A', 2, "(key to left of space)"), // Additional key for Android - A03('A', 3, "space"), - A04('A', 4, "(key to right of space)"), // Additional key for Android - A05('A', 5, "(2 keys to right of space)"), // Additional key for Android - A06('A', 6, "(3 keys to right of space)"), // Additional key for Android - A07('A', 7, "(4 keys to right of space)"); // Additional key for Android - - private final char row; - private final int column; - private final String englishKeyName; - - private IsoLayoutPosition(char row, int column, String englishKeyName) { - this.row = row; - this.column = column; - this.englishKeyName = checkNotNull(englishKeyName); - } - - public char row() { - return row; - } - - public int column() { - return column; - } - - /** - * Get the label that would be on the key on a US keyboard. This is for convenience and - * readability purposes only. If the key does not appear on a US keyboard, it returns a - * description of the position relative to the closest US keyboard key. - */ - public String englishKeyName() { - return englishKeyName; - } - - /** - * Returns the enum member for a given row and column. Throws an illegal argument exception if - * the element does not exist. - * - * @param row the layout row, is an upper-case character between A and E (inclusive) - * @param column the layout column, is an integer between 0 and 13 (inclusive), not all rows - * contain elements for all 14 columns - */ - public static IsoLayoutPosition forPosition(char row, int column) { - for (IsoLayoutPosition position : values()) { - if (position.row == row && position.column == column) { - return position; - } - } - throw new IllegalArgumentException("Missing ISO Position for " + row + ":" + column); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java deleted file mode 100644 index f3f2ac0eeba..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyMap.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.Maps; - -/** - * Object that represents a full keyboard mapping for a given modifier key combination set. - * - *

For example, the English-US keyboard with the Shift modifier activated outputs: - * - *

    - *
  • {@code ISO=E01 US-101 keyboard=[1] = '!'} - *
  • {@code E02 [2] = '@'} - *
  • {@code E03 [3] = '#'} - *
  • {@code E04 [4] = '$'} - *
  • {@code D01 [Q] = 'Q'} - *
  • And so on... - *
- */ -public final class KeyMap implements Comparable { - private final ModifierKeyCombinationSet modifierKeyCombinationSet; - private final ImmutableSortedMap isoLayoutToCharacterMap; - - private KeyMap( - ModifierKeyCombinationSet modifierKeyCombinationSet, - ImmutableSortedMap isoLayoutToCharacterMap) { - this.modifierKeyCombinationSet = checkNotNull(modifierKeyCombinationSet); - this.isoLayoutToCharacterMap = checkNotNull(isoLayoutToCharacterMap); - } - - /** Creates a key map from the given modifier key combination set and characer maps. */ - public static KeyMap of( - ModifierKeyCombinationSet modifierKeyCombinationSet, - ImmutableSet characterMaps) { - return new KeyMap( - modifierKeyCombinationSet, - ImmutableSortedMap.copyOf( - Maps.uniqueIndex(characterMaps, CharacterMap.isoLayoutPositionFunction()))); - } - - public ModifierKeyCombinationSet modifierKeyCombinationSet() { - return modifierKeyCombinationSet; - } - - public ImmutableSortedMap isoLayoutToCharacterMap() { - return isoLayoutToCharacterMap; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("modifierKeyCombinationSet", modifierKeyCombinationSet) - .add("isoLayoutToCharacterMap", isoLayoutToCharacterMap) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof KeyMap) { - KeyMap other = (KeyMap) o; - return modifierKeyCombinationSet.equals(other.modifierKeyCombinationSet) - && isoLayoutToCharacterMap.equals(other.isoLayoutToCharacterMap); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(modifierKeyCombinationSet, isoLayoutToCharacterMap); - } - - @Override - public int compareTo(KeyMap o) { - // Order the key maps by their modifier sets. - return modifierKeyCombinationSet.compareTo(o.modifierKeyCombinationSet); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java deleted file mode 100644 index 86d460cc08e..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Keyboard.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; - -/** - * Object representing a keyboard layout. Includes identifier information, platform given names, - * platform specific names, all the key maps for all modifier set combinations and the possible - * transforms. - */ -public final class Keyboard { - private final KeyboardId keyboardId; - private final ImmutableList names; - private final ImmutableSortedSet keyMaps; - private final ImmutableSortedSet transforms; - private volatile KeyMap baseMap; - - private Keyboard( - KeyboardId keyboardId, - ImmutableList names, - ImmutableSortedSet keyMaps, - ImmutableSortedSet transforms) { - this.keyboardId = checkNotNull(keyboardId); - this.names = checkNotNull(names); - this.keyMaps = checkNotNull(keyMaps); - this.transforms = checkNotNull(transforms); - } - - /** - * Creates a keyboard given an identifier, a list of platform given names, key maps and - * transforms. - */ - public static Keyboard of( - KeyboardId keyboardId, - ImmutableList names, - ImmutableSortedSet keyMaps, - ImmutableSortedSet transforms) { - return new Keyboard(keyboardId, names, keyMaps, transforms); - } - - public KeyboardId keyboardId() { - return keyboardId; - } - - public ImmutableList names() { - return names; - } - - public ImmutableSet keyMaps() { - return keyMaps; - } - - public KeyMap baseMap() { - return baseMap == null ? baseMap = getBaseMap() : baseMap; - } - - private KeyMap getBaseMap() { - for (KeyMap keyMap : keyMaps) { - if (keyMap.modifierKeyCombinationSet().isBase()) { - return keyMap; - } - } - throw new IllegalStateException("Missing base map for " + keyboardId); - } - - public ImmutableSet transforms() { - return transforms; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof Keyboard) { - Keyboard other = (Keyboard) o; - return keyboardId.equals(other.keyboardId) - && names.equals(other.names) - && keyMaps.equals(other.keyMaps) - && transforms.equals(other.transforms); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(keyboardId, names, keyMaps, transforms); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("keyboardIds", keyboardId) - .add("names", names) - .add("keyMaps", keyMaps) - .add("transforms", transforms) - .toString(); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java deleted file mode 100644 index 4c2a2603c38..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardBuilder.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Maps; -import com.google.common.collect.Table; -import com.ibm.icu.text.Collator; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -/** Builder class to assist in constructing a keyboard object. */ -public final class KeyboardBuilder { - private final ImmutableSet.Builder keyboardIds; - private final ImmutableList.Builder names; - private final Map transformSequenceToOutput; - private final Table - modifierAndPositionToCharacter; - - public KeyboardBuilder() { - keyboardIds = ImmutableSet.builder(); - names = ImmutableList.builder(); - transformSequenceToOutput = Maps.newHashMap(); - modifierAndPositionToCharacter = HashBasedTable.create(); - } - - public KeyboardBuilder addKeyboardIds(Iterable keyboardIds) { - this.keyboardIds.addAll(keyboardIds); - return this; - } - - public KeyboardBuilder addName(String name) { - names.add(name); - return this; - } - - public KeyboardBuilder addTransform(String sequence, String output) { - if (transformSequenceToOutput.containsKey(sequence) - && !transformSequenceToOutput.get(sequence).equals(output)) { - String errorMessage = String.format("Duplicate entry for [%s:%s]", sequence, output); - throw new IllegalArgumentException(errorMessage); - } - transformSequenceToOutput.put(sequence, output); - return this; - } - - public KeyboardBuilder addCharacterMap( - ModifierKeyCombination combination, CharacterMap characterMap) { - checkNotNull(combination); - if (modifierAndPositionToCharacter.contains(combination, characterMap.position())) { - CharacterMap existing = - modifierAndPositionToCharacter.get(combination, characterMap.position()); - checkArgument( - existing.equals(characterMap), - "Duplicate entry for [%s:%s:%s]", - combination, - characterMap, - existing); - } - modifierAndPositionToCharacter.put(combination, characterMap.position(), characterMap); - return this; - } - - public KeyboardBuilder addCharacterMap( - Collection combinations, CharacterMap characterMap) { - for (ModifierKeyCombination combination : combinations) { - addCharacterMap(combination, characterMap); - } - return this; - } - - public ImmutableList build() { - ImmutableSet keyboardIds = this.keyboardIds.build(); - checkArgument(keyboardIds.size() > 0, "KeyboardIds must contain at least one element"); - // See if key map consolidation is possible. - ListMultimap, ModifierKeyCombination> charactersToCombinations = - ArrayListMultimap.create(); - for (ModifierKeyCombination combination : modifierAndPositionToCharacter.rowKeySet()) { - Collection characterMaps = - modifierAndPositionToCharacter.row(combination).values(); - charactersToCombinations.put(ImmutableSet.copyOf(characterMaps), combination); - } - // Build the key maps. - KeyboardId id = keyboardIds.iterator().next(); - ImmutableSortedSet.Builder keyMaps = ImmutableSortedSet.naturalOrder(); - for (ImmutableSet characterMaps : charactersToCombinations.keySet()) { - List combinations = charactersToCombinations.get(characterMaps); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.copyOf(combinations)); - keyMaps.add(KeyMap.of(combinationSet, characterMaps)); - } - // Add the transforms. - ImmutableSortedSet.Builder transforms = - ImmutableSortedSet.orderedBy(collatorComparator(Collator.getInstance(id.locale()))); - for (Entry transformEntry : transformSequenceToOutput.entrySet()) { - transforms.add(Transform.of(transformEntry.getKey(), transformEntry.getValue())); - } - ImmutableList.Builder keyboards = ImmutableList.builder(); - for (KeyboardId keyboardId : keyboardIds) { - keyboards.add( - Keyboard.of(keyboardId, names.build(), keyMaps.build(), transforms.build())); - } - return keyboards.build(); - } - - public Set transformSequences() { - return transformSequenceToOutput.keySet(); - } - - private static Comparator collatorComparator(final Collator collator) { - return new Comparator() { - @Override - public int compare(Transform o1, Transform o2) { - return collator.compare(o1.sequence(), o2.sequence()); - } - }; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java deleted file mode 100644 index 08275ab69f8..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardId.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Functions; -import com.google.common.base.Joiner; -import com.google.common.base.Objects; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.ibm.icu.util.ULocale; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.FallbackSetting; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformFailureSetting; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformPartialSetting; - -/** - * An object that is used to uniquely identify a particular keyboard. This object can be serialized - * as a string. The string has the following format: {@code - * -t-k0----} - * - *

The locale and platform tags are mandatory, the attributes are not. - * - *

The following are all valid keyboard locale strings: - * - *

    - *
  • bn-t-k0-windows.xml - *
  • de-BE-t-k0-windows-var.xml - *
  • fi-t-k0-osx-extended-var.xml - *
  • es-US-t-k0-android-768dpi.xml - *
- */ -public final class KeyboardId { - private final ULocale locale; - private final Platform platform; - private final ImmutableList attributes; - - private KeyboardId(ULocale locale, Platform platform, ImmutableList attributes) { - this.locale = checkNotNull(locale); - this.platform = checkNotNull(platform); - this.attributes = checkNotNull(attributes); - } - - /** Creates a keyboard id from the given locale, platform and attributes. */ - public static KeyboardId of( - ULocale locale, Platform platform, ImmutableList attributes) { - return new KeyboardId(locale, platform, attributes); - } - - /** - * Creates a keyboard id from the given string. See class documentation for information on the - * required format of the string. - */ - public static KeyboardId fromString(String keyboardLocale) { - int tExtensionLocation = keyboardLocale.indexOf("-t-k0-"); - checkArgument(tExtensionLocation != -1, keyboardLocale); - String localeString = keyboardLocale.substring(0, tExtensionLocation); - ULocale locale = ULocale.forLanguageTag(localeString); - String[] attributeStrings = keyboardLocale.substring(tExtensionLocation + 6).split("-"); - checkArgument(attributeStrings.length > 0, keyboardLocale); - Platform platform = Platform.fromString(attributeStrings[0]); - ImmutableList attributes = - attributeStrings.length > 1 - ? ImmutableList.copyOf(attributeStrings).subList(1, attributeStrings.length) - : ImmutableList.of(); - return new KeyboardId(locale, platform, attributes); - } - - /** Returns the keyboard's locale. */ - public ULocale locale() { - return locale; - } - - /** Returns the keyboard's platform. */ - public Platform platform() { - return platform; - } - - /** Returns the list of additional attributes associated with the keyboard (if any). */ - public ImmutableList attributes() { - return attributes; - } - - private static final Joiner DASH_JOINER = Joiner.on("-"); - - @Override - public String toString() { - ImmutableList.Builder components = ImmutableList.builder(); - // We want to use dashes within the locale as opposed to underscores. - components.add(locale.toString().replace("_", "-")); - components.add("t-k0"); - components.add(platform.toString()); - components.addAll(FluentIterable.from(attributes).transform(Functions.toStringFunction())); - return DASH_JOINER.join(components.build()); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof KeyboardId) { - KeyboardId other = (KeyboardId) o; - return Objects.equal(locale, other.locale) - && Objects.equal(platform, other.platform) - && Objects.equal(attributes, other.attributes); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(locale, platform, attributes); - } - - /** The current set of platforms supported. */ - public enum Platform { - ANDROID( - 4.4f, - KeyboardSettings.of( - FallbackSetting.NONE, - TransformFailureSetting.NONE, - TransformPartialSetting.NONE)), - CHROMEOS( - 33f, - KeyboardSettings.of( - FallbackSetting.BASE, - TransformFailureSetting.OMIT, - TransformPartialSetting.HIDE)), - OSX( - 10.9f, - KeyboardSettings.of( - FallbackSetting.BASE, - TransformFailureSetting.EMIT, - TransformPartialSetting.SHOW)), - WINDOWS( - 10f, - KeyboardSettings.of( - FallbackSetting.OMIT, - TransformFailureSetting.EMIT, - TransformPartialSetting.HIDE)); - - private final float version; - private final KeyboardSettings settings; - - private Platform(float version, KeyboardSettings settings) { - this.version = version; - this.settings = checkNotNull(settings); - checkArgument(version >= 0); - } - - public double version() { - return version; - } - - public KeyboardSettings settings() { - return settings; - } - - @Override - public String toString() { - return name().toLowerCase(); - } - - /** - * Retrieves the enum value for the given string. Throws an illegal argument exception if - * the given string does not correspond to an enum value. - */ - private static Platform fromString(String platform) { - Platform value = Platform.valueOf(platform.toUpperCase()); - checkArgument(platform != null, platform); - return value; - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java deleted file mode 100644 index a2df18eb9af..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardIdMap.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Charsets; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import com.google.common.io.Resources; -import com.ibm.icu.util.ULocale; -import java.io.IOException; -import java.util.List; -import java.util.Set; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; - -public final class KeyboardIdMap { - private final ImmutableMultimap nameToKeyboardId; - // Internal only. - private final Set coveredNames; - - private KeyboardIdMap(ImmutableMultimap nameToKeyboardId) { - this.nameToKeyboardId = checkNotNull(nameToKeyboardId); - coveredNames = Sets.newHashSet(); - } - - private static final Splitter LINE_SPLITTER = Splitter.on("\n").omitEmptyStrings(); - private static final Splitter COMMA_SPLITTER = Splitter.on(","); - private static final Splitter DASH_SPLITTER = Splitter.on("-").omitEmptyStrings(); - - /** - * Creates the mapping from csv contents. The first line must contain the column headers - * "name,locale,attributes". - */ - public static KeyboardIdMap fromCsv(String csv, Platform platform) { - checkArgument(!csv.isEmpty()); - List lines = LINE_SPLITTER.splitToList(csv); - checkArgument(lines.get(0).equals("name,locale,attributes"), "Missing csv headers"); - ImmutableMultimap.Builder builder = ImmutableMultimap.builder(); - for (String line : Iterables.skip(lines, 1)) { - // The first element may be between quotes (if it includes a comma), if so parse it - // manually. - String name; - int closingQuote = line.startsWith("\"") ? line.indexOf("\"", 1) : 0; - List components = COMMA_SPLITTER.splitToList(line.substring(closingQuote)); - if (closingQuote != 0) { - name = line.substring(1, closingQuote); - } else { - name = components.get(0); - } - ULocale locale = ULocale.forLanguageTag(components.get(1)); - ImmutableList attributes = - ImmutableList.copyOf(DASH_SPLITTER.splitToList(components.get(2))); - builder.put(name, KeyboardId.of(locale, platform, attributes)); - } - return new KeyboardIdMap(builder.build()); - } - - /** Retrieves the csv file relative to the class given. */ - public static KeyboardIdMap fromResource(Class clazz, String fileName, Platform platform) { - try { - String csv = Resources.toString(Resources.getResource(clazz, fileName), Charsets.UTF_8); - return fromCsv(csv, platform); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - } - - public ImmutableCollection getKeyboardId(String name) { - coveredNames.add(name); - ImmutableCollection ids = nameToKeyboardId.get(name); - checkArgument(ids.size() > 0, "No keyboard id for %s [%s]", name, nameToKeyboardId); - return ids; - } - - public Set unmatchedIds() { - return Sets.difference(nameToKeyboardId.keySet(), coveredNames); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java deleted file mode 100644 index 9cf57df6a77..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardSettings.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; - -/** Describes various platform dependent settings that are pertinent to the keyboard use. */ -public final class KeyboardSettings { - private final FallbackSetting fallbackSetting; - private final TransformFailureSetting transformFailureSetting; - private final TransformPartialSetting transformPartialSetting; - - private KeyboardSettings( - FallbackSetting fallbackSetting, - TransformFailureSetting transformFailureSetting, - TransformPartialSetting transformPartialSetting) { - this.fallbackSetting = checkNotNull(fallbackSetting); - this.transformFailureSetting = checkNotNull(transformFailureSetting); - this.transformPartialSetting = checkNotNull(transformPartialSetting); - } - - /** Creates a keyboard settings object from the given options. */ - public static KeyboardSettings of( - FallbackSetting fallbackSetting, - TransformFailureSetting transformFailureSetting, - TransformPartialSetting transformPartialSetting) { - return new KeyboardSettings( - fallbackSetting, transformFailureSetting, transformPartialSetting); - } - - public FallbackSetting fallbackSetting() { - return fallbackSetting; - } - - public TransformFailureSetting transformFailureSetting() { - return transformFailureSetting; - } - - public TransformPartialSetting transformPartialSetting() { - return transformPartialSetting; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("fallbackSetting", fallbackSetting) - .add("transformFailureSetting", transformFailureSetting) - .add("transformPartialSetting", transformPartialSetting) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof KeyboardSettings) { - KeyboardSettings other = (KeyboardSettings) o; - return Objects.equal(fallbackSetting, other.fallbackSetting) - && Objects.equal(transformFailureSetting, other.transformFailureSetting) - && Objects.equal(transformPartialSetting, other.transformPartialSetting); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(fallbackSetting, transformFailureSetting, transformPartialSetting); - } - - /** - * Describes the behavior of the system when a key press fails. It specifies what happens if - * there is no mapping for a particular key for the given set of modifier keys. This setting is - * completely platform dependent. NONE indicates the setting does not apply to the platform. - */ - public enum FallbackSetting { - BASE, - OMIT, - NONE; - - @Override - public String toString() { - return name().toLowerCase(); - } - } - - /** - * Describes the behavior of the system when a transform fails. For example it specifies what - * happens if a dead-key is pressed and the following key cannot be combined. This setting is - * completely platform dependent. NONE indicates the setting does not apply to the platform. - */ - public enum TransformFailureSetting { - EMIT, - OMIT, - NONE; - - @Override - public String toString() { - return name().toLowerCase(); - } - } - - /** - * Describes the behavior of the system while a transform is in progress. It specifies whether - * the pressed keys are displayed or not. This setting is completely platform dependent. NONE - * indicates the setting does not apply to the platform. - */ - public enum TransformPartialSetting { - HIDE, - SHOW, - NONE; - - @Override - public String toString() { - return name().toLowerCase(); - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java deleted file mode 100644 index 83974d8264d..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeyboardTool.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import java.io.File; -import java.io.FileWriter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.StringWriter; -import java.time.Instant; -import java.util.Arrays; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; -import org.unicode.cldr.draft.keyboard.out.KeyboardToXml; -import org.unicode.cldr.draft.keyboard.out.KeycodeMapToXml; -// import org.unicode.cldr.draft.keyboard.windows.KlcParser; -import org.unicode.cldr.draft.keyboard.windows.KlcParser; - -public final class KeyboardTool { - - /** - * First argument is output folder, second is the location of the windows keyboard source files. - */ - public static void main(String[] args) throws IOException { - System.out.println(Arrays.toString(args)); - long timestamp = Instant.now().getEpochSecond(); - String output = args[0] + "/" + timestamp; - File outputFolder = new File(output); - parseWindowsKeyboards(args[1], outputFolder); - // parseOsxKeyboards("/Users/rwainman/Downloads/osx", outputFolder); - } - - /* - private static void parseOsxKeyboards(String inputFolder, File outputFolder) throws IOException { - File macosKeyboardsDirectory = new File(inputFolder); - File macosOutputFolder = new File(outputFolder + "/osx"); - macosOutputFolder.mkdirs(); - for (File keyboardLayout : macosKeyboardsDirectory.listFiles(KeylayoutFilenameFilter.INSTANCE)) { - System.out.println("Parsing " + keyboardLayout); - String contents = Files.toString(keyboardLayout, Charsets.UTF_8); - KeylayoutParser.parseLayout(contents); - for (Document document : KeyboardToXml.writeToXml(keyboard)) { - Element keyboardElement = (Element) document.getFirstChild=(); - String locale = keyboardElement.getAttribute("locale"); - File outputFile = new File(macosOutputFolder + "/" + locale + ".xml"); - Files.write(documentToString(document), outputFile, Charsets.UTF_8); - System.out.println(" Writing to " + outputFile); - } - return; - } - System.out.println(KeylayoutParser.KEYBOARD_ID_MAP.unmatchedIds()); - } - - private enum KeylayoutFilenameFilter implements FilenameFilter { - INSTANCE; - @Override public boolean accept(File dir, String name) { - return name.endsWith(".keylayout"); - } - } - */ - - private static void parseWindowsKeyboards(String inputFolder, File outputFolder) - throws IOException { - File windowsKeyboardsDirectory = new File(inputFolder); - File windowsOutputFolder = new File(outputFolder + "/windows"); - windowsOutputFolder.mkdirs(); - for (File keyboardLayout : - windowsKeyboardsDirectory.listFiles(KlcFilenameFilter.INSTANCE)) { - System.out.println("Parsing " + keyboardLayout); - String contents = Files.toString(keyboardLayout, Charsets.UTF_16); - ImmutableList keyboards = KlcParser.parseLayout(contents); - for (Keyboard keyboard : keyboards) { - String id = keyboard.keyboardId().toString(); - File outputFile = new File(windowsOutputFolder + "/" + id + ".xml"); - StringWriter keyboardStringWriter = new StringWriter(); - KeyboardToXml.writeToXml(keyboard, keyboardStringWriter); - FileWriter keyboardFileWriter = new FileWriter(outputFile); - keyboardFileWriter.write(doLastMinuteFixesToXml(keyboardStringWriter.toString())); - keyboardFileWriter.close(); - System.out.println(" Writing to " + outputFile); - } - } - System.out.println("Writing _platform.xml"); - FileWriter platformFileWriter = new FileWriter(windowsOutputFolder + "/_platform.xml"); - KeycodeMapToXml.writeToXml(KlcParser.KEYCODE_MAP, Platform.WINDOWS, platformFileWriter); - if (KlcParser.KEYBOARD_ID_MAP.unmatchedIds().size() != 0) { - System.out.println( - "Found the following keyboards with no id (add them to windows-locales.csv file):"); - System.out.println(KlcParser.KEYBOARD_ID_MAP.unmatchedIds()); - } - } - - private enum KlcFilenameFilter implements FilenameFilter { - INSTANCE; - - @Override - public boolean accept(File dir, String name) { - return name.endsWith(".klc"); - } - } - - private static String doLastMinuteFixesToXml(String ouputString) { - String cleansedString = - ouputString - // The regular XML output does not escape the apostrophes. - .replace("\"'\"", "\"'\""); - return cleansedString; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java deleted file mode 100644 index 5ad85d9231c..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/KeycodeMap.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Charsets; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.Iterables; -import com.google.common.io.Resources; -import java.io.IOException; -import java.util.List; - -/** - * An class which maps a hardware key code (the value that is sent from keyboard driver to the - * application) to its actual iso layout position. - */ -public final class KeycodeMap { - private final ImmutableSortedMap keycodeToIsoLayout; - - private KeycodeMap(ImmutableSortedMap keycodeToIsoLayout) { - this.keycodeToIsoLayout = checkNotNull(keycodeToIsoLayout); - } - - private static final Splitter LINE_SPLITTER = Splitter.on("\n").omitEmptyStrings(); - private static final Splitter COMMA_SPLITTER = Splitter.on(","); - - /** - * Creates the mapping from csv contents. The first line must contain the column headers - * "keycode,iso". - */ - public static KeycodeMap fromCsv(String csv) { - checkArgument(!csv.isEmpty()); - List lines = LINE_SPLITTER.splitToList(csv); - checkArgument(lines.get(0).equals("keycode,iso"), "Missing csv headers"); - ImmutableSortedMap.Builder builder = - ImmutableSortedMap.naturalOrder(); - for (String line : Iterables.skip(lines, 1)) { - // No fancy CSV parsing required since there are no strings. - List components = COMMA_SPLITTER.splitToList(line); - builder.put( - Integer.valueOf(components.get(0)), - IsoLayoutPosition.valueOf(components.get(1))); - } - return new KeycodeMap(builder.build()); - } - - /** Retrieves the csv file relative to the class given. */ - public static KeycodeMap fromResource(Class clazz, String fileName) { - try { - String csv = Resources.toString(Resources.getResource(clazz, fileName), Charsets.UTF_8); - return fromCsv(csv); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - } - - public boolean hasIsoLayoutPosition(Integer keycode) { - return keycodeToIsoLayout.containsKey(keycode); - } - - public IsoLayoutPosition getIsoLayoutPosition(Integer keycode) { - return checkNotNull( - keycodeToIsoLayout.get(keycode), - "No keycode for %s [%s]", - keycode, - keycodeToIsoLayout); - } - - public ImmutableSortedMap keycodeToIsoLayout() { - return keycodeToIsoLayout; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java deleted file mode 100644 index c007a1e494a..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKey.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -/** - * Modifier keys used in the LDML Keyboard XML representation. A modifier key is pressed to change - * the behavior of the keyboard. For example, pressing the Shift key on most Latin keyboards - * produces upper-case variants of the characters. - * - *

It is important NOT to change the ordering of the declared enum members because this - * enumeration is used for sorting purposes. - */ -public enum ModifierKey { - COMMAND(Variant.NONE, "cmd"), - CONTROL(Variant.PARENT, "ctrl"), - CONTROL_LEFT(Variant.LEFT, "ctrl"), - CONTROL_RIGHT(Variant.RIGHT, "ctrl"), - ALT(Variant.PARENT, "alt"), - ALT_LEFT(Variant.LEFT, "alt"), - ALT_RIGHT(Variant.RIGHT, "alt"), - OPTION(Variant.PARENT, "opt"), - OPTION_LEFT(Variant.LEFT, "opt"), - OPTION_RIGHT(Variant.RIGHT, "opt"), - CAPSLOCK(Variant.NONE, "caps"), - SHIFT(Variant.PARENT, "shift"), - SHIFT_LEFT(Variant.LEFT, "shift"), - SHIFT_RIGHT(Variant.RIGHT, "shift"); - - // Map of modifier key identifiers (obtained by calling toString()) to the modifier key itself. - private static final ImmutableMap STRING_TO_MODIFIER_KEY = - Maps.uniqueIndex( - Lists.newArrayList(ModifierKey.values()), Functions.toStringFunction()); - private static final ImmutableSet PARENTS = - ImmutableSet.of(CONTROL, ALT, OPTION, SHIFT); - private static final ImmutableSet SINGLES = ImmutableSet.of(COMMAND, CAPSLOCK); - - private final Variant variant; - private final String keyType; - - private ModifierKey(Variant variant, String keyType) { - this.variant = checkNotNull(variant); - this.keyType = checkNotNull(keyType); - } - - /** Retrieves a modifier key from its string identifier. */ - public static ModifierKey fromString(String string) { - ModifierKey key = STRING_TO_MODIFIER_KEY.get(checkNotNull(string)); - checkArgument(key != null, string); - return key; - } - - /** Returns all keys that are parent keys. */ - public static ImmutableSet parents() { - return PARENTS; - } - - /** Returns all keys that are neither parent keys or children. */ - public static ImmutableSet singles() { - return SINGLES; - } - - /** - * Returns the matching sibling of this key. For example, if this key is ctrlR return ctrlL. If - * the key has no siblings this method simply returns itself. - */ - public ModifierKey sibling() { - if (variant == Variant.PARENT) { - return this; - } - return fromString(keyType + variant.opposite()); - } - - /** - * Returns the parent of this key. For example, if this key is ctrlR return ctrl. If the key is - * already a parent key this method simply returns itself. - */ - public ModifierKey parent() { - if (variant == Variant.PARENT) { - return this; - } - return fromString(keyType); - } - - /** - * Returns the children of this key. For example if this key is ctrl, return both ctrlL and - * ctrlR. If this is not a parent key, returns an empty list. The left key is always returned - * first. - */ - public ImmutableList children() { - if (variant != Variant.PARENT) { - return ImmutableList.of(); - } - return ImmutableList.of( - fromString(keyType + Variant.LEFT), fromString(keyType + Variant.RIGHT)); - } - - @Override - public String toString() { - return keyType + variant.value; - } - - /** The variant of the key. */ - private static enum Variant { - PARENT(""), - LEFT("L"), - RIGHT("R"), - NONE(""); - - final String value; - - Variant(String value) { - this.value = checkNotNull(value); - } - - /** - * Return the opposite variant. Only applicable to the left and right variants. Returns - * itself otherwise. - */ - Variant opposite() { - return this == LEFT ? RIGHT : this == RIGHT ? LEFT : this; - } - - @Override - public String toString() { - return value; - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java deleted file mode 100644 index be00e97578d..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombination.java +++ /dev/null @@ -1,200 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Sets; -import java.util.Iterator; -import java.util.Set; - -/** - * Object containing the combination of modifier keys that must be on and off for a particular - * combination to be activated. All other keys are considered "don't care keys". This simulates - * boolean logic for a 3 state system. - * - *

For example, suppose we have three keys, "A", "B" and "C". Then the boolean expression: {@code - * A AND !B} means that A must be on, B must be off and C is a don't care. - * - *

Some keys may have L and R variants (like Control which has a Left-Control and a - * Right-Control). When the situation occurs that the parent key (the variant without a left or - * right suffix) is included into the on keys or off keys sets, then the children are included into - * the don't care pool and are omitted when the combination is printed out. - * - *

For example, suppose we have three keys "A", "B" and "C" and "A" has a left and right variant - * which are "A-Right" and "A-Left" respectively. Continuing the example above, the keys fall into - * the following categories: - * - *

    - *
  • ON: { A } - *
  • OFF: { B } - *
  • DON'T CARE: { C, A-Left, A-Right } - *
- * - *

However when printing out the combination, we would exclude the A-Left and A-Right keys - * because their parent is already included in the ON set. Therefore the output result would be: - * {@code A+C?}. - * - *

A slightly different behavior exists for parent modifier keys. When a parent modifier key is - * given then its children are also added to the don't care keys pool. Once again, the - * simplification is shown when printing out the combination. - * - *

For example, continuing the above example but this time assuming that C has a left and right - * variant. Therefore the breakdown looks like: - * - *

    - *
  • ON: { A } - *
  • OFF: { B } - *
  • DON'T CARE: { C, C-Left, C-Right, A-Left, A-Right } - *
- */ -public final class ModifierKeyCombination implements Comparable { - public static final ModifierKeyCombination BASE = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of()); - - private final ImmutableSet onKeys; - private final ImmutableSet offKeys; - - private ModifierKeyCombination( - ImmutableSet onKeys, ImmutableSet offKeys) { - this.onKeys = checkNotNull(onKeys); - this.offKeys = checkNotNull(offKeys); - } - - /** - * Create a modifier key combination from a set of ON keys. This is the most common factory - * method since most sources will provide the keys that MUST be on. Simplifies the set as - * needed. - */ - public static ModifierKeyCombination ofOnKeys(Set onKeys) { - return ofOnAndDontCareKeys(ImmutableSet.copyOf(onKeys), ImmutableSet.of()); - } - - /** - * Create a modifier key combination from a set of ON keys and a set of DON'T CARE keys. That is - * a set of keys that MUST be ON and a set of keys that CAN be ON or OFF. Simplifies the sets as - * needed. - */ - public static ModifierKeyCombination ofOnAndDontCareKeys( - Set onKeys, Set dontCareKeys) { - checkArgument( - Sets.intersection(onKeys, dontCareKeys).size() == 0, - "On keys and don't care keys must be disjoint"); - return ModifierKeySimplifier.simplifyInput( - ImmutableSet.copyOf(onKeys), ImmutableSet.copyOf(dontCareKeys)); - } - - /** Internal. */ - static ModifierKeyCombination of( - ImmutableSet onKeys, ImmutableSet offKeys) { - return new ModifierKeyCombination(onKeys, offKeys); - } - - /** Returns the set of keys that have to be ON for this combination to be active. */ - public ImmutableSet onKeys() { - return onKeys; - } - - /** Returns the set of keys that have to be OFF for this combination to be active. */ - public ImmutableSet offKeys() { - return offKeys; - } - - /** - * Determines if this combination is a base combination. That is, is this combination valid when - * no modifier keys are pressed? - */ - public boolean isBase() { - return onKeys.isEmpty(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof ModifierKeyCombination) { - ModifierKeyCombination other = (ModifierKeyCombination) o; - return onKeys.equals(other.onKeys) && offKeys.equals(other.offKeys); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(onKeys, offKeys); - } - - @Override - public String toString() { - // TODO: cache this result. - return ModifierKeySimplifier.simplifyToString(this); - } - - @Override - public int compareTo(ModifierKeyCombination o) { - // Compare on keys first. - ImmutableSortedSet sortedOnKeys1 = ImmutableSortedSet.copyOf(onKeys); - ImmutableSortedSet sortedOnKeys2 = ImmutableSortedSet.copyOf(o.onKeys); - int result = compareSetsDescending(sortedOnKeys1, sortedOnKeys2); - // If they are identical, compare off keys (this will be the opposite from the result from - // the - // on keys because what we really want is the order for the don't care keys which are simply - // the - // converse of the off keys) - // Here is a simple illustrative example: - // -Suppose Alphabetic order within a combination - // -Suppose reverse Alphabetic order between combinations - // -Suppose four keys {A, B, C, D} - // -Suppose two combinations, A.B.~D (A+B+C?) and A.B.~C (A+B+D?). - // We want them ordered: A+B+D? A+B+C? - // Clearly, AB are identical in both so we move onto the off keys: ~D and ~C respectively. - // According to our initial comparison, ~D comes before ~C, but this is incorrect when - // looking - // at the don't care keys which are C? and D? respectively. This is why we multiply the - // result - // received from the off keys comparison by -1. - // - // More on the reverse ordering scheme between combinations: - // Within a combination: A+B+C (A comes before B and B comes before C) - // Between combinations: Suppose two combinations, A+C and B+C. Then the order would be B+C - // A+C. - // (Reverse ordering so B comes before A). - if (result == 0) { - ImmutableSortedSet sortedOffKeys1 = ImmutableSortedSet.copyOf(offKeys); - ImmutableSortedSet sortedOffKeys2 = ImmutableSortedSet.copyOf(o.offKeys); - return -1 * compareSetsDescending(sortedOffKeys1, sortedOffKeys2); - } else { - return result; - } - } - - /** - * Compare two sets of modifier key elements. Returns a negative integer if {@code set1} is less - * than {@code set2}, a positive integer if {@code set1} is greater than {@code set2} and 0 if - * both sets are equal. - * - *

Compares the sets based on the reverse ordering of the natural order imposed by the - * modifier key enum. This is the convention used in the LDML Keyboard Standard. - */ - private static int compareSetsDescending( - ImmutableSortedSet set1, ImmutableSortedSet set2) { - Iterator iterator1 = set1.iterator(); - Iterator iterator2 = set2.iterator(); - // Compare on keys until a difference is found. - while (iterator1.hasNext() && iterator2.hasNext()) { - ModifierKey modifierKey1 = iterator1.next(); - ModifierKey modifierKey2 = iterator2.next(); - if (modifierKey1.compareTo(modifierKey2) < 0) { - return 1; - } else if (modifierKey1.compareTo(modifierKey2) > 0) { - return -1; - } - } - // If the first x elements are identical, then the set with more modifier keys should come - // after the set with less. - return set1.size() - set2.size(); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java deleted file mode 100644 index 7e04fd0baed..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeyCombinationSet.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Joiner; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import java.util.Iterator; -import java.util.Set; - -/** - * This class wraps a set of modifier key combinations. This class also includes the necessary - * functions to simplify and output these combinations according to the LDML Keyboard Standard. - * - *

A modifier key combination set is active if any single contained modifier key combination is - * active. That is, there is a disjunctive relationship between the combinations. - * - *

Combination1 OR Combination2 OR Combination3 ... - */ -public final class ModifierKeyCombinationSet implements Comparable { - private final ImmutableSortedSet combinations; - - private ModifierKeyCombinationSet(ImmutableSortedSet combinations) { - this.combinations = checkNotNull(combinations); - } - - /** - * Creates a modifier key combination set from a set of combinations. Simplifies the set to its - * simplest form. - */ - public static ModifierKeyCombinationSet of(Set combinations) { - ImmutableSet simplifiedSet = - ModifierKeySimplifier.simplifySet(combinations); - return new ModifierKeyCombinationSet(ImmutableSortedSet.copyOf(simplifiedSet)); - } - - /** - * Merge multiple modifier key combinations into a single one. This method is useful when - * consolidating identical key maps together. - */ - public static ModifierKeyCombinationSet combine(Iterable sets) { - ImmutableSet.Builder builder = ImmutableSet.builder(); - for (ModifierKeyCombinationSet combinationSet : sets) { - builder.addAll(combinationSet.combinations); - } - return ModifierKeyCombinationSet.of(builder.build()); - } - - public ImmutableSortedSet combinations() { - return combinations; - } - - /** - * Determines if this modifier key combination set is a base set. That is, is it active when no - * modifiers are pressed? - */ - public boolean isBase() { - for (ModifierKeyCombination combination : combinations) { - if (combination.isBase()) { - return true; - } - } - return false; - } - - private static final Joiner SPACE_JOINER = Joiner.on(" "); - - @Override - public String toString() { - return SPACE_JOINER.join(combinations); - } - - @Override - public int compareTo(ModifierKeyCombinationSet o) { - Iterator iterator1 = combinations.iterator(); - Iterator iterator2 = o.combinations.iterator(); - // Compare combinations until a difference is found. - while (iterator1.hasNext() && iterator2.hasNext()) { - ModifierKeyCombination combination1 = iterator1.next(); - ModifierKeyCombination combination2 = iterator2.next(); - if (combination1.compareTo(combination2) < 0) { - return -1; - } else if (combination1.compareTo(combination2) > 0) { - return 1; - } - } - // Otherwise compare them based on size. - return combinations.size() - o.combinations.size(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof ModifierKeyCombinationSet) { - ModifierKeyCombinationSet other = (ModifierKeyCombinationSet) o; - return combinations.equals(other.combinations); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(combinations); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java deleted file mode 100644 index 73e15c8fc54..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/ModifierKeySimplifier.java +++ /dev/null @@ -1,457 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableTable; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.common.collect.Sets.SetView; -import java.util.EnumSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -/** - * A helper class which helps simplify single key combinations. That is, keys which come in a parent - * and child variants. - * - *

The strategy used to build this simplification table was to minimize the number of terms in - * the boolean algebra by simplifying most keys into a "don't care (?)" state as much as possible. - * For example, to represent an empty combination of keys, we use "Parent = 0, Left Child = ?, Right - * Child = ?" as opposed to "Parent = 0, Left Child = 0, Right Child = 0". (See the table above for - * more details). Both forms are functionally equivalent but we feel that the first form is much - * simpler to represent. - */ -public final class ModifierKeySimplifier { - /** - * A mapping from input (given by a ON set and a DON'T CARE set) to the internal representation - * of the combination. The order is always {@code }. - * - *

Notation: - * - *

    - *
  • "-" = Missing (not in any set) - *
  • "1" = In the ON set - *
  • "?" = In the DON'T CARE set - *
  • "0" = In the OFF set - *
      - */ - private static final ImmutableMap INPUT_COMBINATION_TO_INTERNAL = - ImmutableMap.builder() - .put("---", "0??") - .put("--1", "?01") - .put("--?", "?0?") - .put("-1-", "?10") - .put("-11", "?11") - .put("-1?", "?1?") - .put("-?-", "??0") - .put("-?1", "??1") - .put("-??", "???") - .put("1--", "1??") - .put("1-1", "??1") - .put("1-?", "1??") - .put("11-", "?1?") - .put("111", "?11") - .put("11?", "?1?") - .put("1?-", "1??") - .put("1?1", "??1") - .put("1??", "1??") - .put("?--", "???") - .put("?-1", "??1") - .put("?-?", "?0?") - .put("?1-", "?1?") - .put("?11", "?11") - .put("?1?", "?1?") - .put("??-", "??0") - .put("??1", "??1") - .put("???", "???") - .build(); - - /** - * A mapping which maps the result of an OR between two combinations. Takes two combinations - * (represented in the internal notation) and returns the simplified combination (also in the - * internal notation). - * - *

      For example, "A? AL" simplifies to "A?", "AL AL+AR" simplifies to "AL+AR?" and so on. The - * equivalence table is included in the document linked in the class header. - * - *

      Notation: - * - *

        - *
      • "%" = No simplification possible, both combinations must stay. - *
      • "1" = In the ON set - *
      • "?" = In the DON'T CARE set - *
      • "0" = In the OFF set - *
          - */ - private static final ImmutableTable COMBINATIONS_TO_SIMPLIFCATION = - ImmutableTable.builder() - .put("1??", "0??", "???") - .put("?10", "0??", "??0") - .put("?1?", "0??", "%") - .put("??0", "0??", "??0") - .put("?11", "0??", "%") - .put("?01", "0??", "?0?") - .put("??1", "0??", "%") - .put("?0?", "0??", "?0?") - .put("???", "0??", "???") - .put("?10", "1??", "1??") - .put("?1?", "1??", "1??") - .put("??0", "1??", "???") - .put("?11", "1??", "1??") - .put("?01", "1??", "1??") - .put("??1", "1??", "1??") - .put("?0?", "1??", "???") - .put("???", "1??", "???") - .put("?1?", "?10", "?1?") - .put("??0", "?10", "??0") - .put("?11", "?10", "?1?") - .put("?01", "?10", "%") - .put("??1", "?10", "%") - .put("?0?", "?10", "%") - .put("???", "?10", "???") - .put("??0", "?1?", "%") - .put("?11", "?1?", "?1?") - .put("?01", "?1?", "%") - .put("??1", "?1?", "1??") - .put("?0?", "?1?", "???") - .put("???", "?1?", "???") - .put("?11", "??0", "%") - .put("?01", "??0", "%") - .put("??1", "??0", "???") - .put("?0?", "??0", "%") - .put("???", "??0", "???") - .put("?01", "?11", "??1") - .put("??1", "?11", "??1") - .put("?0?", "?11", "%") - .put("???", "?11", "???") - .put("??1", "?01", "??1") - .put("?0?", "?01", "?0?") - .put("???", "?01", "???") - .put("?0?", "??1", "%") - .put("???", "??1", "???") - .put("???", "?0?", "???") - .build(); - - /** - * Given a set of ON keys and DON'T CARE keys, simplify and determine the internal - * representation of the combination. - */ - public static ModifierKeyCombination simplifyInput( - Set onKeys, Set dontCareKeys) { - checkArgument(Sets.intersection(onKeys, dontCareKeys).size() == 0); - ImmutableSet.Builder onKeysBuilder = ImmutableSet.builder(); - ImmutableSet.Builder offKeysBuilder = ImmutableSet.builder(); - // Add parent keys and their children. - for (ModifierKey parentKey : ModifierKey.parents()) { - StringBuilder inputRepresentation = new StringBuilder(); - // Parent key. - inputRepresentation.append(getInputKeyState(parentKey, onKeys, dontCareKeys)); - // Children. - for (ModifierKey child : parentKey.children()) { - inputRepresentation.append(getInputKeyState(child, onKeys, dontCareKeys)); - } - // Get the internal representation - String result = INPUT_COMBINATION_TO_INTERNAL.get(inputRepresentation.toString()); - checkNotNull(result, "No internal mapping for %s", inputRepresentation); - // Transform the String representation into the internal representation and add them to - // the ON - // and OFF sets. - addInternalRepresentationFromString(parentKey, result, onKeysBuilder, offKeysBuilder); - } - // Add single keys. - for (ModifierKey singleKey : ModifierKey.singles()) { - if (onKeys.contains(singleKey)) { - onKeysBuilder.add(singleKey); - } else if (!dontCareKeys.contains(singleKey)) { - offKeysBuilder.add(singleKey); - } - } - return ModifierKeyCombination.of(onKeysBuilder.build(), offKeysBuilder.build()); - } - - /** Find the state of the given modifier key by evaluating the given sets. */ - private static char getInputKeyState( - ModifierKey modifierKey, Set onKeys, Set dontCareKeys) { - return onKeys.contains(modifierKey) ? '1' : dontCareKeys.contains(modifierKey) ? '?' : '-'; - } - - private static Joiner PLUS_JOINER = Joiner.on('+'); - - /** - * Given a set of ON keys and OFF keys in the internal representation, simplify the combination - * and produce a string representing the combination in the format defined by the LDML Keyboard - * Standard. - * - *

          Namely: - * - *

            - *
          • All keys are separated by a '+'. - *
          • All don't care keys are suffixed by a '?'. - *
          • ON keys are grouped together and are displayed first, followed by the don't care keys. - *
          • The modifier keys should be in the order defined in the standard within a group. - *
          • The combination should be in its simplest form. - *
          - */ - public static String simplifyToString(ModifierKeyCombination combination) { - ImmutableSet onKeys = combination.onKeys(); - ImmutableSet offKeys = combination.offKeys(); - TreeSet onKeysForOutput = Sets.newTreeSet(); - TreeSet dontCareKeysForOutput = Sets.newTreeSet(); - for (ModifierKey parentKey : ModifierKey.parents()) { - String result = getStringFromInternalRepresentation(parentKey, onKeys, offKeys); - char parentState = result.charAt(0); - char leftChildState = result.charAt(1); - char rightChildState = result.charAt(2); - // If both children are don't cares, output the parent only in its state (don't output - // the OFF - // ones). - if (leftChildState == '?' && rightChildState == '?') { - if (parentState == '1') { - onKeysForOutput.add(parentKey); - } else if (parentState == '?') { - dontCareKeysForOutput.add(parentKey); - } - } - // Otherwise, add the child keys in their states (don't output the OFF ones). - else { - ImmutableList children = parentKey.children(); - if (leftChildState == '1') { - onKeysForOutput.add(children.get(0)); - } else if (leftChildState == '?') { - dontCareKeysForOutput.add(children.get(0)); - } - if (rightChildState == '1') { - onKeysForOutput.add(children.get(1)); - } else if (rightChildState == '?') { - dontCareKeysForOutput.add(children.get(1)); - } - } - } - // Add single keys - for (ModifierKey singleKey : ModifierKey.singles()) { - if (onKeys.contains(singleKey)) { - onKeysForOutput.add(singleKey); - } else if (!offKeys.contains(singleKey)) { - dontCareKeysForOutput.add(singleKey); - } - } - // Join on-keys. - String onKeysString = PLUS_JOINER.join(onKeysForOutput); - // Join don't care keys. - List dontCareKeysList = Lists.newArrayList(); - for (ModifierKey dontCareKey : dontCareKeysForOutput) { - dontCareKeysList.add(dontCareKey.toString() + "?"); - } - String dontCareKeysString = PLUS_JOINER.join(dontCareKeysList); - return dontCareKeysString.isEmpty() - ? onKeysString - : onKeysString.isEmpty() - ? dontCareKeysString - : PLUS_JOINER.join(onKeysString, dontCareKeysString); - } - - /** Find the state of the given modifier key by evaluating the given sets. */ - private static char getInternalKeyState( - ModifierKey modifierKey, Set onKeys, Set offKeys) { - return onKeys.contains(modifierKey) ? '1' : offKeys.contains(modifierKey) ? '0' : '?'; - } - - /** - * Simplifies the set of combinations into its most simple forms and returns a modifier key - * combination set. - */ - public static ImmutableSet simplifySet( - Set combinations) { - // Make a defensive copy of the input. - Set finalCombinations = Sets.newHashSet(combinations); - // Keep simplifying the combination until a stable version is attained. - int sizeChange = Integer.MAX_VALUE; - while (sizeChange != 0) { - int initialSize = finalCombinations.size(); - finalCombinations = simplifyCombinationsOnePass(finalCombinations); - sizeChange = initialSize - finalCombinations.size(); - } - return ImmutableSet.copyOf(finalCombinations); - } - - /** - * Make a single pass over the set of combinations to attempt to simplify them. Multiple calls - * to this method are necessary to achieve the simplest form. - */ - private static Set simplifyCombinationsOnePass( - Set combinations) { - if (combinations.size() < 2) { - return combinations; - } - Iterator iterator = Sets.newTreeSet(combinations).iterator(); - Set finalCombinations = Sets.newHashSet(); - // Take two consecutive objects in the sorted set and attempt to simplify them. - ModifierKeyCombination combination1 = iterator.next(); - while (iterator.hasNext()) { - ModifierKeyCombination combination2 = iterator.next(); - Set result = - simplifyTwoCombinations(combination1, combination2); - // If the simplification was successful, use it as a new pointer. - if (result.size() == 1) { - combination1 = result.iterator().next(); - } else { - finalCombinations.add(combination1); - combination1 = combination2; - } - } - finalCombinations.add(combination1); - return finalCombinations; - } - - /** - * Given two modifier key combinations, attempt to simplify them into a single combination. If - * no simplification is possible, the method simply returns a set containing the two original - * combinations. - */ - private static ImmutableSet simplifyTwoCombinations( - ModifierKeyCombination combination1, ModifierKeyCombination combination2) { - // If the combinations are identical, the simplification is trivial. - if (combination1.equals(combination2)) { - return ImmutableSet.of(combination1); - } - SetView onKeyDifferences = - Sets.symmetricDifference(combination1.onKeys(), combination2.onKeys()); - SetView offKeyDifferences = - Sets.symmetricDifference(combination1.offKeys(), combination2.offKeys()); - // Simplification is only possible if there is some sort of relationship between the keys - // (and - // even then, simplification is not guaranteed. - if (!keysAreRelated(onKeyDifferences, offKeyDifferences)) { - return ImmutableSet.of(combination1, combination2); - } - // Get the modifier key parent in question. - ModifierKey key = null; - if (onKeyDifferences.size() > 0) { - key = onKeyDifferences.iterator().next(); - } else { - key = offKeyDifferences.iterator().next(); - } - ModifierKey parentKey = key.parent(); - // Set up a new combination with all the common keys from the two combinations. - Sets.SetView onKeysIntersect = - Sets.intersection(combination1.onKeys(), combination2.onKeys()); - EnumSet onKeys = - onKeysIntersect.isEmpty() - ? EnumSet.noneOf(ModifierKey.class) - : EnumSet.copyOf(onKeysIntersect); - Sets.SetView offKeysIntersect = - Sets.intersection(combination1.offKeys(), combination2.offKeys()); - EnumSet offKeys = - offKeysIntersect.isEmpty() - ? EnumSet.noneOf(ModifierKey.class) - : EnumSet.copyOf(offKeysIntersect); - // Get the internal state of both combinations for this particular modifier key - String combination1States = - getStringFromInternalRepresentation( - parentKey, combination1.onKeys(), combination1.offKeys()); - String combination2States = - getStringFromInternalRepresentation( - parentKey, combination2.onKeys(), combination2.offKeys()); - // Attempt to get simplification (may need to reverse the col/row keys because we are just - // storing a triangular matrix with the simplification codes). - String result = COMBINATIONS_TO_SIMPLIFCATION.get(combination1States, combination2States); - if (result == null) { - result = COMBINATIONS_TO_SIMPLIFCATION.get(combination2States, combination1States); - } - checkNotNull( - result, "Unknown combination %s", combination1States + "," + combination2States); - // The "%" return code means that the two combinations cannot be combined. - if (result.equals("%")) { - return ImmutableSet.of(combination1, combination2); - } - // Transform the String representation into the internal representation and add them to the - // ON - // and OFF sets. - ImmutableSet.Builder onKeysBuilder = ImmutableSet.builder(); - ImmutableSet.Builder offKeysBuilder = ImmutableSet.builder(); - addInternalRepresentationFromString(parentKey, result, onKeysBuilder, offKeysBuilder); - onKeysBuilder.addAll(onKeys); - offKeysBuilder.addAll(offKeys); - return ImmutableSet.of( - ModifierKeyCombination.of(onKeysBuilder.build(), offKeysBuilder.build())); - } - - /** - * Given the set difference between two combinations ON keys and OFF keys, determine if the - * differences in both sets are related (simplification is only possible if there is a - * relationship between the different keys). - */ - private static boolean keysAreRelated(Set onKeys, Set offKeys) { - // Combine all keys. - Set allKeys = EnumSet.noneOf(ModifierKey.class); - allKeys.addAll(onKeys); - allKeys.addAll(offKeys); - // Get a test key. - ModifierKey testKey = allKeys.iterator().next(); - // Remove all keys which have some sort of relationship to the test key from all keys. - allKeys.remove(testKey); - allKeys.remove(testKey.parent()); - allKeys.remove(testKey.sibling()); - allKeys.removeAll(testKey.children()); - // Check that set is empty, if it isn't there are some extra keys. - return allKeys.size() == 0; - } - - /** - * Return a length 3 String representing the state of a parent key and its two children in their - * internal representation given a set of ON keys and OFF keys (in internal representation). - */ - private static String getStringFromInternalRepresentation( - ModifierKey parentKey, Set onKeys, Set offKeys) { - StringBuilder internalRepresentationBuilder = new StringBuilder(); - internalRepresentationBuilder.append(getInternalKeyState(parentKey, onKeys, offKeys)); - // Children - ImmutableList children = parentKey.children(); - // If there are no children, mark them as ?? (effectively removing them from the boolean - // equation). - if (children.size() == 0) { - internalRepresentationBuilder.append("??"); - } else { - internalRepresentationBuilder.append( - getInternalKeyState(children.get(0), onKeys, offKeys)); - internalRepresentationBuilder.append( - getInternalKeyState(children.get(1), onKeys, offKeys)); - } - return internalRepresentationBuilder.toString(); - } - - /** - * Transform a length 3 String containing the state of a modifier key and its children and add - * it to the onKeys and offKeys builders. - */ - private static void addInternalRepresentationFromString( - ModifierKey parentKey, - String modifierKeyState, - ImmutableSet.Builder onKeysOut, - ImmutableSet.Builder offKeysOut) { - checkArgument(modifierKeyState.length() == 3, modifierKeyState); - ImmutableList children = parentKey.children(); - List keys = - children.isEmpty() - ? Lists.newArrayList(parentKey, parentKey, parentKey) - : Lists.newArrayList(parentKey, children.get(0), children.get(1)); - for (int i = 0; i < modifierKeyState.length(); i++) { - char state = modifierKeyState.charAt(i); - ModifierKey key = keys.get(i); - if (state == '1') { - onKeysOut.add(key); - } else if (state == '0') { - offKeysOut.add(key); - } - } - } - - private ModifierKeySimplifier() {} -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Transform.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Transform.java deleted file mode 100644 index b64d9a2b35b..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/Transform.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.unicode.cldr.draft.keyboard; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; - -/** - * Object representing the result of one transform from the tree. A transform has two components: - * - *
            - *
          • the sequence of characters that must be input in order to activate this transform - *
          • the output of the transformation - *
          - * - *

          For example, the character sequence for a particular transform could be '^e' and its resulting - * output 'ê'. - */ -public final class Transform implements Comparable { - private final String sequence; - private final String output; - - private Transform(String sequence, String output) { - this.sequence = checkNotNull(sequence); - this.output = checkNotNull(output); - } - - /** Creates a transform from the given source sequence and resulting output. */ - public static Transform of(String sequence, String output) { - return new Transform(sequence, output); - } - - /** - * Returns the sequence of characters that must be typed in order to activate this transform. - */ - public String sequence() { - return sequence; - } - - /** Returns the result of the transform. */ - public String output() { - return output; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sequence", sequence) - .add("output", output) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof Transform) { - Transform other = (Transform) o; - return sequence.equals(other.sequence) && output.equals(other.output); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(sequence, output); - } - - @Override - public int compareTo(Transform o) { - return sequence.compareTo(o.sequence); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/KeylayoutParser.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/KeylayoutParser.java deleted file mode 100644 index f54e84dff69..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/KeylayoutParser.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.unicode.cldr.draft.keyboard.osx; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.CharMatcher; -import com.google.common.base.Charsets; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Map; -import java.util.regex.Pattern; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.unicode.cldr.draft.keyboard.CharacterMap; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.Keyboard; -import org.unicode.cldr.draft.keyboard.KeyboardBuilder; -import org.unicode.cldr.draft.keyboard.KeyboardId; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; -import org.unicode.cldr.draft.keyboard.KeyboardIdMap; -import org.unicode.cldr.draft.keyboard.KeycodeMap; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombinationSet; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -public final class KeylayoutParser { - private static final Pattern INVALID_UNICODE_XML = Pattern.compile("�([01][0-9a-fA-F]);"); - private static final KeycodeMap KEYCODE_MAP = - KeycodeMap.fromResource(KeylayoutParser.class, "osx-keycodes.csv"); - public static final KeyboardIdMap KEYBOARD_ID_MAP = - KeyboardIdMap.fromResource(KeylayoutParser.class, "osx-locales.csv", Platform.OSX); - - private final KeyboardBuilder builder; - private final Element keyboardElement; - private final Map mapIndexToModifier = Maps.newHashMap(); - - private KeylayoutParser(Element keyboardElement) { - this.keyboardElement = checkNotNull(keyboardElement); - builder = new KeyboardBuilder(); - } - - public static ImmutableList parseLayout(String keylayoutContents) { - String cleansedString = - keylayoutContents - .replace("\u007f", "") - .replace("", "") - .replace("", "") - .replace("\"<\"", "\"<\"") - .replace("\">\"", "\">\"") - .replace("\"\"\"", "\""\"") - .replace("\"&\"", "\"&\"") - .replace("\"'\"", "\"'\""); - cleansedString = INVALID_UNICODE_XML.matcher(cleansedString).replaceAll(""); - Document document; - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - document = - builder.parse( - new InputSource( - new ByteArrayInputStream( - cleansedString - .toString() - .getBytes(Charsets.US_ASCII)))); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } catch (SAXException e) { - throw new RuntimeException(e); - } - KeylayoutParser parser = new KeylayoutParser(document.getDocumentElement()); - return parser.parse(); - } - - /** Parse the given keylayout contents and populate the keyboard builder. */ - private ImmutableList parse() { - parseId(); - Element layout = findLayout(); - String modifierId = layout.getAttribute("modifiers"); - parseModifiers(modifierId); - String mapSet = layout.getAttribute("mapSet"); - parseKeyMaps(mapSet); - return builder.build(); - } - - private void parseId() { - String name = keyboardElement.getAttribute("name"); - checkArgument(!name.isEmpty()); - builder.addName(name); - ImmutableCollection ids = KEYBOARD_ID_MAP.getKeyboardId(name); - builder.addKeyboardIds(ids); - } - - private Element findLayout() { - NodeList layouts = keyboardElement.getElementsByTagName("layout"); - for (int i = 0; i < layouts.getLength(); i++) { - Element layout = (Element) layouts.item(i); - if (layout.getAttribute("first").equals("0") - || layout.getAttribute("first").equals("1")) { - return layout; - } - } - throw new IllegalArgumentException("No layout element containing first='0'"); - } - - private void parseModifiers(String modifierId) { - checkArgument(!modifierId.isEmpty()); - NodeList modifierMaps = keyboardElement.getElementsByTagName("modifierMap"); - Element modifierMap = null; - for (int i = 0; i < modifierMaps.getLength(); i++) { - Element modifierMapElement = (Element) modifierMaps.item(i); - if (modifierMapElement.getAttribute("id").equals(modifierId)) { - modifierMap = modifierMapElement; - } - } - checkNotNull(modifierMap); - NodeList keyMapSelects = modifierMap.getElementsByTagName("keyMapSelect"); - for (int i = 0; i < keyMapSelects.getLength(); i++) { - Element keyMapSelect = (Element) keyMapSelects.item(i); - NodeList modifiers = keyMapSelect.getElementsByTagName("modifier"); - ImmutableSet.Builder combinations = ImmutableSet.builder(); - for (int j = 0; j < modifiers.getLength(); j++) { - Element modifier = (Element) modifiers.item(j); - String keys = modifier.getAttribute("keys"); - combinations.add(parseKeys(keys)); - } - String mapIndex = keyMapSelect.getAttribute("mapIndex"); - checkArgument(!mapIndex.isEmpty()); - mapIndexToModifier.put(mapIndex, ModifierKeyCombinationSet.of(combinations.build())); - } - } - - private static final Splitter WHITESPACE_SPLITTER = - Splitter.on(CharMatcher.whitespace()).omitEmptyStrings(); - - private static ModifierKeyCombination parseKeys(String keys) { - ImmutableSet.Builder onKeys = ImmutableSet.builder(); - ImmutableSet.Builder dontCareKeys = ImmutableSet.builder(); - for (String key : WHITESPACE_SPLITTER.splitToList(keys)) { - boolean maybe = key.contains("?"); - key = maybe ? key.substring(0, key.length() - 1) : key; - ImmutableSet.Builder builder = maybe ? dontCareKeys : onKeys; - if (key.equals("command")) { - builder.add(ModifierKey.COMMAND); - } else if (key.equals("caps")) { - builder.add(ModifierKey.CAPSLOCK); - } else if (key.equals("anyShift")) { - builder.add(ModifierKey.SHIFT); - } else if (key.equals("shift")) { - builder.add(ModifierKey.SHIFT_LEFT); - } else if (key.equals("rightShift")) { - builder.add(ModifierKey.SHIFT_RIGHT); - } else if (key.equals("anyOption")) { - builder.add(ModifierKey.OPTION); - } else if (key.equals("option")) { - builder.add(ModifierKey.OPTION_LEFT); - } else if (key.equals("rightOption")) { - builder.add(ModifierKey.OPTION_RIGHT); - } else if (key.equals("anyControl")) { - builder.add(ModifierKey.CONTROL); - } else if (key.equals("control")) { - builder.add(ModifierKey.CONTROL_LEFT); - } else if (key.equals("rightControl")) { - builder.add(ModifierKey.CONTROL_RIGHT); - } else { - throw new IllegalArgumentException(key); - } - } - return ModifierKeyCombination.ofOnAndDontCareKeys(onKeys.build(), dontCareKeys.build()); - } - - private void parseKeyMaps(String mapSet) { - NodeList keyMapSets = keyboardElement.getElementsByTagName("keyMapSet"); - Element keyMapSet = null; - for (int i = 0; i < keyMapSets.getLength(); i++) { - Element keyMapSetElement = (Element) keyMapSets.item(i); - if (keyMapSetElement.getAttribute("id").equals(mapSet)) { - keyMapSet = keyMapSetElement; - } - } - checkNotNull(keyMapSet); - NodeList keyMaps = keyMapSet.getElementsByTagName("keyMap"); - for (int i = 0; i < keyMaps.getLength(); i++) { - Element keyMap = (Element) keyMaps.item(i); - String modifierIndex = keyMap.getAttribute("index"); - ModifierKeyCombinationSet combinationSet = mapIndexToModifier.get(modifierIndex); - checkNotNull(combinationSet, modifierIndex); - NodeList keys = keyMap.getElementsByTagName("key"); - for (int j = 0; j < keys.getLength(); j++) { - Element key = (Element) keys.item(j); - if (!key.getAttribute("code").matches("[0-9]+")) { - throw new IllegalArgumentException(key.getAttribute("code")); - } - Integer code = Integer.valueOf(key.getAttribute("code")); - if (!KEYCODE_MAP.hasIsoLayoutPosition(code)) { - continue; - } - IsoLayoutPosition position = KEYCODE_MAP.getIsoLayoutPosition(code); - CharacterMap characterMap = CharacterMap.of(position, key.getAttribute("output")); - for (ModifierKeyCombination combination : combinationSet.combinations()) { - builder.addCharacterMap(combination, characterMap); - } - } - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/TransformTree.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/TransformTree.java deleted file mode 100644 index f698ecaa78f..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/osx/TransformTree.java +++ /dev/null @@ -1,3 +0,0 @@ -package org.unicode.cldr.draft.keyboard.osx; - -public final class TransformTree {} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeyboardToXml.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeyboardToXml.java deleted file mode 100644 index 68463f76aa2..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeyboardToXml.java +++ /dev/null @@ -1,208 +0,0 @@ -package org.unicode.cldr.draft.keyboard.out; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableMap; -import com.ibm.icu.lang.UCharacter; -import com.ibm.icu.text.DecimalFormat; -import com.ibm.icu.text.UCharacterIterator; -import com.ibm.icu.text.UnicodeSet; -import java.io.Writer; -import org.unicode.cldr.draft.keyboard.CharacterMap; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.KeyMap; -import org.unicode.cldr.draft.keyboard.Keyboard; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.FallbackSetting; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformFailureSetting; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformPartialSetting; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombinationSet; -import org.unicode.cldr.draft.keyboard.Transform; - -public final class KeyboardToXml { - private final Keyboard keyboard; - private final XmlWriter xmlWriter; - - private KeyboardToXml(Keyboard keyboard, XmlWriter xmlWriter) { - this.keyboard = checkNotNull(keyboard); - this.xmlWriter = checkNotNull(xmlWriter); - } - - /** Writes the given keyboard map in XML format to the provided writer. */ - public static void writeToXml(Keyboard keyboard, Writer writer) { - XmlWriter xmlWriter = XmlWriter.newXmlWriter(writer); - KeyboardToXml keyboardToXml = new KeyboardToXml(keyboard, xmlWriter); - keyboardToXml.toXml(); - } - - private void toXml() { - xmlWriter.startDocument("keyboard", "../dtd/ldmlKeyboard.dtd"); - xmlWriter.startElement("keyboard", ImmutableMap.of("locale", keyboard.keyboardId())); - addMetadata(); - addKeyMaps(); - addTransforms(); - xmlWriter.endElement(); - xmlWriter.endDocument(); - } - - private static DecimalFormat VERSION_FORMAT = new DecimalFormat("#.#"); - - private void addMetadata() { - Platform platform = keyboard.keyboardId().platform(); - ImmutableMap versionAttributes = - ImmutableMap.of( - "platform", - VERSION_FORMAT.format(platform.version()), - "number", - "$Revision$"); - xmlWriter.addElement("version", versionAttributes); - // xmlWriter.addElement("generation", ImmutableMap.of("date", "$Date$")); - xmlWriter.startElement("names"); - for (String name : keyboard.names()) { - xmlWriter.addElement("name", ImmutableMap.of("value", name)); - } - xmlWriter.endElement(); - // Settings. - ImmutableMap.Builder settingsBuilder = ImmutableMap.builder(); - if (platform.settings().fallbackSetting() == FallbackSetting.OMIT) { - FallbackSetting fallbackSetting = platform.settings().fallbackSetting(); - settingsBuilder.put("fallback", fallbackSetting.toString().toLowerCase()); - } - boolean hasTransform = keyboard.transforms().size() > 0; - if (hasTransform - && platform.settings().transformFailureSetting() == TransformFailureSetting.OMIT) { - TransformFailureSetting transformFailure = - platform.settings().transformFailureSetting(); - settingsBuilder.put("transformFailure", transformFailure.toString()); - } - if (hasTransform - && platform.settings().transformPartialSetting() == TransformPartialSetting.HIDE) { - TransformPartialSetting transformPartial = - platform.settings().transformPartialSetting(); - settingsBuilder.put("transformPartial", transformPartial.toString()); - } - ImmutableMap settingsAttributes = settingsBuilder.build(); - if (!settingsAttributes.isEmpty()) { - xmlWriter.addElement("settings", settingsAttributes); - } - } - - private static final Joiner COMMA_JOINER = Joiner.on(","); - - private void addKeyMaps() { - for (KeyMap keyMap : keyboard.keyMaps()) { - ImmutableMap.Builder keyMapAttributes = ImmutableMap.builder(); - ModifierKeyCombinationSet modifiers = keyMap.modifierKeyCombinationSet(); - if (!modifiers.isBase()) { - keyMapAttributes.put("modifiers", modifiers.toString()); - } - xmlWriter.startElement("keyMap", keyMapAttributes.build()); - for (CharacterMap characterMap : keyMap.isoLayoutToCharacterMap().values()) { - String output = characterMap.output(); - ImmutableMap.Builder mapAttributes = ImmutableMap.builder(); - mapAttributes.put("iso", "" + characterMap.position()); - String escapedOutput = escapeOutput(output); - mapAttributes.put("to", escapedOutput); - if (!characterMap.longPressKeys().isEmpty()) { - mapAttributes.put("longPress", COMMA_JOINER.join(characterMap.longPressKeys())); - } - if (characterMap.isTransformNo()) { - mapAttributes.put("transform", "no"); - } - String comment = buildReadabilityComment(characterMap, escapedOutput); - xmlWriter.addElement("map", mapAttributes.build(), comment); - } - xmlWriter.endElement(); - } - } - - private static final UnicodeSet ESCAPED_CHARACTERS_NO_SPACE = - new UnicodeSet("[[:di:][:c:][:M:][:whitespace:][\"]-[\\u0020]]").freeze(); - - private String escapeOutput(String output) { - StringBuilder stringBuilder = new StringBuilder(); - UCharacterIterator it = UCharacterIterator.getInstance(output); - int character; - while ((character = it.nextCodePoint()) != UCharacterIterator.DONE) { - if (ESCAPED_CHARACTERS_NO_SPACE.contains(character)) { - stringBuilder.append(String.format("\\u{%X}", character)); - } else { - stringBuilder.append(UCharacter.toString(character)); - } - } - return stringBuilder.toString(); - } - - private static final UnicodeSet ILLEGAL_COMMENT_CHARACTERS = - new UnicodeSet("[[:di:][:c:][:whitespace:]]").freeze(); - - private String buildReadabilityComment(CharacterMap characterMap, String escapedOutput) { - StringBuilder comment = new StringBuilder(); - String output = characterMap.output(); - IsoLayoutPosition position = characterMap.position(); - // English Key Name (Only if it is non-trivial) - if (!output.toUpperCase().equals(position.englishKeyName())) { - comment.append(position.englishKeyName()); - } - // Base (Only if it is different than the english key and non-trivial). - KeyMap baseMap = keyboard.baseMap(); - CharacterMap baseKey = baseMap.isoLayoutToCharacterMap().get(position); - if (baseKey != null - && !baseKey.output().toUpperCase().equals(output.toUpperCase()) - && !baseKey.output().toUpperCase().equals(position.englishKeyName())) { - comment.append(" base="); - comment.append(baseKey.output()); - } - // Output (Only if the output is safe for comment) - if (escapedOutput.contains("\\u{") && !ILLEGAL_COMMENT_CHARACTERS.contains(output)) { - comment.append(" to= " + output + " "); - } - /* - // Long press - if (longPressString.contains("\\u{")) { - StringBuilder longPressBuilder = new StringBuilder(); - for (String longPress : longPressKeys) { - if (!CommonUtil.ILLEGAL_COMMENT_CHARACTERS.contains(longPress)) { - longPressBuilder.append(longPress); - longPressBuilder.append(" "); - } - } - - if (longPressBuilder.length() > 0) { - comment.append(" long="); - comment.append(longPressBuilder.toString()); - } - } - */ - return comment.toString(); - } - - private void addTransforms() { - if (keyboard.transforms().isEmpty()) { - return; - } - xmlWriter.startElement("transforms", ImmutableMap.of("type", "simple")); - for (Transform transform : keyboard.transforms()) { - String escapedSequence = escapeOutput(transform.sequence()); - String escapedOutput = escapeOutput(transform.output()); - String comment = - buildTransformReadabilityComment(transform, escapedSequence, escapedOutput); - xmlWriter.addElement( - "transform", - ImmutableMap.of("from", escapedSequence, "to", escapedOutput), - comment); - } - xmlWriter.endElement(); - } - - private String buildTransformReadabilityComment( - Transform transform, String escapedSequence, String escapedOutput) { - if ((escapedSequence.contains("\\u{") || escapedOutput.contains("\\u{")) - && !ILLEGAL_COMMENT_CHARACTERS.containsSome(transform.sequence()) - && !ILLEGAL_COMMENT_CHARACTERS.contains(transform.output())) { - return transform.sequence() + " → " + transform.output(); - } - return ""; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeycodeMapToXml.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeycodeMapToXml.java deleted file mode 100644 index 7c3a0014a09..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/KeycodeMapToXml.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.unicode.cldr.draft.keyboard.out; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.collect.ImmutableMap; -import java.io.Writer; -import java.util.Map.Entry; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; -import org.unicode.cldr.draft.keyboard.KeycodeMap; - -/** Utility class that writes the given key code map into the LDML XML format. */ -public final class KeycodeMapToXml { - private final KeycodeMap keycodeMap; - private final Platform platform; - private final XmlWriter xmlWriter; - - private KeycodeMapToXml(KeycodeMap keycodeMap, Platform platform, XmlWriter xmlWriter) { - this.keycodeMap = checkNotNull(keycodeMap); - this.platform = checkNotNull(platform); - this.xmlWriter = checkNotNull(xmlWriter); - } - - /** Writes the given key code map in XML format to the provided writer. */ - public static void writeToXml(KeycodeMap keycodeMap, Platform platform, Writer writer) { - XmlWriter xmlWriter = XmlWriter.newXmlWriter(writer); - KeycodeMapToXml keycodeMapToXml = new KeycodeMapToXml(keycodeMap, platform, xmlWriter); - keycodeMapToXml.toXml(); - } - - private void toXml() { - xmlWriter.startDocument("platform", "../dtd/ldmlPlatform.dtd"); - xmlWriter.startElement("platform", ImmutableMap.of("id", platform)); - xmlWriter.startElement("hardwareMap"); - for (Entry entry : keycodeMap.keycodeToIsoLayout().entrySet()) { - xmlWriter.addElement( - "map", ImmutableMap.of("keycode", entry.getKey(), "iso", entry.getValue())); - } - xmlWriter.endElement(); - xmlWriter.endElement(); - xmlWriter.endDocument(); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/XmlWriter.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/XmlWriter.java deleted file mode 100644 index 50c0e5cc279..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/out/XmlWriter.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.unicode.cldr.draft.keyboard.out; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import com.google.common.collect.ImmutableMap; -import java.io.Writer; -import java.util.Map; -import java.util.Map.Entry; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; - -/** - * Object which wraps around an XML stream writer. Automatically adds proper formatting (indentation - * and line breaks) to the written XML elements. - */ -final class XmlWriter { - private final XMLStreamWriter writer; - private int depth = 0; - - private XmlWriter(XMLStreamWriter writer) { - this.writer = checkNotNull(writer); - } - - static XmlWriter newXmlWriter(Writer writer) { - XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - XMLStreamWriter xmlStreamWriter; - try { - xmlStreamWriter = outputFactory.createXMLStreamWriter(writer); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - return new XmlWriter(xmlStreamWriter); - } - - XmlWriter startDocument(String doctype, String dtdLocation) { - try { - writer.writeStartDocument("UTF-8", "1.0"); - writer.writeCharacters("\n"); - writer.writeDTD(""); - writer.writeCharacters("\n"); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - return this; - } - - XmlWriter endDocument() { - checkState(depth == 0, "Cannot close document with unclosed elements"); - try { - writer.writeEndDocument(); - writer.close(); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - return this; - } - - XmlWriter startElement(String name) { - return startElement(name, ImmutableMap.of()); - } - - XmlWriter startElement(String name, Map attributeToValue) { - addIndent(); - try { - writer.writeStartElement(name); - for (Entry entry : attributeToValue.entrySet()) { - writer.writeAttribute(entry.getKey(), "" + entry.getValue()); - } - writer.writeCharacters("\n"); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - depth++; - return this; - } - - XmlWriter endElement() { - depth--; - addIndent(); - try { - writer.writeEndElement(); - writer.writeCharacters("\n"); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - return this; - } - - XmlWriter addElement(String name, Map attributeToValue) { - return addElement(name, attributeToValue, ""); - } - - XmlWriter addElement(String name, Map attributeToValue, String comment) { - addIndent(); - try { - writer.writeEmptyElement(name); - for (Entry entry : attributeToValue.entrySet()) { - writer.writeAttribute(entry.getKey(), "" + entry.getValue()); - } - if (!comment.isEmpty()) { - writer.writeCharacters(" "); - writer.writeComment(" " + comment + " "); - } - writer.writeCharacters("\n"); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - return this; - } - - private void addIndent() { - for (int i = 0; i < depth; i++) { - try { - writer.writeCharacters("\t"); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/CharacterMapTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/CharacterMapTest.java deleted file mode 100644 index aec9c6c5225..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/CharacterMapTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import static org.unicode.cldr.draft.keyboard.IsoLayoutPosition.A03; -import static org.unicode.cldr.draft.keyboard.IsoLayoutPosition.B00; -import static org.unicode.cldr.draft.keyboard.IsoLayoutPosition.B01; -import static org.unicode.cldr.draft.keyboard.IsoLayoutPosition.B04; - -import com.google.common.collect.ImmutableList; -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.CharacterMap; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; - -public class CharacterMapTest extends TestFmwk { - - public void testCharacterMap() { - ImmutableList longPress = ImmutableList.of("a", "b", "c"); - CharacterMap character = CharacterMap.of(B04, "a", longPress); - assertEquals("", B04, character.position()); - assertEquals("", "a", character.output()); - assertEquals("", ImmutableList.of("a", "b", "c"), character.longPressKeys()); - } - - public void testCompareTo() { - CharacterMap character1 = CharacterMap.of(B00, "test1"); - CharacterMap character2 = CharacterMap.of(B01, "test2"); - CharacterMap character3 = CharacterMap.of(A03, "test3"); - CharacterMap character4 = CharacterMap.of(A03, "test4"); - - // Between rows (B00 < A03) - int result = character1.compareTo(character3); - assertTrue("", result < 0); - - // Between columns (B00 < B01) - result = character1.compareTo(character2); - assertTrue("", result < 0); - - // Equal (A03 == A03) - result = character3.compareTo(character4); - assertTrue("", result == 0); - } - - public void testEqualsTrue() { - CharacterMap characterMap1 = - CharacterMap.of(IsoLayoutPosition.A01, "Output", ImmutableList.of("A", "B")); - CharacterMap characterMap2 = - CharacterMap.of(IsoLayoutPosition.A01, "Output", ImmutableList.of("A", "B")); - - assertTrue("", characterMap1.equals(characterMap2)); - assertTrue("", characterMap1.hashCode() == characterMap2.hashCode()); - } - - public void testEqualsFalse() { - CharacterMap characterMap1 = - CharacterMap.of(IsoLayoutPosition.A01, "Output", ImmutableList.of("A", "B")); - CharacterMap characterMap2 = CharacterMap.of(IsoLayoutPosition.A01, "Output"); - - assertFalse("", characterMap1.equals(characterMap2)); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/IsoLayoutPositionTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/IsoLayoutPositionTest.java deleted file mode 100644 index 84e000e2fe7..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/IsoLayoutPositionTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; - -public class IsoLayoutPositionTest extends TestFmwk { - public void testForPosition() { - IsoLayoutPosition position = IsoLayoutPosition.forPosition('C', 6); - assertEquals("", IsoLayoutPosition.C06, position); - } - - public void testForPositionWithInvalidRow() { - try { - IsoLayoutPosition.forPosition('F', 6); - fail(); - } catch (IllegalArgumentException e) { - // Expected behavior - } - } - - public void testForPositionWithInvalidColumn() { - try { - IsoLayoutPosition.forPosition('A', 14); - fail(); - } catch (IllegalArgumentException e) { - // Expected behavior - } - } - - public void testForPositionWithMissingEntry() { - try { - IsoLayoutPosition.forPosition('A', 9); - fail(); - } catch (IllegalArgumentException e) { - // Expected behavior - } - } - - public void testToStringWithLeadingZero() { - String string = IsoLayoutPosition.A02.toString(); - assertEquals("", "A02", string); - } - - public void testIsoLayoutPosition() { - IsoLayoutPosition position = IsoLayoutPosition.D01; - assertEquals("", "Q", position.englishKeyName()); - assertEquals("", 'D', position.row()); - assertEquals("", 1, position.column()); - } - - public void testIsoLayoutPositionForNonUsKey() { - IsoLayoutPosition position = IsoLayoutPosition.B00; - assertEquals("", "(key to left of Z)", position.englishKeyName()); - assertEquals("", 'B', position.row()); - assertEquals("", 0, position.column()); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyMapTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyMapTest.java deleted file mode 100644 index ec07c3405c1..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyMapTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.ibm.icu.dev.test.TestFmwk; -import java.util.EnumSet; -import org.unicode.cldr.draft.keyboard.CharacterMap; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.KeyMap; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombinationSet; - -public class KeyMapTest extends TestFmwk { - private KeyMap keyMap = createKeyMap(); - - private static KeyMap createKeyMap() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL), - ImmutableSet.of(ModifierKey.OPTION_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - CharacterMap characterMap1 = - CharacterMap.of( - IsoLayoutPosition.C03, "A", ImmutableList.of("$", "%", "\uD800\uDE80")); - CharacterMap characterMap2 = CharacterMap.of(IsoLayoutPosition.C02, "S"); - return KeyMap.of(combinationSet, ImmutableSet.of(characterMap1, characterMap2)); - } - - public void testModifierKeyCombinationSet() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.CONTROL), EnumSet.of(ModifierKey.OPTION_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(EnumSet.of(ModifierKey.SHIFT)); - ModifierKeyCombinationSet combinationSetTest = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - assertEquals("", combinationSetTest, keyMap.modifierKeyCombinationSet()); - } - - public void testIsoLayoutToCharacterMap() { - CharacterMap characterMap1 = - CharacterMap.of( - IsoLayoutPosition.C03, "A", ImmutableList.of("$", "%", "\uD800\uDE80")); - CharacterMap characterMap2 = CharacterMap.of(IsoLayoutPosition.C02, "S"); - ImmutableMap isoLayoutToCharacterMap = - ImmutableMap.of( - IsoLayoutPosition.C03, characterMap1, IsoLayoutPosition.C02, characterMap2); - assertEquals("", isoLayoutToCharacterMap, keyMap.isoLayoutToCharacterMap()); - } - - public void testEqualsFalse() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL), - ImmutableSet.of(ModifierKey.OPTION_RIGHT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - CharacterMap characterMap1 = - CharacterMap.of(IsoLayoutPosition.C03, "B", ImmutableList.of("$", "%")); - CharacterMap characterMap2 = CharacterMap.of(IsoLayoutPosition.C02, "W"); - KeyMap keyMapTest = - KeyMap.of(combinationSet, ImmutableSet.of(characterMap1, characterMap2)); - assertFalse("", keyMap.equals(keyMapTest)); - assertNotSame("", keyMapTest.hashCode(), keyMap.hashCode()); - } - - public void testEqualsTrue() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL), - ImmutableSet.of(ModifierKey.OPTION_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(EnumSet.of(ModifierKey.SHIFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - CharacterMap characterMap1 = - CharacterMap.of( - IsoLayoutPosition.C03, "A", ImmutableList.of("$", "%", "\uD800\uDE80")); - CharacterMap characterMap2 = CharacterMap.of(IsoLayoutPosition.C02, "S"); - KeyMap keyMapTest = - KeyMap.of(combinationSet, ImmutableSet.of(characterMap1, characterMap2)); - assertTrue("", keyMap.equals(keyMapTest)); - assertEquals("", keyMapTest.hashCode(), keyMap.hashCode()); - } - - public void testCompareToGreater() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys(EnumSet.noneOf(ModifierKey.class)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination)); - KeyMap keyMapTest = KeyMap.of(combinationSet, ImmutableSet.of()); - assertTrue("", keyMap.compareTo(keyMapTest) > 0); - } - - public void testCompareToLess() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys(EnumSet.of(ModifierKey.COMMAND)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination)); - KeyMap keyMapTest = KeyMap.of(combinationSet, ImmutableSet.of()); - assertTrue("", keyMap.compareTo(keyMapTest) < 0); - } - - public void testCompareTo_equals() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.CONTROL), EnumSet.of(ModifierKey.OPTION_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(EnumSet.of(ModifierKey.SHIFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - KeyMap keyMapTest = KeyMap.of(combinationSet, ImmutableSet.of()); - assertEquals("", 0, keyMap.compareTo(keyMapTest)); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardIdTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardIdTest.java deleted file mode 100644 index 237ca412f54..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardIdTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableList; -import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.util.ULocale; -import org.unicode.cldr.draft.keyboard.KeyboardId; - -/** Unit tests for {@link KeyboardId}. */ -public class KeyboardIdTest extends TestFmwk { - - public void testKeyboardId() { - KeyboardId id = KeyboardId.fromString("de-CH-t-k0-windows-extended-var"); - assertEquals("", ULocale.forLanguageTag("de-CH"), id.locale()); - assertEquals("", KeyboardId.Platform.WINDOWS, id.platform()); - ImmutableList attributes = ImmutableList.of("extended", "var"); - assertEquals("", attributes, id.attributes()); - } - - public void testFromStringForSimple() { - KeyboardId keyboardLocale = KeyboardId.fromString("bn-t-k0-windows"); - assertEquals("", "bn-t-k0-windows", keyboardLocale.toString()); - } - - public void testFromStringForComplex() { - KeyboardId keyboardLocale = KeyboardId.fromString("es-US-t-k0-android-768dpi.xml"); - assertEquals("", "es-US-t-k0-android-768dpi.xml", keyboardLocale.toString()); - } - - public void testFromStringForInvalid() { - try { - KeyboardId.fromString("en-US-android"); - fail(); - } catch (IllegalArgumentException e) { - // Expected behavior. - } - } - - public void testEqualsTrue() { - KeyboardId id1 = KeyboardId.fromString("de-CH-t-k0-windows-extended-var"); - KeyboardId id2 = KeyboardId.fromString("de-CH-t-k0-windows-extended-var"); - assertTrue("", id1.equals(id2)); - assertTrue("", id1.hashCode() == id2.hashCode()); - } - - public void testEqualsFalse() { - KeyboardId id1 = KeyboardId.fromString("de-CH-t-k0-windows-extended-var"); - KeyboardId id2 = KeyboardId.fromString("es-US-t-k0-android-768dpi.xml"); - assertFalse("", id1.equals(id2)); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardSettingsTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardSettingsTest.java deleted file mode 100644 index 81b5bb6de92..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardSettingsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.KeyboardSettings; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.FallbackSetting; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformFailureSetting; -import org.unicode.cldr.draft.keyboard.KeyboardSettings.TransformPartialSetting; - -public class KeyboardSettingsTest extends TestFmwk { - - public void testKeyboardSettings() { - KeyboardSettings settings = - KeyboardSettings.of( - FallbackSetting.BASE, - TransformFailureSetting.EMIT, - TransformPartialSetting.SHOW); - assertEquals("", FallbackSetting.BASE, settings.fallbackSetting()); - assertEquals("", TransformFailureSetting.EMIT, settings.transformFailureSetting()); - assertEquals("", TransformPartialSetting.SHOW, settings.transformPartialSetting()); - } - - public void testEqualsTrue() { - KeyboardSettings settings1 = - KeyboardSettings.of( - FallbackSetting.BASE, - TransformFailureSetting.EMIT, - TransformPartialSetting.SHOW); - KeyboardSettings settings2 = - KeyboardSettings.of( - FallbackSetting.BASE, - TransformFailureSetting.EMIT, - TransformPartialSetting.SHOW); - assertTrue("", settings1.equals(settings2)); - assertTrue("", settings1.hashCode() == settings2.hashCode()); - } - - public void testEqualsFalse() { - KeyboardSettings settings1 = - KeyboardSettings.of( - FallbackSetting.NONE, - TransformFailureSetting.EMIT, - TransformPartialSetting.SHOW); - KeyboardSettings settings2 = - KeyboardSettings.of( - FallbackSetting.BASE, - TransformFailureSetting.EMIT, - TransformPartialSetting.SHOW); - assertFalse("", settings1.equals(settings2)); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardTest.java deleted file mode 100644 index 9944fa9549b..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeyboardTest.java +++ /dev/null @@ -1,209 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.util.ULocale; -import java.util.EnumSet; -import org.unicode.cldr.draft.keyboard.CharacterMap; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.KeyMap; -import org.unicode.cldr.draft.keyboard.Keyboard; -import org.unicode.cldr.draft.keyboard.KeyboardId; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombinationSet; -import org.unicode.cldr.draft.keyboard.Transform; - -public class KeyboardTest extends TestFmwk { - private Keyboard keyboard = createKeyboard(); - - private static Keyboard createKeyboard() { - // Base key map. - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of()); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - CharacterMap characterMap1 = CharacterMap.of(IsoLayoutPosition.E02, "ě"); - CharacterMap characterMap2 = - CharacterMap.of(IsoLayoutPosition.E03, "š", ImmutableList.of("ç %")); - CharacterMap characterMap3 = CharacterMap.of(IsoLayoutPosition.D10, "¨"); - KeyMap keyMap1 = - KeyMap.of( - combinationSet1, - ImmutableSet.of(characterMap1, characterMap2, characterMap3)); - - // Option key map. - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.OPTION)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION, ModifierKey.SHIFT), - ImmutableSet.of(ModifierKey.CAPSLOCK)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination2, combination3)); - CharacterMap characterMap4 = CharacterMap.of(IsoLayoutPosition.C01, "ä"); - CharacterMap characterMap5 = - CharacterMap.of(IsoLayoutPosition.C03, "ß", ImmutableList.of("Ð")); - CharacterMap characterMap6 = CharacterMap.of(IsoLayoutPosition.C10, "\u0302"); - KeyMap keyMap2 = - KeyMap.of( - combinationSet2, - ImmutableSet.of(characterMap4, characterMap5, characterMap6)); - - // Transforms. - ImmutableSortedSet transforms = - ImmutableSortedSet.of( - Transform.of("¨ß", "\uD800\uDE80"), - Transform.of("¨š", "s"), - Transform.of("\u0302ß", "\u0305a")); - - return Keyboard.of( - KeyboardId.fromString("cs-t-k0-osx-qwerty"), - ImmutableList.of("Czech-QWERTY"), - ImmutableSortedSet.of(keyMap1, keyMap2), - transforms); - } - - public void testKeyboardId() { - KeyboardId id = keyboard.keyboardId(); - KeyboardId testId = - KeyboardId.of( - ULocale.forLanguageTag("cs"), Platform.OSX, ImmutableList.of("qwerty")); - assertEquals("", testId, id); - } - - public void testNames() { - ImmutableList names = keyboard.names(); - assertEquals("", ImmutableList.of("Czech-QWERTY"), names); - } - - public void testKeyMaps() { - // Base key map. - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of()); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - CharacterMap characterMap1 = CharacterMap.of(IsoLayoutPosition.E02, "ě"); - CharacterMap characterMap2 = - CharacterMap.of(IsoLayoutPosition.E03, "š", ImmutableList.of("ç %")); - CharacterMap characterMap3 = CharacterMap.of(IsoLayoutPosition.D10, "¨"); - KeyMap keyMap1 = - KeyMap.of( - combinationSet1, - ImmutableSet.of(characterMap1, characterMap2, characterMap3)); - - // Option key map. - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.OPTION)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION, ModifierKey.SHIFT), - ImmutableSet.of(ModifierKey.CAPSLOCK)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination2, combination3)); - CharacterMap characterMap4 = CharacterMap.of(IsoLayoutPosition.C01, "ä"); - CharacterMap characterMap5 = - CharacterMap.of(IsoLayoutPosition.C03, "ß", ImmutableList.of("Ð")); - CharacterMap characterMap6 = CharacterMap.of(IsoLayoutPosition.C10, "\u0302"); - KeyMap keyMap2 = - KeyMap.of( - combinationSet2, - ImmutableSet.of(characterMap4, characterMap5, characterMap6)); - - assertEquals("", ImmutableSet.of(keyMap1, keyMap2), keyboard.keyMaps()); - } - - public void testTransforms() { - ImmutableSet transforms = - ImmutableSet.of( - Transform.of("¨ß", "\uD800\uDE80"), - Transform.of("¨š", "s"), - Transform.of("\u0302ß", "\u0305a")); - assertEquals("", transforms, keyboard.transforms()); - } - - public void testEqualsTrue() { - KeyboardId id = - KeyboardId.of( - ULocale.forLanguageTag("cs"), Platform.OSX, ImmutableList.of("qwerty")); - // Base key map. - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of()); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - CharacterMap characterMap1 = CharacterMap.of(IsoLayoutPosition.E02, "ě"); - CharacterMap characterMap2 = - CharacterMap.of(IsoLayoutPosition.E03, "š", ImmutableList.of("ç %")); - CharacterMap characterMap3 = CharacterMap.of(IsoLayoutPosition.D10, "¨"); - KeyMap keyMap1 = - KeyMap.of( - combinationSet1, - ImmutableSet.of(characterMap1, characterMap2, characterMap3)); - // Option key map. - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.OPTION)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION, ModifierKey.SHIFT), - ImmutableSet.of(ModifierKey.CAPSLOCK)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination2, combination3)); - CharacterMap characterMap4 = CharacterMap.of(IsoLayoutPosition.C01, "ä"); - CharacterMap characterMap5 = - CharacterMap.of(IsoLayoutPosition.C03, "ß", ImmutableList.of("Ð")); - CharacterMap characterMap6 = CharacterMap.of(IsoLayoutPosition.C10, "\u0302"); - KeyMap keyMap2 = - KeyMap.of( - combinationSet2, - ImmutableSet.of(characterMap4, characterMap5, characterMap6)); - - // Transforms. - ImmutableSortedSet transforms = - ImmutableSortedSet.of( - Transform.of("¨ß", "\uD800\uDE80"), - Transform.of("¨š", "s"), - Transform.of("\u0302ß", "\u0305a")); - - Keyboard keyboard2 = - Keyboard.of( - id, - ImmutableList.of("Czech-QWERTY"), - ImmutableSortedSet.of(keyMap1, keyMap2), - transforms); - - assertTrue("", keyboard.equals(keyboard2)); - assertEquals("", keyboard2.hashCode(), keyboard.hashCode()); - } - - public void testEqualsFalse() { - KeyboardId id = - KeyboardId.of( - ULocale.forLanguageTag("cs"), Platform.OSX, ImmutableList.of("qwerty")); - - // Base key map - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(EnumSet.noneOf(ModifierKey.class)); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - CharacterMap characterMap1 = CharacterMap.of(IsoLayoutPosition.E02, "ě"); - CharacterMap characterMap2 = - CharacterMap.of(IsoLayoutPosition.E03, "š", ImmutableList.of("ç %")); - KeyMap keyMap1 = KeyMap.of(combinationSet1, ImmutableSet.of(characterMap1, characterMap2)); - - // Transforms - ImmutableSortedSet emptyTransforms = ImmutableSortedSet.of(); - - Keyboard keyboard2 = - Keyboard.of( - id, - ImmutableList.of("Czech-QWERTY"), - ImmutableSortedSet.of(keyMap1), - emptyTransforms); - - assertFalse("", keyboard.equals(keyboard2)); - assertNotSame("", keyboard2.hashCode(), keyboard.hashCode()); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeycodeMapTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeycodeMapTest.java deleted file mode 100644 index 0977dfa8b58..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/KeycodeMapTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.KeycodeMap; - -public class KeycodeMapTest extends TestFmwk { - public void testGetIsoLayoutPosition() { - String csv = "keycode,iso\n50,E03\n80,D10\n4,B00"; - KeycodeMap mapping = KeycodeMap.fromCsv(csv); - assertEquals("", IsoLayoutPosition.E03, mapping.getIsoLayoutPosition(50)); - } - - public void testGetIsoLayoutPositionForMissingValue() { - String csv = "keycode,iso\n50,E03\n80,D10\n4,B00"; - KeycodeMap mapping = KeycodeMap.fromCsv(csv); - try { - mapping.getIsoLayoutPosition(100); - fail(); - } catch (NullPointerException e) { - // Expected behavior - } - } - - public void testFromCsvMissingHeaders() { - String csv = "50,E03\n4,B00"; - try { - KeycodeMap.fromCsv(csv); - fail(); - } catch (IllegalArgumentException e) { - // Expected behavior - } - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationSetTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationSetTest.java deleted file mode 100644 index b140e4f3aa6..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationSetTest.java +++ /dev/null @@ -1,290 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Lists; -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombinationSet; - -public class ModifierKeyCombinationSetTest extends TestFmwk { - - public void testOfWithSingleCombination() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of()); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination)); - assertEquals("", ImmutableSortedSet.of(combination), combinationSet.combinations()); - assertEquals("", "", combinationSet.toString()); - } - - public void testOfWithMultipleCombinations() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION_RIGHT, ModifierKey.CONTROL), - ImmutableSet.of(ModifierKey.COMMAND, ModifierKey.SHIFT_LEFT)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.CONTROL_LEFT, - ModifierKey.CONTROL_RIGHT, - ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.ALT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of( - ImmutableSet.of(combination1, combination2, combination3)); - assertEquals( - "", - ImmutableSortedSet.of(combination1, combination2, combination3), - combinationSet.combinations()); - assertEquals( - "", - "ctrlL+ctrlR+caps+alt? ctrl+optR+cmd?+shiftL? cmd+shift+ctrl?", - combinationSet.toString()); - } - - public void testOfWithSimplification() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.ALT_RIGHT, ModifierKey.COMMAND, ModifierKey.SHIFT_LEFT), - ImmutableSet.of(ModifierKey.SHIFT_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - ModifierKeyCombination simplifiedCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.SHIFT)); - assertEquals( - "", ImmutableSortedSet.of(simplifiedCombination), combinationSet.combinations()); - assertEquals("", "cmd+altR+shift?", combinationSet.toString()); - } - - public void testOfWithMultipleSimplifications() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.ALT_RIGHT, ModifierKey.COMMAND, ModifierKey.SHIFT_LEFT), - ImmutableSet.of(ModifierKey.SHIFT_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.ALT_LEFT)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombination combination4 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.CONTROL, ModifierKey.ALT_LEFT, ModifierKey.ALT_RIGHT)); - ModifierKeyCombination combination5 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.CAPSLOCK)); - ImmutableSet combinations = - ImmutableSet.of( - combination1, combination2, combination3, combination4, combination5); - ModifierKeyCombinationSet combinationSet = ModifierKeyCombinationSet.of(combinations); - ModifierKeyCombination simplifiedCombination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombination simplifiedCombination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.ALT_LEFT), - ImmutableSet.of(ModifierKey.ALT_RIGHT)); - assertEquals( - "", - ImmutableSortedSet.of(simplifiedCombination1, simplifiedCombination2, combination5), - combinationSet.combinations()); - assertEquals("", "caps ctrl+altL+altR? cmd+altR+shift?", combinationSet.toString()); - } - - public void testOfWithCascadingSimplifications() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.OPTION_LEFT, - ModifierKey.OPTION_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.OPTION_RIGHT)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), - ImmutableSet.of(ModifierKey.OPTION_LEFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of( - ImmutableSet.of(combination1, combination2, combination3)); - ModifierKeyCombination simplifiedCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), ImmutableSet.of(ModifierKey.OPTION)); - assertEquals( - "", ImmutableSortedSet.of(simplifiedCombination), combinationSet.combinations()); - assertEquals("", "shift+opt?", combinationSet.toString()); - } - - public void testCombine() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION_RIGHT, ModifierKey.CONTROL), - ImmutableSet.of(ModifierKey.COMMAND, ModifierKey.SHIFT_LEFT)); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CAPSLOCK, ModifierKey.OPTION), - ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination3)); - ModifierKeyCombinationSet finalSet = - ModifierKeyCombinationSet.combine( - Lists.newArrayList(combinationSet1, combinationSet2)); - assertEquals( - "", - ImmutableSortedSet.of(combination1, combination2, combination3), - finalSet.combinations()); - assertEquals( - "", "opt+caps+ctrl? ctrl+optR+cmd?+shiftL? cmd+shift+ctrl?", finalSet.toString()); - } - - public void testCompareToWithSimpleCombinations() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.COMMAND)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination2)); - assertTrue("", combinationSet1.compareTo(combinationSet2) < 0); - } - - public void testCompareToWithComplexCombinations() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CAPSLOCK, ModifierKey.SHIFT_RIGHT), - ImmutableSet.of(ModifierKey.ALT)); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION_RIGHT, ModifierKey.CONTROL), - ImmutableSet.of(ModifierKey.COMMAND, ModifierKey.SHIFT_LEFT)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination3)); - assertTrue("", combinationSet1.compareTo(combinationSet2) < 0); - } - - public void testCompareToWithDifferentSizeCombinations() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombinationSet combinationSet1 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.COMMAND, ModifierKey.SHIFT_RIGHT), - ImmutableSet.of(ModifierKey.ALT)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombinationSet combinationSet2 = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination2, combination3)); - assertTrue("", combinationSet1.compareTo(combinationSet2) < 0); - } - - public void testIsBaseForSimpleCombinations() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of()); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination)); - assertTrue("", combinationSet.isBase()); - } - - public void testIsBaseForComplexCombinations() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(), - ImmutableSet.of( - ModifierKey.COMMAND, ModifierKey.ALT_LEFT, ModifierKey.CONTROL)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - assertTrue("", combinationSet.isBase()); - } - - public void testIsBaseFalse() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - assertFalse("", combinationSet.isBase()); - } - - public void testEqualsTrue() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - ModifierKeyCombination combinationTest1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombination combinationTest2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - ModifierKeyCombinationSet combinationSetTest = - ModifierKeyCombinationSet.of(ImmutableSet.of(combinationTest1, combinationTest2)); - assertTrue("", combinationSet.equals(combinationSetTest)); - assertEquals("", combinationSet.hashCode(), combinationSetTest.hashCode()); - } - - public void testEqualsFalse() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - ModifierKeyCombinationSet combinationSet = - ModifierKeyCombinationSet.of(ImmutableSet.of(combination1, combination2)); - ModifierKeyCombination combinationTest1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ModifierKeyCombination combinationTest2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - ModifierKeyCombinationSet combinationSetTest = - ModifierKeyCombinationSet.of(ImmutableSet.of(combinationTest1, combinationTest2)); - assertFalse("", combinationSet.equals(combinationSetTest)); - assertNotSame("", combinationSet.hashCode(), combinationSetTest.hashCode()); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationTest.java deleted file mode 100644 index b9f950b0137..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyCombinationTest.java +++ /dev/null @@ -1,324 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableSet; -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; - -public class ModifierKeyCombinationTest extends TestFmwk { - - public void testOfOnKeysForSimpleCombination() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - ImmutableSet onKeys = ImmutableSet.of(ModifierKey.SHIFT); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.CONTROL, - ModifierKey.OPTION, - ModifierKey.ALT, - ModifierKey.COMMAND, - ModifierKey.CAPSLOCK); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "shift", combination.toString()); - } - - public void testOfOnKeysForComplexCombination() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.CONTROL, - ModifierKey.ALT_RIGHT, - ModifierKey.CAPSLOCK)); - ImmutableSet onKeys = - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.ALT_RIGHT, - ModifierKey.CAPSLOCK, - ModifierKey.CONTROL); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of(ModifierKey.ALT_LEFT, ModifierKey.OPTION, ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "ctrl+altR+caps+shift", combination.toString()); - } - - public void testOfOnKeysForComplexCombinationWithVariant() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.SHIFT_RIGHT, - ModifierKey.ALT_RIGHT, - ModifierKey.CAPSLOCK)); - ImmutableSet onKeys = - ImmutableSet.of( - ModifierKey.SHIFT_RIGHT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.CONTROL, - ModifierKey.ALT_LEFT, - ModifierKey.OPTION, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "altR+caps+shiftR+shiftL?", combination.toString()); - } - - public void testOfOnAndDontCareKeysForSimpleCombination() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.COMMAND), - ImmutableSet.of(ModifierKey.OPTION_LEFT)); - ImmutableSet onKeys = ImmutableSet.of(ModifierKey.COMMAND); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.CONTROL, - ModifierKey.ALT, - ModifierKey.CONTROL, - ModifierKey.OPTION_RIGHT, - ModifierKey.SHIFT, - ModifierKey.CAPSLOCK); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "cmd+optL?", combination.toString()); - } - - public void testOfOnAndDontCareKeys_complex() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.ALT, ModifierKey.COMMAND)); - ImmutableSet onKeys = - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.CAPSLOCK); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = ImmutableSet.of(ModifierKey.OPTION); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "ctrl+caps+shift+cmd?+alt?", combination.toString()); - } - - public void testOfOnAndDontCareKeysForComplexCombinationWithVariant() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.CAPSLOCK), - ImmutableSet.of( - ModifierKey.ALT, ModifierKey.ALT_RIGHT, ModifierKey.COMMAND)); - ImmutableSet onKeys = - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.CAPSLOCK); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of(ModifierKey.OPTION, ModifierKey.ALT_LEFT); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "ctrl+caps+shift+cmd?+altR?", combination.toString()); - } - - public void testOfOnAndDontCareKeys_empty() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(), ImmutableSet.of()); - assertEquals("", ImmutableSet.of(), combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.OPTION, - ModifierKey.SHIFT, - ModifierKey.CONTROL, - ModifierKey.ALT, - ModifierKey.CAPSLOCK, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - assertEquals("", "", combination.toString()); - } - - public void testEqualsTrue() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - assertTrue("", combination1.equals(combination2)); - assertTrue("", combination1.hashCode() == combination2.hashCode()); - } - - public void testEqualsWithDontCareTrue() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.COMMAND)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.COMMAND)); - assertTrue("", combination1.equals(combination2)); - assertTrue("", combination1.hashCode() == combination2.hashCode()); - } - - public void testEqualsFalse() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.ALT_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND)); - assertFalse("", combination1.equals(combination2)); - assertTrue("", combination1.hashCode() != combination2.hashCode()); - } - - public void testEqualsWithDontCareFalse() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), ImmutableSet.of(ModifierKey.ALT_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.COMMAND)); - assertFalse("", combination1.equals(combination2)); - assertTrue("", combination1.hashCode() != combination2.hashCode()); - } - - public void testCompareToForOnKeys() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.OPTION)); - // Expected: [caps, opt] - assertTrue("", combination1.compareTo(combination2) < 0); - } - - public void testCompareToForCloseOnKeys() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - // Expected: [altR+caps, altR+caps+shift] - assertTrue("", combination1.compareTo(combination2) < 0); - } - - public void testCompareToForComplexOnKeys() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.CONTROL_LEFT, ModifierKey.OPTION)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.OPTION)); - // Expected: [ctrlL+opt, ctrl+opt+shift] - assertTrue("", combination1.compareTo(combination2) < 0); - } - - public void testCompareToForLeftAndRightVariants() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.CONTROL_LEFT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.CONTROL_RIGHT)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.CONTROL)); - // Expected: [ctrlR, ctrlL, ctrl] - assertTrue("", combination1.compareTo(combination2) > 0); - assertTrue("", combination1.compareTo(combination3) < 0); - assertTrue("", combination2.compareTo(combination3) < 0); - } - - public void testCompareToForEqualCombinations() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - assertTrue("", combination1.compareTo(combination2) == 0); - } - - public void testCompareToWithDontCares() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION), ImmutableSet.of(ModifierKey.CONTROL)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.OPTION), ImmutableSet.of(ModifierKey.COMMAND)); - // Expected: [opt+ctrl?, opt+cmd?] - assertTrue("", combination1.compareTo(combination2) < 0); - } - - public void testCompareToWithCloseDontCares() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT), - ImmutableSet.of(ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.ALT_RIGHT)); - // Expected: [altR altR+caps?] - assertTrue("", combination1.compareTo(combination2) > 0); - } - - public void testCompareToWithComplexDontCares() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT), - ImmutableSet.of(ModifierKey.CONTROL_LEFT, ModifierKey.OPTION)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_RIGHT), - ImmutableSet.of( - ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.OPTION)); - // Expected: [altR+ctrlL?+opt?, altR+ctrl?+opt?+shift?] - assertTrue("", combination1.compareTo(combination2) < 0); - } - - public void testCompareToWithLeftRightVariantDontCares() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), - ImmutableSet.of(ModifierKey.CONTROL_LEFT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), - ImmutableSet.of(ModifierKey.CONTROL_RIGHT)); - ModifierKeyCombination combination3 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT), ImmutableSet.of(ModifierKey.CONTROL)); - // Expected: [shift+ctrlR?, shift+ctrlL?, shift+ctrl?] - assertTrue("", combination1.compareTo(combination2) > 0); - assertTrue("", combination1.compareTo(combination3) < 0); - assertTrue("", combination2.compareTo(combination3) < 0); - } - - public void testCompareToWithEqualDontCares() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.COMMAND), - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.COMMAND), - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - assertTrue("", combination1.compareTo(combination2) == 0); - } - - public void testIsBaseCombinationTrue() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(), - ImmutableSet.of( - ModifierKey.COMMAND, ModifierKey.ALT_LEFT, ModifierKey.CONTROL)); - assertTrue("", combination.isBase()); - } - - public void testIsBaseCombinationFalse() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - assertFalse("", combination.isBase()); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeySimplifierTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeySimplifierTest.java deleted file mode 100644 index b2a44d11b2a..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeySimplifierTest.java +++ /dev/null @@ -1,455 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableSet; -import com.ibm.icu.dev.test.TestFmwk; -import java.util.EnumSet; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; -import org.unicode.cldr.draft.keyboard.ModifierKeySimplifier; - -public class ModifierKeySimplifierTest extends TestFmwk { - private static ImmutableSet EMPTY_SET = ImmutableSet.of(); - - public void testSimplifyInputWithOverlappingSets() { - try { - ModifierKeySimplifier.simplifyInput( - ImmutableSet.of(ModifierKey.ALT_LEFT, ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.ALT_LEFT)); - fail(); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testSimplifyInputWithBase() { - ModifierKeyCombination combination = ModifierKeyCombination.ofOnKeys(EMPTY_SET); - assertTrue("", combination.onKeys().isEmpty()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.CONTROL, - ModifierKey.ALT, - ModifierKey.OPTION, - ModifierKey.SHIFT, - ModifierKey.COMMAND, - ModifierKey.CAPSLOCK); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithParentOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.ALT, ModifierKey.CAPSLOCK)); - ImmutableSet onKeys = ImmutableSet.of(ModifierKey.ALT, ModifierKey.CAPSLOCK); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.CONTROL, - ModifierKey.OPTION, - ModifierKey.SHIFT, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithChildOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.OPTION_LEFT, ModifierKey.COMMAND)); - ImmutableSet onKeys = - ImmutableSet.of(ModifierKey.OPTION_LEFT, ModifierKey.COMMAND); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.ALT, - ModifierKey.CONTROL, - ModifierKey.OPTION_RIGHT, - ModifierKey.SHIFT, - ModifierKey.CAPSLOCK); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithBothChildrenOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT_LEFT, ModifierKey.SHIFT_RIGHT)); - ImmutableSet onKeys = - ImmutableSet.of(ModifierKey.SHIFT_LEFT, ModifierKey.SHIFT_RIGHT); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.ALT, - ModifierKey.CONTROL, - ModifierKey.OPTION, - ModifierKey.CAPSLOCK, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithParentDontCare() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EMPTY_SET, ImmutableSet.of(ModifierKey.SHIFT)); - assertEquals("", EMPTY_SET, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.ALT, - ModifierKey.CONTROL, - ModifierKey.OPTION, - ModifierKey.CAPSLOCK, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithParentDontCareAndChildOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.ALT_LEFT), ImmutableSet.of(ModifierKey.ALT)); - ImmutableSet onKeys = ImmutableSet.of(ModifierKey.ALT_LEFT); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.CONTROL, - ModifierKey.OPTION, - ModifierKey.CAPSLOCK, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithChildDontCare() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EMPTY_SET, ImmutableSet.of(ModifierKey.CONTROL_RIGHT)); - assertEquals("", EMPTY_SET, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.CONTROL_LEFT, - ModifierKey.ALT, - ModifierKey.OPTION, - ModifierKey.CAPSLOCK, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyInputWithAllThreeKeysPresent() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.CONTROL_LEFT), - ImmutableSet.of(ModifierKey.CONTROL_RIGHT)); - ImmutableSet onKeys = ImmutableSet.of(ModifierKey.CONTROL_LEFT); - assertEquals("", onKeys, combination.onKeys()); - ImmutableSet offKeys = - ImmutableSet.of( - ModifierKey.SHIFT, - ModifierKey.ALT, - ModifierKey.OPTION, - ModifierKey.CAPSLOCK, - ModifierKey.COMMAND); - assertEquals("", offKeys, combination.offKeys()); - } - - public void testSimplifyToStringWithBase() { - ModifierKeyCombination combination = ModifierKeyCombination.ofOnKeys(EMPTY_SET); - assertEquals("", "", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithParentOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.ALT, ModifierKey.CAPSLOCK)); - assertEquals("", "alt+caps", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithChildOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.OPTION_LEFT, ModifierKey.COMMAND)); - assertEquals("", "cmd+optL", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithBothChildrenOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT_LEFT, ModifierKey.SHIFT_RIGHT)); - assertEquals("", "shiftL+shiftR", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithParentDontCare() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EMPTY_SET, ImmutableSet.of(ModifierKey.SHIFT)); - assertEquals("", "shift?", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithChildDontCareAndOn() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.SHIFT_LEFT), - ImmutableSet.of(ModifierKey.SHIFT_RIGHT)); - assertEquals("", "shiftL+shiftR?", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithChildDontCare() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EMPTY_SET, ImmutableSet.of(ModifierKey.OPTION_RIGHT)); - assertEquals("", "optR?", ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifyToStringWithComplexCombination() { - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of( - ModifierKey.CONTROL, ModifierKey.ALT_RIGHT, ModifierKey.COMMAND), - ImmutableSet.of( - ModifierKey.OPTION, ModifierKey.CAPSLOCK, ModifierKey.SHIFT_LEFT)); - assertEquals( - "", - "cmd+ctrl+altR+opt?+caps?+shiftL?", - ModifierKeySimplifier.simplifyToString(combination)); - } - - public void testSimplifySetWithIdentical() { - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.SHIFT_RIGHT)); - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - ImmutableSet.of(ModifierKey.CONTROL, ModifierKey.CAPSLOCK), - ImmutableSet.of(ModifierKey.SHIFT_RIGHT)); - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - assertEquals("", 1, result.size()); - assertEquals("", ImmutableSet.of(combination1), result); - } - - public void testSimplifySetWithSingleOnKey() { - // altR+shift+caps - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of( - ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CAPSLOCK)); - // altR+shift - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT)); - // 1 + 0 = ? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+caps? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CAPSLOCK)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithParentOnKey() { - // ctrl+altR+shift - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT, ModifierKey.CONTROL)); - // altR+shift - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT)); - // 1?? + 0?? = ??? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+ctrl? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CONTROL)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithSingleOffKey() { - // altR+shift - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT)); - // altR+shift+cmd? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.COMMAND)); - // 0 + ? = ? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+cmd? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.COMMAND)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithParentOffKey() { - // altR+shift - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT)); - // altR+shift+opt? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION)); - // 0?? + ??? = ??? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+opt? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithChildOnKey() { - // altR+shift+ctrlL - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of( - ModifierKey.SHIFT, - ModifierKey.ALT_RIGHT, - ModifierKey.CONTROL_LEFT)); - // altR+shift - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT)); - // ?10 + 0?? = ??0 - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+ctrlL? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CONTROL_LEFT)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithChildOffKey() { - // altR+shift - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT)); - // altR+shift+ctrlL? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CONTROL_LEFT)); - // 0?? + ??0 = ??0 - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+ctrlL? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CONTROL_LEFT)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithTwoDifferentChildrenDontCare() { - // altR+shift+ctrlR? - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CONTROL_RIGHT)); - // altR+shift+ctrlL? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.CONTROL_LEFT)); - // ??0 + ?0? = ??0 + ?0? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+ctrlL? altR+shift+ctrlR - assertEquals("", ImmutableSet.of(combination1, combination2), result); - } - - public void testSimplifySetWithTwoDifferentChildrenOn() { - // altR+shift+ctrlR? - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of( - ModifierKey.SHIFT, - ModifierKey.ALT_RIGHT, - ModifierKey.CONTROL_RIGHT)); - // altR+shift+ctrlL? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of( - ModifierKey.SHIFT, - ModifierKey.ALT_RIGHT, - ModifierKey.CONTROL_LEFT)); - // ?01 + ?10 = ?01 + ?10 - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // ctrlL+altR+shift ctrlR+altR+shift - assertEquals("", ImmutableSet.of(combination1, combination2), result); - } - - public void testSimplifySetWithParentDontCareAndChildOn() { - // altR+shift+opt? - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION)); - // altR+shift+optR - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnKeys( - EnumSet.of( - ModifierKey.SHIFT, - ModifierKey.ALT_RIGHT, - ModifierKey.OPTION_RIGHT)); - // ??? + ?01 = ??? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+opt? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION)); - assertEquals("", ImmutableSet.of(resultCombination), result); - } - - public void testSimplifySetWithParentDontCareAndChildDontCare() { - // altR+shift+opt? - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION)); - // altR+shift+optR? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION_RIGHT)); - // ??? + ?0? = ??? - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - // altR+shift+opt? - ModifierKeyCombination resultCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.OPTION)); - assertTrue("", result.contains(resultCombination)); - } - - public void testSimplifySetWithNoSimplification() { - // ctrl+shift+caps+opt? - ModifierKeyCombination combination1 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.CONTROL, ModifierKey.SHIFT, ModifierKey.CAPSLOCK), - EnumSet.of(ModifierKey.OPTION)); - // altR+shift+cmd? - ModifierKeyCombination combination2 = - ModifierKeyCombination.ofOnAndDontCareKeys( - EnumSet.of(ModifierKey.SHIFT, ModifierKey.ALT_RIGHT), - EnumSet.of(ModifierKey.COMMAND)); - ImmutableSet result = - ModifierKeySimplifier.simplifySet(ImmutableSet.of(combination1, combination2)); - assertEquals("", ImmutableSet.of(combination1, combination2), result); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyTest.java deleted file mode 100644 index 239e1d3b84c..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/ModifierKeyTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.google.common.collect.ImmutableList; -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.ModifierKey; - -public class ModifierKeyTest extends TestFmwk { - - public void testFromString() { - ModifierKey key = ModifierKey.fromString("shiftL"); - assertEquals("", ModifierKey.SHIFT_LEFT, key); - } - - public void testFromStringInvalid() { - try { - ModifierKey.fromString("bla"); - fail(); - } catch (IllegalArgumentException e) { - // Expected. - } - } - - public void testModifierKey() { - ModifierKey key = ModifierKey.COMMAND; - assertEquals("", ModifierKey.COMMAND, key.sibling()); - assertEquals("", ModifierKey.COMMAND, key.parent()); - assertEquals("", ImmutableList.of(), key.children()); - } - - public void testChildModifierKey() { - ModifierKey key = ModifierKey.CONTROL_RIGHT; - assertEquals("", ModifierKey.CONTROL_LEFT, key.sibling()); - assertEquals("", ModifierKey.CONTROL, key.parent()); - assertEquals("", ImmutableList.of(), key.children()); - } - - public void testParentModifierKey() { - ModifierKey key = ModifierKey.ALT; - assertEquals("", ModifierKey.ALT, key.sibling()); - assertEquals("", ModifierKey.ALT, key.parent()); - assertEquals( - "", ImmutableList.of(ModifierKey.ALT_LEFT, ModifierKey.ALT_RIGHT), key.children()); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/RunTests.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/RunTests.java deleted file mode 100644 index 276248bb4c9..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/RunTests.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import java.io.PrintWriter; -import org.unicode.cldr.draft.keyboard.test.windows.KlcParserTest; - -public final class RunTests { - - public static void main(String[] args) { - PrintWriter printWriter = new PrintWriter(System.out); - new CharacterMapTest().run(args, printWriter); - new IsoLayoutPositionTest().run(args, printWriter); - new KeyboardIdTest().run(args, printWriter); - new KeyboardSettingsTest().run(args, printWriter); - new KeyboardTest().run(args, printWriter); - new KeycodeMapTest().run(args, printWriter); - new KeyMapTest().run(args, printWriter); - new ModifierKeyCombinationSetTest().run(args, printWriter); - new ModifierKeyCombinationTest().run(args, printWriter); - new ModifierKeySimplifierTest().run(args, printWriter); - new ModifierKeyTest().run(args, printWriter); - new TransformTest().run(args, printWriter); - - // Windows. - new KlcParserTest().run(args, printWriter); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/TransformTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/TransformTest.java deleted file mode 100644 index 5467cb34036..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/TransformTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test; - -import com.ibm.icu.dev.test.TestFmwk; -import org.unicode.cldr.draft.keyboard.Transform; - -public class TransformTest extends TestFmwk { - - public void testTransform() { - Transform transform = Transform.of("^e", "ê"); - assertEquals("", "^e", transform.sequence()); - assertEquals("", "ê", transform.output()); - } - - public void testEqualsTrue() { - Transform transform1 = Transform.of("^e", "ê"); - Transform transform2 = Transform.of("^e", "ê"); - - assertTrue("", transform1.equals(transform2)); - assertTrue("", transform1.hashCode() == transform2.hashCode()); - } - - public void testEqualsFalse() { - Transform transform1 = Transform.of("^e", "ê"); - Transform transform2 = Transform.of("e^", "ê"); - - assertFalse("", transform1.equals(transform2)); - assertFalse("", transform1.hashCode() == transform2.hashCode()); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/windows/KlcParserTest.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/windows/KlcParserTest.java deleted file mode 100644 index 0f6f8280253..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/test/windows/KlcParserTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.unicode.cldr.draft.keyboard.test.windows; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import com.ibm.icu.dev.test.TestFmwk; -import java.io.IOException; -import org.unicode.cldr.draft.keyboard.windows.KlcParser; - -public class KlcParserTest extends TestFmwk { - - public void testParse() throws IOException { - String layout = - Resources.toString( - Resources.getResource(KlcParserTest.class, "test_layout.txt"), - Charsets.UTF_8); - System.out.println(KlcParser.parseLayout(layout)); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/windows/KlcParser.java b/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/windows/KlcParser.java deleted file mode 100644 index 9a4692fea79..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/draft/keyboard/windows/KlcParser.java +++ /dev/null @@ -1,369 +0,0 @@ -package org.unicode.cldr.draft.keyboard.windows; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.CharMatcher; -import com.google.common.base.Splitter; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import com.google.common.collect.Table; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; -import org.unicode.cldr.draft.keyboard.CharacterMap; -import org.unicode.cldr.draft.keyboard.IsoLayoutPosition; -import org.unicode.cldr.draft.keyboard.Keyboard; -import org.unicode.cldr.draft.keyboard.KeyboardBuilder; -import org.unicode.cldr.draft.keyboard.KeyboardId; -import org.unicode.cldr.draft.keyboard.KeyboardId.Platform; -import org.unicode.cldr.draft.keyboard.KeyboardIdMap; -import org.unicode.cldr.draft.keyboard.KeycodeMap; -import org.unicode.cldr.draft.keyboard.ModifierKey; -import org.unicode.cldr.draft.keyboard.ModifierKeyCombination; - -/** - * This class allows the parsing of Windows source keyboard files which are created by the Windows - * Keyboard Layout Creator application. These files are simply text files divided into sections. - * - *

          A typical layout file has multiple sections (always in the same order) with each section - * headed by a title in capital letters (eg. "LAYOUT"). Each of these sections are parsed - * independently of the others. - */ -public final class KlcParser { - public static final KeycodeMap KEYCODE_MAP = - KeycodeMap.fromResource(KlcParser.class, "windows-keycodes.csv"); - public static final KeyboardIdMap KEYBOARD_ID_MAP = - KeyboardIdMap.fromResource(KlcParser.class, "windows-locales.csv", Platform.WINDOWS); - - private static final Splitter WHITESPACE_SPLITTER = - Splitter.on(CharMatcher.whitespace()).omitEmptyStrings(); - private static final Splitter LINE_SPLITTER = - Splitter.on(CharMatcher.anyOf("\n\r")).omitEmptyStrings(); - - private final KeyboardBuilder builder; - private final String klcContents; - private final Table virtualKeyAndIndexPlaceToLigature; - private final Multimap indexToModifierKeyCombinations; - // Sorted list of the modifier indexes. Used when parsing the layout. - private final List modifierIndexes; - private int shiftIndex; - - private KlcParser(String klcContents) { - this.klcContents = checkNotNull(klcContents); - builder = new KeyboardBuilder(); - virtualKeyAndIndexPlaceToLigature = HashBasedTable.create(); - indexToModifierKeyCombinations = ArrayListMultimap.create(); - modifierIndexes = Lists.newArrayList(); - } - - public static ImmutableList parseLayout(String klcLayout) { - KlcParser parser = new KlcParser(klcLayout); - return parser.parse(); - } - - /** Parse the given klc layout contents and populate the keyboard builder. */ - private ImmutableList parse() { - parseNameAndId(); - parseModifiers(); - parseLigatures(); - // Dead keys has to come before layout since they are needed in the layout process. - parseDeadkeys(); - parseLayout(); - return builder.build(); - } - - private void parseNameAndId() { - // The descriptions section (containing the name) is bounded below by the languagenames - // section. - int descriptionsIndex = klcContents.indexOf("\nDESCRIPTIONS"); - int languageNamesIndex = klcContents.indexOf("\nLANGUAGENAMES"); - String section = klcContents.substring(descriptionsIndex, languageNamesIndex); - List lines = LINE_SPLITTER.splitToList(section); - checkArgument(lines.size() == 2, section); - // The name line always starts with a 4 digit number, then a tab followed by the actual - // name. - // eg. "0409 Canadian French - Custom" - String name = lines.get(1).substring(5).replace(" - Custom", "").trim(); - checkArgument(!name.isEmpty(), section); - builder.addName(name); - ImmutableCollection ids = KEYBOARD_ID_MAP.getKeyboardId(name); - builder.addKeyboardIds(ids); - } - - private void parseModifiers() { - // The modifiers section (shiftstate) is always bounded below by the layout section. - int shiftStateIndex = klcContents.indexOf("\nSHIFTSTATE"); - int layoutIndex = klcContents.indexOf("\nLAYOUT"); - String section = klcContents.substring(shiftStateIndex, layoutIndex); - List lines = LINE_SPLITTER.splitToList(section); - for (int i = 1; i < lines.size(); i++) { - List components = WHITESPACE_SPLITTER.splitToList(lines.get(i)); - Integer index = Integer.valueOf(components.get(0)); - Set modifiers = Sets.newHashSet(); - for (int j = 1; j < components.size(); j++) { - String token = components.get(j); - if (token.equals("Shft")) { - modifiers.add(ModifierKey.SHIFT); - } else if (token.equals("Alt")) { - modifiers.add(ModifierKey.ALT); - } else if (token.equals("Ctrl")) { - modifiers.add(ModifierKey.CONTROL); - } - } - ImmutableSet dontCareKeys = ImmutableSet.of(); - // Exception: If either Ctrl or Alt or both are present in a combination, add Caps as a - // don't care key - if (modifiers.contains(ModifierKey.ALT) || modifiers.contains(ModifierKey.CONTROL)) { - dontCareKeys = ImmutableSet.of(ModifierKey.CAPSLOCK); - } - modifierIndexes.add(index); - ModifierKeyCombination combination = - ModifierKeyCombination.ofOnAndDontCareKeys(modifiers, dontCareKeys); - indexToModifierKeyCombinations.put(index, combination); - if (combination.equals(SHIFT)) { - shiftIndex = index; - } - // Exception: If both Ctrl and Alt are present in a combination then a second equivalent - // combination of "AltR+Caps?" is added to the same index - if (modifiers.contains(ModifierKey.ALT) && modifiers.contains(ModifierKey.CONTROL)) { - Set keys = Sets.newHashSet(modifiers); - keys.remove(ModifierKey.ALT); - keys.remove(ModifierKey.CONTROL); - keys.add(ModifierKey.ALT_RIGHT); - ModifierKeyCombination rAltCombination = - ModifierKeyCombination.ofOnAndDontCareKeys( - keys, ImmutableSet.of(ModifierKey.CAPSLOCK)); - indexToModifierKeyCombinations.put(index, rAltCombination); - } - } - } - - private int findLigatureEndIndex() { - int keynameIndex = klcContents.indexOf("\nKEYNAME"); - keynameIndex = keynameIndex == -1 ? Integer.MAX_VALUE : keynameIndex; - int deadkeyIndex = klcContents.indexOf("\nDEADKEY"); - deadkeyIndex = deadkeyIndex == -1 ? Integer.MAX_VALUE : deadkeyIndex; - return Math.min(keynameIndex, deadkeyIndex); - } - - private void parseLigatures() { - // The ligature section is always bounded below by the keyname or deadkey sections. - int ligatureIndex = klcContents.indexOf("\nLIGATURE\r"); - if (ligatureIndex == -1) { - return; - } - int endIndex = findLigatureEndIndex(); - String section = klcContents.substring(ligatureIndex, endIndex); - List lines = LINE_SPLITTER.splitToList(section); - // Ignore the first line as it only contains the title. - for (int i = 1; i < lines.size(); i++) { - if (lines.get(i).startsWith("//")) { - continue; - } - List components = WHITESPACE_SPLITTER.splitToList(lines.get(i)); - String virtualKey = components.get(0); - Integer modifierIndexPlace = Integer.valueOf(components.get(1)); - StringBuilder ligature = new StringBuilder(); - for (int j = 2; j < components.size(); j++) { - String value = components.get(j); - if (value.startsWith("//")) { - break; - } - ligature.append(convertHexValueToString(value)); - } - String ligatureValue = ligature.toString(); - checkArgument(!ligatureValue.isEmpty(), section); - virtualKeyAndIndexPlaceToLigature.put( - virtualKey, modifierIndexPlace, ligature.toString()); - } - } - - private int findLayoutEndIndex() { - int deadKeyIndex = klcContents.indexOf("\nDEADKEY"); - deadKeyIndex = deadKeyIndex == -1 ? Integer.MAX_VALUE : deadKeyIndex; - int keynameIndex = klcContents.indexOf("\nKEYNAME"); - keynameIndex = keynameIndex == -1 ? Integer.MAX_VALUE : keynameIndex; - int ligatureIndex = klcContents.indexOf("\nLIGATURE"); - ligatureIndex = ligatureIndex == -1 ? Integer.MAX_VALUE : ligatureIndex; - return Math.min(Math.min(deadKeyIndex, keynameIndex), ligatureIndex); - } - - private static final ModifierKeyCombination SHIFT = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.SHIFT)); - - private static final ModifierKeyCombination CAPSLOCK = - ModifierKeyCombination.ofOnKeys(ImmutableSet.of(ModifierKey.CAPSLOCK)); - - private static final ModifierKeyCombination SHIFT_CAPSLOCK = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.of(ModifierKey.CAPSLOCK, ModifierKey.SHIFT)); - - private void parseLayout() { - // The layout section is bounded from below by the deadkey, keyname or ligature section. - int layoutIndex = klcContents.indexOf("\nLAYOUT"); - int endIndex = findLayoutEndIndex(); - String section = klcContents.substring(layoutIndex, endIndex); - List lines = LINE_SPLITTER.splitToList(section); - for (int i = 1; i < lines.size(); i++) { - if (lines.get(i).startsWith("//")) { - continue; - } - List components = WHITESPACE_SPLITTER.splitToList(lines.get(i)); - Integer scanCode = Integer.valueOf(components.get(0), 16); - // Delete key. - if (scanCode == 0x53 || scanCode == 0x7E) { - continue; - } - IsoLayoutPosition position = KEYCODE_MAP.getIsoLayoutPosition(scanCode); - Map modifierIndexToCharacterMap = Maps.newHashMap(); - int index = 0; - for (String output : Iterables.skip(components, 3)) { - if (output.equals("//")) { - break; - } - Integer modifierIndex = modifierIndexes.get(index++); - Collection combinations = - indexToModifierKeyCombinations.get(modifierIndex); - if (output.equals("-1")) { - continue; - } - String character; - boolean deadKey = false; - if (output.equals("%%")) { - String virtualKey = components.get(1); - // Getting ligatures is always based on the index of the modifier index. (The - // position of - // the index in order). - Integer modifierIndexPlace = index - 1; - character = - checkNotNull( - virtualKeyAndIndexPlaceToLigature.get( - virtualKey, modifierIndexPlace), - "[Modifier: %s, VirtualKey: %s]", - modifierIndexPlace, - virtualKey, - virtualKeyAndIndexPlaceToLigature); - } else { - // An @ appended to the output value indicates that this is a deadkey. - deadKey = output.endsWith("@"); - output = deadKey ? output.substring(0, output.length() - 1) : output; - character = convertHexValueToString(output); - } - CharacterMap characterMap = CharacterMap.of(position, character); - if (!deadKey && startsTransformSequence(character)) { - characterMap = characterMap.markAsTransformNo(); - } - builder.addCharacterMap(combinations, characterMap); - modifierIndexToCharacterMap.put(modifierIndex, characterMap); - } - String capsLock = components.get(2); - if (capsLock.equals("1") || capsLock.equals("4") || capsLock.equals("5")) { - // Integer capsIndex = Integer.valueOf(components.get(2)); - // Add the base output to the caps+shift output - if (modifierIndexToCharacterMap.containsKey(0)) { - builder.addCharacterMap(SHIFT_CAPSLOCK, modifierIndexToCharacterMap.get(0)); - } - if (modifierIndexToCharacterMap.containsKey(shiftIndex)) { - builder.addCharacterMap(CAPSLOCK, modifierIndexToCharacterMap.get(shiftIndex)); - } - } else if (capsLock.equals("SGCap")) { - // Deal with the caps lock case. - // The next line describes the outputs of the modifiers with the extra caps key. - String nextLine = lines.get(++i); - List nextLineComponents = WHITESPACE_SPLITTER.splitToList(nextLine); - int nextLineIndex = 0; - for (String output : Iterables.skip(nextLineComponents, 3)) { - if (output.equals("//")) { - break; - } - Integer modifierIndex = modifierIndexes.get(nextLineIndex++); - ModifierKeyCombination combination = - Iterables.getOnlyElement( - indexToModifierKeyCombinations.get(modifierIndex)); - ModifierKeyCombination capsCombination = - ModifierKeyCombination.ofOnKeys( - ImmutableSet.copyOf( - Iterables.concat( - combination.onKeys(), - ImmutableSet.of(ModifierKey.CAPSLOCK)))); - if (output.equals("-1")) { - continue; - } - String character = convertHexValueToString(output); - CharacterMap characterMap = CharacterMap.of(position, character); - builder.addCharacterMap(capsCombination, characterMap); - } - } else if (capsLock.equals("0")) { - if (modifierIndexToCharacterMap.containsKey(0)) { - builder.addCharacterMap(CAPSLOCK, modifierIndexToCharacterMap.get(0)); - } - if (modifierIndexToCharacterMap.containsKey(shiftIndex)) { - builder.addCharacterMap( - SHIFT_CAPSLOCK, modifierIndexToCharacterMap.get(shiftIndex)); - } - } else { - throw new IllegalArgumentException(capsLock); - } - } - } - - private void parseDeadkeys() { - // Each deadkey section is bounded below by another deadkey section or the keyname section. - int deadkeyIndex = klcContents.indexOf("\nDEADKEY"); - while (deadkeyIndex != -1) { - int nextDeadkeySection = klcContents.indexOf("\nDEADKEY", deadkeyIndex + 1); - int endIndex = - nextDeadkeySection == -1 - ? klcContents.indexOf("\nKEYNAME") - : nextDeadkeySection; - String section = klcContents.substring(deadkeyIndex, endIndex); - checkArgument(!section.isEmpty(), klcContents); - parseDeadkeySection(klcContents.substring(deadkeyIndex, endIndex)); - deadkeyIndex = nextDeadkeySection; - } - } - - private void parseDeadkeySection(String section) { - List lines = LINE_SPLITTER.splitToList(section); - // The first line contains the actual deadkey. Eg. "DEADKEY 0060" - String deadkey = - convertHexValueToString(WHITESPACE_SPLITTER.splitToList(lines.get(0)).get(1)); - // The remaining lines include all possible combinations. - for (int i = 1; i < lines.size(); i++) { - List components = WHITESPACE_SPLITTER.splitToList(lines.get(i)); - String combinationKey = convertHexValueToString(components.get(0)); - String output = convertHexValueToString(components.get(1)); - builder.addTransform(deadkey + combinationKey, output); - } - } - - private static final Pattern LETTER_OR_DIGIT = Pattern.compile("[0-9]|[a-z]|[A-Z]"); - - private String convertHexValueToString(String hexValue) { - // Some keyboards encode digits and letters as the character itself. - if (LETTER_OR_DIGIT.matcher(hexValue).matches()) { - return hexValue; - } - return Character.toString((char) Integer.valueOf(hexValue, 16).intValue()); - } - - private boolean startsTransformSequence(String string) { - for (String sequence : builder.transformSequences()) { - if (sequence.startsWith(string)) { - return true; - } - } - return false; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDtdDelta.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDtdDelta.java index aaff33fb208..75fae0f3db1 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDtdDelta.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ChartDtdDelta.java @@ -219,7 +219,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException { static { FIRST_VERSION.put(DtdType.ldmlBCP47, "1.7.2"); - FIRST_VERSION.put(DtdType.keyboard, "22.1"); + FIRST_VERSION.put(DtdType.keyboard3, "22.1"); } private void diff(String prefix, DtdData dtdLast, DtdData dtdCurrent) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateAllCharts.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateAllCharts.java index 0ba2034fe5f..8f4cc8cbcb0 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateAllCharts.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/GenerateAllCharts.java @@ -45,8 +45,5 @@ public static void main(String[] args) throws Exception { VerifyZones.main(args); DateTimeFormats.main(args); new ChartPersonNames().writeChart(null); - - // put this at the end, since it currently fails. - ShowKeyboards.main(args); } } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeyboardFlatten.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeyboardFlatten.java index ff75a6bfe41..8244eb68d73 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeyboardFlatten.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeyboardFlatten.java @@ -199,7 +199,7 @@ private static DocumentBuilderFactory getKeyboardDocFactory() throws SAXExceptio sfac.newSchema( new File( CLDRConfig.getInstance().getCldrBaseDirectory(), - DtdType.keyboard.getXsdPath())); + DtdType.keyboard3.getXsdPath())); dfactory.setSchema(schema); // Set other attributes here as needed // applyAttributes(dfactory, attributes); diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeymanCheck.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeymanCheck.java deleted file mode 100644 index bec9053a428..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/KeymanCheck.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.unicode.cldr.tool; - -import com.google.common.base.Splitter; -import com.google.common.collect.Multimap; -import com.google.common.collect.TreeMultimap; -import com.google.gson.Gson; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.math.BigDecimal; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import org.unicode.cldr.draft.FileUtilities; -import org.unicode.cldr.draft.Keyboard; -import org.unicode.cldr.util.CLDRConfig; -import org.unicode.cldr.util.CLDRFile; -import org.unicode.cldr.util.LanguageTagCanonicalizer; -import org.unicode.cldr.util.LanguageTagParser; -import org.unicode.cldr.util.SupplementalDataInfo; -import org.unicode.cldr.util.SupplementalDataInfo.PopulationData; - -public class KeymanCheck { - static Splitter SPACE = Splitter.on(' ').trimResults().omitEmptyStrings(); - static final List board = - SPACE.splitToList( - "aa-ET ab-GE an-ES apa-US ar-AE ar-DZ ar-IL ar-IQ ar-JO ar-KW ar-LB ar-LY ar-QA ar-SA ar-SD ar-SY ar-TN ar-YE arn-CL ast-ES av-RU awa-IN ay-BO az-AZ az-IR ba-RU bal-PK bar-AT bfy-IN bgc-IN bgq-IN bgq-PK bh-IN bho-IN bho-MU bho-NP bi-VU bm-ML bn-IN bns-IN bo-CN br-FR brx-Beng-IN brx-Deva-IN brx-Latn-IN bs-BA bug-ID ca-AD ca-ES ce-RU ceb-PH ch-GU cho-US chr-US cmn-Hans-SG cmn-Hant-HK co-FR cr-Cans-CA cr-Latn-CA cv-RU cy-GB dak-US de-AT de-CH de-LI de-LU dhd-IN din-SD doi-Arab-IN doi-Deva-IN dv-MV dz-BT ee-GH en-BD en-BM en-HK en-IE en-MY en-NZ en-PK en-SD en-SG en-TT en-TZ en-UG eo-001 es-419 es-BO es-CL es-CO es-CR es-CU es-DO es-EC es-GQ es-GT es-HN es-NI es-PA es-PE es-PR es-PY es-SV es-UY es-VE esu-US fa-AF ff-011 fj-FJ fo-FO fr-BE fr-CH fr-CI fr-LU fr-SN fy-NL ga-IE gbm-IN gd-GB gn-PG gv-IM gyn-GY ha-NG haw-US hi-Latn-IN hil-PH hmn-CN hne-IN ho-PG hoj-IN hsb-DE hu-SK hy-AM hz-NA ia-001 ig-NG ii-CN ik-US ilo-PH it-CH it-MT iu-Cans-CA iu-Latn-CA jbo-001 kfy-IN kg-CD ki-KE kj-AO kl-GL kok-Deva-IN kok-Knda-IN kok-Latn-IN kr-NG kri-SL ks-Arab-IN ks-Deva-IN ktu-CD ku-Arab-IQ ku-Latn-IQ kv-RU ky-KG la-001 lb-LU lg-UG li-NL lis-CN lkt-US lmn-IN lmo-IT ln-CD lu-CD mad-ID mag-IN mag-NP mai-NP mg-MG mh-MH mi-NZ min-ID ml-IN mn-CN mni-Beng-IN mrj-RU ms-SG mt-MT mtr-IN mup-IN mus-US mwr-IN na-NR nah-MX nap-IT nd-ZW nds-DE ne-IN new-NP nl-BE nn-NO noe-IN nr-ZA nso-ZA nv-US ny-MW oc-FR oj-CA om-ET os-RU pa-Arab-PK pap-CW pms-IT ps-AF pt-AO pt-TL qu-BO quc-GT raj-PK rm-CH rn-BI ro-MD ru-BY ru-KZ ru-UA sa-IN sah-RU sat-Beng-IN sat-Deva-IN sat-Latn-IN sat-Olck-IN sc-IT sck-IN scn-IT sco-GB sd-Arab-IN sd-Deva-IN sd-PK se-NO see-US sg-CF sgs-LT sjp-BD sm-WS sn-ZW sr-Cyrl-ME sr-Cyrl-RS sr-Latn-ME ss-ZA st-ZA sv-FI sw-KE sw-TZ sw-UG syl-BD ta-LK ta-SG tcy-IN tet-TL ti-ET tk-TM tn-BW tn-ZA to-TO tpi-PG ts-ZA tt-RU tw-GH ty-PF ug-CN ur-IN var-IN ve-ZA vec-IT wa-BE war-PH wen-DE wo-SN xh-ZA xnr-IN yi-US yo-NG"); - - private static final SupplementalDataInfo SUPPLEMENTAL_DATA_INFO = - CLDRConfig.getInstance().getSupplementalDataInfo(); - - public static void main(String[] args) throws IOException { - Gson gson = new Gson(); - JsonReader reader = - gson.newJsonReader( - FileUtilities.openFile( - "/Users/markdavis/Google Drive/workspace/DATA/cldr/", - "keyman.json")); - final StringWriter stringWriter = new StringWriter(); - JsonWriter writer = gson.newJsonWriter(stringWriter); - writer.setIndent(" "); - prettyprint(reader, writer); - reader.close(); - writer.close(); - // System.out.println(stringWriter); - } - - static LanguageTagCanonicalizer ltc = new LanguageTagCanonicalizer(); - - static void prettyprint(JsonReader reader, JsonWriter writer) throws IOException { - boolean afterId = false; - boolean afterName = false; - boolean afterLanguage = false; - String lastId = null; - Multimap languageIdToName = TreeMultimap.create(); - - main: - while (true) { - JsonToken token = reader.peek(); - switch (token) { - case BEGIN_ARRAY: - reader.beginArray(); - writer.beginArray(); - break; - case END_ARRAY: - reader.endArray(); - writer.endArray(); - afterLanguage = false; - break; - case BEGIN_OBJECT: - reader.beginObject(); - writer.beginObject(); - break; - case END_OBJECT: - reader.endObject(); - writer.endObject(); - break; - case NAME: - String name = reader.nextName(); - switch (name) { - case "id": - afterId = afterLanguage; - break; - case "name": - afterName = afterLanguage; - break; - case "languages": - afterLanguage = true; - break; - } - writer.name(name); - break; - case STRING: - String s = reader.nextString(); - writer.value(s); - if (afterId) { - lastId = ltc.transform(s); - afterId = false; - } else if (afterName) { - languageIdToName.put(lastId, s); - afterName = false; - } - break; - case NUMBER: - String n = reader.nextString(); - writer.value(new BigDecimal(n)); - break; - case BOOLEAN: - boolean b = reader.nextBoolean(); - writer.value(b); - break; - case NULL: - reader.nextNull(); - writer.nullValue(); - break; - case END_DOCUMENT: - break main; - } - } - int count = 0; - CLDRFile en = CLDRConfig.getInstance().getEnglish(); - TreeMultimap keyboardLangs = TreeMultimap.create(); - for (String kpid : Keyboard.getPlatformIDs()) { - for (String kid : Keyboard.getKeyboardIDs(kpid)) { - keyboardLangs.put(ltp.set(kid).getLanguageScript(), kid); - } - } - - LikelySubtags likely = new LikelySubtags(); - LanguageTagParser ltp = new LanguageTagParser(); - - Set minBoard = new HashSet<>(); - for (String boardId : board) { - ltp.set(boardId); - ltp.setRegion(""); - String min = ltc.transform(ltp.toString()); - minBoard.add(min == null ? boardId : min); - } - - TreeSet langs = new TreeSet<>(); - langs.addAll(keyboardLangs.keySet()); - langs.addAll(languageIdToName.keySet()); - langs.addAll(minBoard); - for (String lang : langs) { - PopulationData pop = getPopulationData(lang); - System.out.println( - // ++count - // + "\t" + - en.getName(lang) - + "\t" - + lang - + "\t" - + (pop != null ? (long) pop.getLiteratePopulation() : "-1") - + "\t" - + (keyboardLangs.containsKey(lang) ? "CLDR" : "") - + "\t" - + (languageIdToName.containsKey(lang) ? "SIL" : "") - + "\t" - + (minBoard.contains(lang) ? "GB" : "")); - } - } - - static LanguageTagParser ltp = new LanguageTagParser(); - static LikelySubtags ls = new LikelySubtags(); - static Map unfixedData = new TreeMap<>(); - - static { - for (String s : SUPPLEMENTAL_DATA_INFO.getLanguagesForTerritoriesPopulationData()) { - String fixed = ltc.transform(s); - if (!fixed.equals(s)) { - unfixedData.put(fixed, s); - System.out.println(s + " => " + fixed); - } - } - } - - private static PopulationData getPopulationData(String lang) { - PopulationData pop = SUPPLEMENTAL_DATA_INFO.getLanguagePopulationData(lang); - if (pop == null) { - String unfixed = unfixedData.get(lang); - if (unfixed != null) { - pop = SUPPLEMENTAL_DATA_INFO.getLanguagePopulationData(unfixed); - } - } - // if (pop == null) { - // final String maximize = ls.maximize(lang); - // if (maximize != null) { - // ltp.set(maximize); - // SUPPLEMENTAL_DATA_INFO.getLanguagePopulationData(ltp.getLanguageScript()); - // } - // } - return pop; - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowDtdDiffs.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowDtdDiffs.java index cafda6a6087..364466ad456 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowDtdDiffs.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowDtdDiffs.java @@ -30,7 +30,7 @@ public class ShowDtdDiffs { static { FIRST_VERSION.put(DtdType.ldmlBCP47, "1.7.2"); - FIRST_VERSION.put(DtdType.keyboard, "22.1"); + FIRST_VERSION.put(DtdType.keyboard3, "22.1"); } public static void main(String[] args) { diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowKeyboards.java b/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowKeyboards.java deleted file mode 100644 index a5e4b63adfc..00000000000 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ShowKeyboards.java +++ /dev/null @@ -1,1114 +0,0 @@ -package org.unicode.cldr.tool; - -import com.google.common.base.Joiner; -import com.ibm.icu.impl.Relation; -import com.ibm.icu.impl.Row; -import com.ibm.icu.impl.Row.R2; -import com.ibm.icu.impl.Row.R3; -import com.ibm.icu.impl.Utility; -import com.ibm.icu.lang.UCharacter; -import com.ibm.icu.lang.UProperty; -import com.ibm.icu.lang.UScript; -import com.ibm.icu.text.Collator; -import com.ibm.icu.text.Transliterator; -import com.ibm.icu.text.UnicodeSet; -import com.ibm.icu.util.ULocale; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.BitSet; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.regex.Matcher; -import org.unicode.cldr.draft.FileUtilities; -import org.unicode.cldr.draft.Keyboard; -import org.unicode.cldr.draft.Keyboard.Gesture; -import org.unicode.cldr.draft.Keyboard.Iso; -import org.unicode.cldr.draft.Keyboard.KeyMap; -import org.unicode.cldr.draft.Keyboard.Output; -import org.unicode.cldr.draft.Keyboard.TransformStatus; -import org.unicode.cldr.draft.Keyboard.TransformType; -import org.unicode.cldr.draft.Keyboard.Transforms; -import org.unicode.cldr.draft.KeyboardModifierSet; -import org.unicode.cldr.tool.Option.Options; -import org.unicode.cldr.util.CLDRConfig; -import org.unicode.cldr.util.CLDRFile; -import org.unicode.cldr.util.CLDRFile.WinningChoice; -import org.unicode.cldr.util.CLDRPaths; -import org.unicode.cldr.util.CLDRTool; -import org.unicode.cldr.util.CldrUtility; -import org.unicode.cldr.util.Counter; -import org.unicode.cldr.util.Factory; -import org.unicode.cldr.util.FileCopier; -import org.unicode.cldr.util.LanguageTagCanonicalizer; -import org.unicode.cldr.util.Log; -import org.unicode.cldr.util.SupplementalDataInfo; -import org.unicode.cldr.util.TransliteratorUtilities; -import org.unicode.cldr.util.UnicodeSetPrettyPrinter; - -@CLDRTool(alias = "showkeyboards", description = "Generate keyboard charts") -public class ShowKeyboards { - // TODO - fix ' > xxx - // TODO - check for bad locale ids - - private static final String ABOUT_KEYBOARD_CHARTS = - "

          For more information, see About Keyboard Charts.

          "; - private static String keyboardChartDir; - private static String keyboardChartLayoutsDir; - static final CLDRConfig testInfo = ToolConfig.getToolInstance(); - static final Factory factory = testInfo.getCldrFactory(); - - static final boolean SHOW_BACKGROUND = false; - - static final Options myOptions = new Options(); - - enum MyOptions { - idFilter(".+", ".*", "Filter the information based on id, using a regex argument."), - sourceDirectory( - ".+", - CLDRPaths.BASE_DIRECTORY + "keyboards/", - "The source directory. CURRENTLY CAN’T BE CHANGED!!"), - targetDirectory(".+", CLDRPaths.CHART_DIRECTORY + "keyboards/", "The target directory."), - layouts(null, null, "Only create html files for keyboard layouts"), - repertoire(null, null, "Only create html files for repertoire"), - ; - // boilerplate - final Option option; - - MyOptions(String argumentPattern, String defaultArgument, String helpText) { - option = myOptions.add(this, argumentPattern, defaultArgument, helpText); - } - } - - static SupplementalDataInfo supplementalDataInfo = SupplementalDataInfo.getInstance(); - - // ********************************************* - // Temporary, for some simple testing - // ********************************************* - public static void main(String[] args) throws IOException { - myOptions.parse(MyOptions.idFilter, args, true); - String idPattern = MyOptions.idFilter.option.getValue(); - keyboardChartDir = MyOptions.targetDirectory.option.getValue(); - keyboardChartLayoutsDir = keyboardChartDir + "/layouts/"; - - FileCopier.ensureDirectoryExists(keyboardChartDir); - FileCopier.copy( - ShowKeyboards.class, "keyboards-index.html", keyboardChartDir, "index.html"); - - // Matcher idMatcher = PatternCache.get(idPattern).matcher(""); - // try { - // Log.setLog(CLDRPaths.LOG_DIRECTORY + "keyboard-log.txt"); - // } catch (IOException e) { - // throw new ICUUncheckedIOException(e); - // } - // boolean layoutsOnly = MyOptions.layouts.option.doesOccur(); - // boolean repertoireOnly = MyOptions.repertoire.option.doesOccur(); - - // if (!repertoireOnly) { - // showHtml(idMatcher); - // } - // if (!layoutsOnly) { - // showRepertoire(idMatcher); - // } - } - - public static void showRepertoire(Matcher idMatcher) { - Set totalErrors = new LinkedHashSet<>(); - Set errors = new LinkedHashSet<>(); - UnicodeSet controls = new UnicodeSet("[:Cc:]").freeze(); - // check what the characters are, excluding controls. - Map id2unicodeset = new TreeMap<>(); - Set totalModifiers = new LinkedHashSet<>(); - Relation locale2ids = - Relation.of(new TreeMap>(), TreeSet.class); - LanguageTagCanonicalizer canonicalizer = new LanguageTagCanonicalizer(); - IdInfo idInfo = new IdInfo(); - for (String platformId : Keyboard.getPlatformIDs()) { - // Platform p = Keyboard.getPlatform(platformId); - // System.out.println(platformId + "\t" + p.getHardwareMap()); - for (String keyboardId : Keyboard.getKeyboardIDs(platformId)) { - if (!idMatcher.reset(keyboardId).matches()) { - continue; - } - Keyboard keyboard = Keyboard.getKeyboard(platformId, keyboardId, errors); - for (Exception error : errors) { - totalErrors.add(new IllegalArgumentException(keyboardId, error)); - } - UnicodeSet unicodeSet = keyboard.getPossibleResults().removeAll(controls); - final Id id = new Id(keyboardId, keyboard.getPlatformVersion()); - idInfo.add(id, unicodeSet); - String canonicalLocale = canonicalizer.transform(id.locale).replace('_', '-'); - if (!id.locale.equals(canonicalLocale)) { - totalErrors.add( - new IllegalArgumentException( - "Non-canonical id: " + id.locale + "\t=>\t" + canonicalLocale)); - } - id2unicodeset.put(id, unicodeSet.freeze()); - locale2ids.put(id.locale, id); - System.out.println(id.toString().replace('/', '\t') + "\t" + keyboard.getNames()); - for (KeyMap keymap : keyboard.getKeyMaps()) { - totalModifiers.add(keymap.getModifiers().toString()); - } - } - } - if (totalErrors.size() != 0) { - System.out.println( - "Errors\t" + Joiner.on(System.lineSeparator() + "\t").join(totalErrors)); - } - for (String item : totalModifiers) { - System.out.println(item); - } - // logInfo.put(Row.of("k-cldr",common), keyboardId); - try { - FileCopier.copy(ShowKeyboards.class, "keyboards.css", keyboardChartDir, "index.css"); - FormattedFileWriter.copyIncludeHtmls(keyboardChartDir); - - PrintWriter out = - FileUtilities.openUTF8Writer(keyboardChartDir, "chars2keyboards.html"); - String[] headerAndFooter = new String[2]; - - ShowData.getChartTemplate( - "Characters → Keyboards", - ToolConstants.CHART_DISPLAY_VERSION, - "", - headerAndFooter, - null, - false); - out.println(headerAndFooter[0] + ABOUT_KEYBOARD_CHARTS); - - // printTop("Characters → Keyboards", out); - idInfo.print(out); - // printBottom(out); - out.println(headerAndFooter[1]); - out.close(); - - out = FileUtilities.openUTF8Writer(keyboardChartDir, "keyboards2chars.html"); - ShowData.getChartTemplate( - "Keyboards → Characters", - ToolConstants.CHART_DISPLAY_VERSION, - "", - headerAndFooter, - null, - false); - out.println(headerAndFooter[0] + ABOUT_KEYBOARD_CHARTS); - // printTop("Keyboards → Characters", out); - showLocaleToCharacters(out, id2unicodeset, locale2ids); - // printBottom(out); - out.println(headerAndFooter[1]); - out.close(); - } catch (IOException e1) { - e1.printStackTrace(); - } - for (Entry, Set> entry : logInfo.keyValuesSet()) { - IdSet idSet = new IdSet(); - idSet.addAll(entry.getValue()); - Log.logln( - entry.getKey().get0() - + "\t" - + entry.getKey().get1().toPattern(false) - + "\t" - + idSet.toString(idInfo.allIds)); - } - Log.close(); - } - - private static void showHtml(Matcher idMatcher) throws IOException { - Set errors = new LinkedHashSet<>(); - Relation> locale2keyboards = - Relation.of( - new TreeMap>>(), TreeSet.class); - Map localeIndex = new TreeMap<>(); - - for (String platformId : Keyboard.getPlatformIDs()) { - // Platform p = Keyboard.getPlatform(platformId); - // System.out.println(platformId + "\t" + p.getHardwareMap()); - for (String keyboardId : Keyboard.getKeyboardIDs(platformId)) { - if (!idMatcher.reset(keyboardId).matches()) { - continue; - } - String baseLocale = keyboardId.substring(0, keyboardId.indexOf('-')); - String locale = keyboardId.substring(0, keyboardId.indexOf("-t-")); - locale2keyboards.put(baseLocale, Row.of(platformId, locale, keyboardId)); - - final String localeName = testInfo.getEnglish().getName(baseLocale, true); - localeIndex.put(localeName, baseLocale); - } - } - - FileCopier.ensureDirectoryExists(keyboardChartLayoutsDir); - FileCopier.copy(ShowKeyboards.class, "keyboards.css", keyboardChartLayoutsDir, "index.css"); - FormattedFileWriter.copyIncludeHtmls(keyboardChartLayoutsDir); - PrintWriter index = FileUtilities.openUTF8Writer(keyboardChartLayoutsDir, "index.html"); - String[] headerAndFooter = new String[2]; - ShowData.getChartTemplate( - "Keyboard Layout Index", - ToolConstants.CHART_DISPLAY_VERSION, - "", - headerAndFooter, - "Keyboard Index", - false); - index.println(headerAndFooter[0] + ABOUT_KEYBOARD_CHARTS); - // printTop("Keyboard Layout Index", index); - index.println("
            "); - for (Entry entry : localeIndex.entrySet()) { - index.println( - "
          1. " - + entry.getKey() - + "" - + " [" - + entry.getValue() - + "]" - + "
          2. "); - } - index.println("
          "); - index.println(headerAndFooter[1]); - // printBottom(index); - index.close(); - // FileUtilities.copyFile(ShowKeyboards.class, "keyboards.css", keyboardChartLayoutsDir); - - for (Entry>> localeKeyboards : - locale2keyboards.keyValuesSet()) { - String locale = localeKeyboards.getKey(); - final String localeName = testInfo.getEnglish().getName(locale); - - // String localeNameString = localeName.replace(' ', '_').toLowerCase(Locale.ENGLISH); - PrintWriter out = - FileUtilities.openUTF8Writer(keyboardChartLayoutsDir, locale + ".html"); - ShowData.getChartTemplate( - "Layouts: " + localeName + " (" + locale + ")", - ToolConstants.CHART_DISPLAY_VERSION, - "", - headerAndFooter, - null, - false); - out.println(headerAndFooter[0] + ABOUT_KEYBOARD_CHARTS); - // printTop("Layouts: " + localeName + " (" + locale + ")", out); - Set> keyboards = localeKeyboards.getValue(); - for (R3 platformKeyboard : keyboards) { - String platformId = platformKeyboard.get0(); - String keyboardId = platformKeyboard.get2(); - // System.out.println(platformId + "\t" + p.getHardwareMap()); - Keyboard keyboard = Keyboard.getKeyboard(platformId, keyboardId, errors); - showErrors(errors); - Set names = keyboard.getNames(); - String platformFromKeyboardId = Keyboard.getPlatformId(keyboardId); - String printId = - platformId.equals(platformFromKeyboardId) - ? keyboardId - : keyboardId + "/und"; - out.println( - "

          " - + CldrUtility.getDoubleLinkedText(printId, printId) - + (names.size() == 0 ? "" : " " + names) - + "

          "); - - Transforms transforms = keyboard.getTransforms().get(TransformType.SIMPLE); - - out.println(""); - for (KeyMap map : keyboard.getKeyMaps()) { - KeyboardModifierSet mods = map.getModifiers(); - out.println(""); - } - out.println("
          "); - // KeyboardModifierSet modifiers = map.getModifiers(); - Map isoMap = map.getIso2Output(); - for (Keyboard.IsoRow row : Keyboard.IsoRow.values()) { - out.println(""); - for (Iso isoValue : Iso.values()) { - if (isoValue.isoRow != row) { - continue; - } - Output output = isoMap.get(isoValue); - if (output == null) { - out.println(""); - continue; - } - String chars = output.getOutput(); - TransformStatus transformStatus = output.getTransformStatus(); - StringBuilder hover = new StringBuilder(); - if (transformStatus == TransformStatus.DEFAULT && transforms != null) { - Map map2 = transforms.getMatch(chars); - add(map2, hover); - } - Map> gestures = output.getGestures(); - if (!gestures.isEmpty()) { - add(gestures, hover); - } - final String longPress = - hover.length() == 0 ? "" : " title='" + hover + "'"; - out.println( - ""); - } - out.println(""); - } - String modsString = mods.getShortInput(); - if (modsString.isEmpty()) { - modsString = "\u00A0"; - } else if (modsString.length() > 20) { - modsString = modsString.substring(0, 20) + "…"; - } - out.println( - "
           " - + toSafeHtml(chars) - + "
          " - + TransliteratorUtilities.toHTML.transform(modsString) - + "
          "); - } - index.println(headerAndFooter[1]); - // printBottom(out); - out.close(); - } - System.out.println("Failing Invisibles: " + FAILING_INVISIBLE.retainAll(INVISIBLE)); - } - - private static void showErrors(Set errors) { - for (Exception error : errors) { - String title = error.getMessage().contains("No minimal data for") ? "Warning" : "Error"; - System.out.println("\t*" + title + ":\t" + error); - } - } - - static Transliterator TO_SAFE_HTML; - - static { - StringBuilder rules = new StringBuilder(TransliteratorUtilities.toHTML.toRules(false)); - for (char i = 0; i < 0x20; ++i) { - addRule(String.valueOf(i), "^" + String.valueOf((char) (i + 0x40)), rules); - } - String[][] map = { - // {"\u0020","sp"}, - {"\u007F", "del"}, - {"\u00A0", "nbsp"}, - {"\u00AD", "shy"}, - {"\u200B", "zwsp"}, - {"\u200C", "zwnj"}, - {"\u200D", "zwj"}, - {"\u200E", "lrm"}, - {"\u200F", "rlm"}, - {"\u202F", "nnbs"}, - {"\uFEFF", "bom"}, - {"\u180B", "mvs1"}, - {"\u180C", "mvs2"}, - {"\u180D", "mvs3"}, - {"\u180E", "mvs"}, - // {"\uF8FF","appl"}, - }; - for (String[] items : map) { - final String fromItem = items[0]; - final String toItem = items[1]; - addRule(fromItem, toItem, rules); - } - TO_SAFE_HTML = - Transliterator.createFromRules("none", rules.toString(), Transliterator.FORWARD); - } - - public static void addRule(final String fromItem, final String toItem, StringBuilder rules) { - rules.append( - "'" - + fromItem - + "'>" - + "'" - + toItem - + "'" - + ";" - + System.lineSeparator()); - } - - static UnicodeSet INVISIBLE = - new UnicodeSet("[[:C:][:Z:][:whitespace:][:Default_Ignorable_Code_Point:]-[\\u0020]]") - .freeze(); - static UnicodeSet FAILING_INVISIBLE = new UnicodeSet(); - - public static String toSafeHtml(Object hover) { - String result = TO_SAFE_HTML.transform(hover.toString()); - if (INVISIBLE.containsSome(result)) { - FAILING_INVISIBLE.addAll(result); - } - return result; - } - - private static void add(Map map2, StringBuilder hover) { - if (!map2.isEmpty()) { - for (Entry entry : map2.entrySet()) { - if (hover.length() != 0) { - hover.append("; "); - } - final K key = entry.getKey(); - String keyString = key == Gesture.LONGPRESS ? "LP" : key.toString(); - final V value = entry.getValue(); - String valueString = - value instanceof Collection - ? Joiner.on(" ").join((Collection) value) - : value.toString(); - hover.append(TransliteratorUtilities.toHTML.transform(keyString)) - .append("→") - .append(TransliteratorUtilities.toHTML.transform(valueString)); - } - } - } - - // public static void printTop(String title, PrintWriter out) { - // out.println( - // "\n" + - // "\n" + - // "\n" + - // "" + - // "" + title + "\n" + - // "\n" + - // "\n" + - // "

          DRAFT " + - // title + - // "

          \n" + - // "

          For more information, see Keyboard Charts.

          " - // ); - // } - // - // public static void printBottom(PrintWriter pw) { - // pw.println( - // "\n" + - // "" - // ); - // } - - public static void showLocaleToCharacters( - PrintWriter out, Map id2unicodeset, Relation locale2ids) { - - TablePrinter t = - new TablePrinter() - .addColumn("Name") - .setSpanRows(true) - .setBreakSpans(true) - .setSortPriority(0) - .setCellAttributes("class='cell'") - .addColumn("Locale") - .setSpanRows(true) - .setBreakSpans(true) - .setCellAttributes("class='cell'") - .addColumn("Platform") - .setSpanRows(true) - .setCellAttributes("class='cell'") - .addColumn("Variant") - .setCellAttributes("class='cell'") - .addColumn("Script") - .setCellAttributes("class='cell'") - .addColumn("Statistics") - .setCellAttributes("class='cell'") - .addColumn("Characters") - .setSpanRows(true) - .setCellAttributes("class='cell'"); - - Map commonSets = new HashMap<>(); - Counter commonCount = new Counter<>(); - Set commonDone = new HashSet<>(); - - for (Entry> localeAndIds : locale2ids.keyValuesSet()) { - final String key = localeAndIds.getKey(); - final Set keyboardIds = localeAndIds.getValue(); - - // System.out.println(); - final String localeName = testInfo.getEnglish().getName(key, true); - final String linkedLocaleName = CldrUtility.getDoubleLinkedText(key, localeName); - final ULocale uLocale = ULocale.forLanguageTag(key); - String script = uLocale.getScript(); - String writtenLanguage = uLocale.getLanguage() + (script.isEmpty() ? "" : "_" + script); - CLDRFile cldrFile = null; - try { - cldrFile = factory.make(writtenLanguage, true); - } catch (Exception e) { - } - - // final String heading = uLocale.getDisplayName(ULocale.ENGLISH) - // + "\t" + ULocale.addLikelySubtags(uLocale).getScript() - // + "\t"; - UnicodeSet common = UnicodeSet.EMPTY; - final String likelyScript = ULocale.addLikelySubtags(uLocale).getScript(); - commonCount.clear(); - for (String platform : Keyboard.getPlatformIDs()) { - commonSets.put(platform, UnicodeSet.EMPTY); - } - if (keyboardIds.size() > 1) { - common = UnicodeSet.EMPTY; - for (Id keyboardId : keyboardIds) { - final UnicodeSet keyboardSet = id2unicodeset.get(keyboardId); - if (common == UnicodeSet.EMPTY) { - common = new UnicodeSet(keyboardSet); - } else { - common.retainAll(keyboardSet); - } - UnicodeSet platformCommon = commonSets.get(keyboardId.platform); - commonCount.add(keyboardId.platform, 1); - if (platformCommon == UnicodeSet.EMPTY) { - commonSets.put(keyboardId.platform, new UnicodeSet(keyboardSet)); - } else { - platformCommon.retainAll(keyboardSet); - } - } - common.freeze(); - t.addRow() - .addCell(linkedLocaleName) // name - .addCell(key) // locale - .addCell("ALL") // platform - .addCell("COMMON") // variant - .addCell(likelyScript) // script - .addCell(getInfo(null, common, cldrFile)) // stats - .addCell(safeUnicodeSet(common)) // characters - .finishRow(); - - // System.out.println( - // locale + "\tCOMMON\t\t-" - // + "\t" + heading + getInfo(common, cldrFile) - // + "\t" + common.toPattern(false)); - } - commonDone.clear(); - for (Id keyboardId : keyboardIds) { - UnicodeSet platformCommon = commonSets.get(keyboardId.platform); - if (!commonDone.contains(keyboardId.platform)) { - commonDone.add(keyboardId.platform); - if (commonCount.get(keyboardId.platform) <= 1) { - platformCommon = UnicodeSet.EMPTY; - commonSets.put(keyboardId.platform, platformCommon); - } else if (platformCommon.size() > 0) { - // get stats for all, but otherwise remove common. - final String stats = getInfo(null, platformCommon, cldrFile); - platformCommon.removeAll(common).freeze(); - commonSets.put(keyboardId.platform, platformCommon); - t.addRow() - .addCell(linkedLocaleName) // name - .addCell(key) // locale - .addCell(keyboardId.platform) // platform - .addCell("COMMON") // variant - .addCell(likelyScript) // script - .addCell(stats) // stats - .addCell(safeUnicodeSet(platformCommon)) // characters - .finishRow(); - } - } - final UnicodeSet current2 = id2unicodeset.get(keyboardId); - final UnicodeSet remainder = - new UnicodeSet(current2).removeAll(common).removeAll(platformCommon); - - t.addRow() - .addCell(linkedLocaleName) // name - .addCell(key) // locale - .addCell(keyboardId.platform) // platform - .addCell(keyboardId.variant) // variant - .addCell(likelyScript) // script - .addCell(getInfo(keyboardId, current2, cldrFile)) // stats - .addCell(safeUnicodeSet(remainder)) // characters - .finishRow(); - // System.out.println( - // keyboardId.toString().replace('/','\t') - // + "\t" + keyboardId.platformVersion - // + "\t" + heading + getInfo(current2, cldrFile) - // + "\t" + remainder.toPattern(false)); - } - } - out.println(t.toTable()); - } - - static UnicodeSetPrettyPrinter prettyPrinter = - UnicodeSetPrettyPrinter.fromIcuLocale(ULocale.ROOT.toString()); - - public static String safeUnicodeSet(UnicodeSet unicodeSet) { - return TransliteratorUtilities.toHTML.transform(prettyPrinter.format(unicodeSet)); - } - - static class IdInfo { - final Collator collator = Collator.getInstance(ULocale.ENGLISH); - BitSet bitset = new BitSet(); - BitSet bitset2 = new BitSet(); - - @SuppressWarnings("unchecked") - TreeMap[] charToKeyboards = new TreeMap[UScript.CODE_LIMIT]; - - { - collator.setStrength(Collator.IDENTICAL); - for (int i = 0; i < charToKeyboards.length; ++i) { - charToKeyboards[i] = new TreeMap<>(collator); - } - } - - IdSet allIds = new IdSet(); - - public void add(Id id, UnicodeSet unicodeSet) { - allIds.add(id); - for (String s : unicodeSet) { - int script = getScriptExtensions(s, bitset); - if (script >= 0) { - addToScript(script, id, s); - } else { - for (int script2 = bitset.nextSetBit(0); - script2 >= 0; - script2 = bitset.nextSetBit(script2 + 1)) { - addToScript(script2, id, s); - } - } - } - } - - public int getScriptExtensions(String s, BitSet outputBitset) { - final int firstCodePoint = s.codePointAt(0); - int result = UScript.getScriptExtensions(firstCodePoint, outputBitset); - final int firstCodePointCount = Character.charCount(firstCodePoint); - if (s.length() == firstCodePointCount) { - return result; - } - for (int i = firstCodePointCount; i < s.length(); ) { - int ch = s.codePointAt(i); - UScript.getScriptExtensions(ch, bitset2); - outputBitset.or(bitset2); - i += Character.charCount(ch); - } - // remove inherited, if there is anything else; then remove common if there is anything - // else - int cardinality = outputBitset.cardinality(); - if (cardinality > 1) { - if (outputBitset.get(UScript.INHERITED)) { - outputBitset.clear(UScript.INHERITED); - --cardinality; - } - if (cardinality > 1) { - if (outputBitset.get(UScript.COMMON)) { - outputBitset.clear(UScript.COMMON); - --cardinality; - } - } - } - if (cardinality == 1) { - return outputBitset.nextSetBit(0); - } else { - return -cardinality; - } - } - - public void addToScript(int script, Id id, String s) { - TreeMap charToKeyboard = charToKeyboards[script]; - IdSet idSet = charToKeyboard.get(s); - if (idSet == null) { - charToKeyboard.put(s, idSet = new IdSet()); - } - idSet.add(id); - } - - public void print(PrintWriter pw) { - - TablePrinter t = - new TablePrinter() - .addColumn("Script") - .setSpanRows(true) - .setCellAttributes("class='s'") - .addColumn("Char") - .setCellAttributes("class='ch'") - .addColumn("Code") - .setCellAttributes("class='c'") - .addColumn("Name") - .setCellAttributes("class='n'") - .addColumn("Keyboards") - .setSpanRows(true) - .setCellAttributes("class='k'"); - Set missingScripts = new TreeSet<>(); - UnicodeSet notNFKC = new UnicodeSet("[:nfkcqc=n:]"); - UnicodeSet COMMONINHERITED = new UnicodeSet("[[:sc=common:][:sc=inherited:]]"); - - for (int script = 0; script < charToKeyboards.length; ++script) { - UnicodeSet inScript = - new UnicodeSet() - .applyIntPropertyValue(UProperty.SCRIPT, script) - .removeAll(notNFKC); - - // UnicodeSet fullScript = new UnicodeSet(inScript); - // int fullScriptSize = inScript.size(); - if (inScript.size() == 0) { - continue; - } - final TreeMap charToKeyboard = charToKeyboards[script]; - final String scriptName = UScript.getName(script); - final String linkedScriptName = - CldrUtility.getDoubleLinkedText(UScript.getShortName(script), scriptName); - if (charToKeyboard.size() == 0) { - missingScripts.add(scriptName); - continue; - } - - // also check to see that at least one item is not all common - check: - if (script != UScript.COMMON && script != UScript.INHERITED) { - for (String s : charToKeyboard.keySet()) { - if (!COMMONINHERITED.containsAll(s)) { - break check; - } - } - missingScripts.add(scriptName); - continue; - } - - String last = ""; - for (Entry entry : charToKeyboard.entrySet()) { - String s = entry.getKey(); - IdSet value = entry.getValue(); - final String keyboardsString = value.toString(allIds); - if (!s.equalsIgnoreCase(last)) { - if (s.equals( - "\u094D\u200C")) { // Hack, because the browsers width is way off - s = "\u094D"; - } - String name = UCharacter.getName(s, " + "); - if (name == null) { - name = "[no name]"; - } - String ch = s.equals("\u0F39") ? "\uFFFD" : s; - t.addRow() - .addCell(linkedScriptName) - .addCell( - (SHOW_BACKGROUND ? "" : "") - + TransliteratorUtilities.toHTML.transform(ch) - + (SHOW_BACKGROUND ? "" : "")) - .addCell(Utility.hex(s, 4, " + ")) - .addCell(name) - .addCell(keyboardsString) - .finishRow(); - } - inScript.remove(s); - last = s; - } - if (inScript.size() != 0 && script != UScript.UNKNOWN) { - // String pattern; - // if (inScript.size() < 255 || inScript.size()*4 < fullScriptSize) { - // } else { - // fullScript.removeAll(inScript); - // inScript = new UnicodeSet("[[:sc=" + UScript.getShortName(script) + ":]-" + - // fullScript.toPattern(false) + "]"); - // } - t.addRow() - .addCell(linkedScriptName) - .addCell("") - .addCell(String.valueOf(inScript.size())) - .addCell("missing (NFKC)!") - .addCell(safeUnicodeSet(inScript)) - .finishRow(); - } - } - t.addRow() - .addCell("") - .addCell("") - .addCell(String.valueOf(missingScripts.size())) - .addCell("missing scripts!") - .addCell(missingScripts.toString()) - .finishRow(); - pw.println(t.toTable()); - } - } - - private static String getInfo(Id keyboardId, UnicodeSet common, CLDRFile cldrFile) { - Counter results = new Counter<>(); - for (String s : common) { - int first = s.codePointAt(0); // first char is good enough - results.add(UScript.getShortName(UScript.getScript(first)), 1); - } - results.remove("Zyyy"); - results.remove("Zinh"); - results.remove("Zzzz"); - - if (cldrFile != null) { - UnicodeSet exemplars = - new UnicodeSet(cldrFile.getExemplarSet("", WinningChoice.WINNING)); - UnicodeSet auxExemplars = cldrFile.getExemplarSet("auxiliary", WinningChoice.WINNING); - if (auxExemplars != null) { - exemplars.addAll(auxExemplars); - } - UnicodeSet punctuationExemplars = - cldrFile.getExemplarSet("punctuation", WinningChoice.WINNING); - if (punctuationExemplars != null) { - exemplars.addAll(punctuationExemplars); - } - exemplars.addAll(getNumericExemplars(cldrFile)); - exemplars.addAll(getQuotationMarks(cldrFile)); - exemplars.add(" "); - addComparison(keyboardId, common, exemplars, results); - } - StringBuilder b = new StringBuilder(); - for (String entry : results.keySet()) { - if (b.length() != 0) { - b.append(", "); - } - b.append(entry).append(":").append(results.get(entry)); - } - return b.toString(); - } - - private static void addComparison( - Id keyboardId, UnicodeSet keyboard, UnicodeSet exemplars, Counter results) { - UnicodeSet common = new UnicodeSet(keyboard).retainAll(exemplars); - if (common.size() != 0) { - results.add("k∩cldr", common.size()); - } - common = new UnicodeSet(keyboard).removeAll(exemplars); - if (common.size() != 0) { - results.add("k‑cldr", common.size()); - if (keyboardId != null) { - common.remove(0, 0x7F); // don't care much about ASCII. - logInfo.put(Row.of("k-cldr\t" + keyboardId.getBaseLanguage(), common), keyboardId); - // Log.logln(keyboardId + "\tk-cldr\t" + common.toPattern(false)); - } - } - common = new UnicodeSet(exemplars).removeAll(keyboard).remove("ss"); - if (common.size() != 0) { - results.add("cldr‑k", common.size()); - if (keyboardId != null && SKIP_LOG.containsNone(common)) { - logInfo.put(Row.of("cldr‑k\t" + keyboardId.getBaseLanguage(), common), keyboardId); - // Log.logln(keyboardId + "\tcldr‑k\t" + common.toPattern(false)); - } - } - } - - static final UnicodeSet SKIP_LOG = new UnicodeSet("[가一]").freeze(); - static Relation, Id> logInfo = - Relation.of(new TreeMap, Set>(), TreeSet.class); - - static class Id implements Comparable { - final String locale; - final String platform; - final String variant; - final String platformVersion; - - Id(String input, String platformVersion) { - int pos = input.indexOf("-t-k0-"); - String localeTemp = input.substring(0, pos); - locale = ULocale.minimizeSubtags(ULocale.forLanguageTag(localeTemp)).toLanguageTag(); - pos += 6; - int pos2 = input.indexOf('-', pos); - if (pos2 > 0) { - platform = input.substring(pos, pos2); - variant = input.substring(pos2 + 1); - } else { - platform = input.substring(pos); - variant = ""; - } - this.platformVersion = platformVersion; - } - - @Override - public int compareTo(Id other) { - int result; - if (0 != (result = locale.compareTo(other.locale))) { - return result; - } - if (0 != (result = platform.compareTo(other.platform))) { - return result; - } - if (0 != (result = variant.compareTo(other.variant))) { - return result; - } - return 0; - } - - @Override - public String toString() { - return locale + "/" + platform + "/" + variant; - } - - public String getBaseLanguage() { - int pos = locale.indexOf('-'); - return pos < 0 ? locale : locale.substring(0, pos); - } - } - - static class IdSet { - Map> data = new TreeMap<>(); - - public void add(Id id) { - Relation platform2variant = data.get(id.platform); - if (platform2variant == null) { - data.put( - id.platform, - platform2variant = - Relation.of(new TreeMap>(), TreeSet.class)); - } - platform2variant.put(id.locale, id.variant); - } - - public void addAll(Collection idSet) { - for (Id id : idSet) { - add(id); - } - } - - public String toString(IdSet allIds) { - if (this.equals(allIds)) { - return "*"; - } - StringBuilder b = new StringBuilder(); - final Set>> entrySet = data.entrySet(); - boolean first = true; - for (Entry> entry : entrySet) { - if (first) { - first = false; - } else { - b.append(" "); - } - String key = entry.getKey(); - Set>> valueSet = entry.getValue().keyValuesSet(); - b.append(key).append(":"); - appendLocaleAndVariants(b, valueSet, allIds.data.get(key)); - } - return b.toString(); - } - - private void appendLocaleAndVariants( - StringBuilder b, - Set>> set, - Relation relation) { - if (set.equals(relation.keyValuesSet())) { - b.append("*"); - return; - } - final int setSize = set.size(); - if (setSize > 9) { - b.append(setSize).append("/").append(relation.size()); - return; - } - final boolean isSingle = setSize == 1; - if (!isSingle) b.append("("); - boolean first = true; - for (Entry> item : set) { - if (first) { - first = false; - } else { - b.append("|"); - } - final String key = item.getKey(); - b.append(key); - final Set variants = item.getValue(); - final int size = variants.size(); - if (size != 0) { - if (size == 1) { - String firstOne = variants.iterator().next(); - if (firstOne.isEmpty()) { - continue; // fr-CA/∅ => fr-CA - } - } - b.append("/"); - appendVariant(b, variants, relation.get(key)); - } - } - if (!isSingle) b.append(")"); - } - - private void appendVariant(StringBuilder b, Set set, Set set2) { - if (set.equals(set2)) { - b.append("*"); - return; - } - final boolean isSingle = set.size() == 1; - if (!isSingle) b.append("("); - boolean first = true; - for (String item : set) { - if (first) { - first = false; - } else { - b.append("|"); - } - b.append(item.isEmpty() ? "∅" : item); - } - if (!isSingle) b.append(")"); - } - - public boolean isEquals(Object other) { - return data.equals(((IdSet) other).data); - } - - @Override - public int hashCode() { - return data.hashCode(); - } - } - - // public static class Key { - // Iso iso; - // ModifierSet modifierSet; - // } - // /** - // * Return all possible results. Could be external utility. WARNING: doesn't account for - // transform='no' or - // failure='omit'. - // */ - // public Map> getPossibleSource() { - // Map> results = new HashMap>(); - // UnicodeSet results = new UnicodeSet(); - // addOutput(getBaseMap().iso2output.values(), results); - // for (KeyMap keymap : getKeyMaps()) { - // addOutput(keymap.string2output.values(), results); - // } - // for (Transforms transforms : getTransforms().values()) { - // // loop, to catch empty case - // for (String result : transforms.string2string.values()) { - // if (!result.isEmpty()) { - // results.add(result); - // } - // } - // } - // return results; - // } - - static UnicodeSet getQuotationMarks(CLDRFile file) { - UnicodeSet results = new UnicodeSet(); - // TODO should have a test to make sure these are in exemplars. - results.add(file.getStringValue("//ldml/delimiters/quotationEnd")); - results.add(file.getStringValue("//ldml/delimiters/quotationStart")); - results.add(file.getStringValue("//ldml/delimiters/alternateQuotationEnd")); - results.add(file.getStringValue("//ldml/delimiters/alternateQuotationStart")); - return results; - } - - // TODO Add as utility to CLDRFile - static UnicodeSet getNumericExemplars(CLDRFile file) { - UnicodeSet results = new UnicodeSet(); - String defaultNumberingSystem = - file.getStringValue("//ldml/numbers/defaultNumberingSystem"); - String nativeNumberingSystem = - file.getStringValue("//ldml/numbers/otherNumberingSystems/native"); - // "//ldml/numbers/otherNumberingSystems/native" - addNumberingSystem(file, results, "latn"); - if (!defaultNumberingSystem.equals("latn")) { - addNumberingSystem(file, results, defaultNumberingSystem); - } - if (!nativeNumberingSystem.equals("latn") - && !nativeNumberingSystem.equals(defaultNumberingSystem)) { - addNumberingSystem(file, results, nativeNumberingSystem); - } - return results; - } - - public static void addNumberingSystem( - CLDRFile file, UnicodeSet results, String numberingSystem) { - String digits = supplementalDataInfo.getDigits(numberingSystem); - results.addAll(digits); - addSymbol(file, numberingSystem, "decimal", results); - addSymbol(file, numberingSystem, "group", results); - addSymbol(file, numberingSystem, "minusSign", results); - addSymbol(file, numberingSystem, "percentSign", results); - addSymbol(file, numberingSystem, "plusSign", results); - } - - public static void addSymbol( - CLDRFile file, String numberingSystem, String key, UnicodeSet results) { - String symbol = - file.getStringValue( - "//ldml/numbers/symbols[@numberSystem=\"" + numberingSystem + "\"]/" + key); - results.add(symbol); - } -} diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java index c9026fde5c2..6c2fbe5d7e3 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/CLDRFile.java @@ -2020,7 +2020,7 @@ public void startDTD(String name, String publicId, String systemId) throws SAXEx + ", systemId: " + systemId); commentStack++; - target.dtdType = DtdType.valueOf(name); + target.dtdType = DtdType.fromElement(name); target.dtdData = dtdData = DtdData.getInstance(target.dtdType); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdData.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdData.java index 2a66d2d3d9e..c4ec1836c83 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdData.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdData.java @@ -438,7 +438,7 @@ public enum ValueStatus { private DtdData(DtdType type, String version) { this.dtdType = type; - this.ROOT = elementFrom(type.rootType.toString()); + this.ROOT = elementFrom(type.rootElement()); this.version = version; } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdType.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdType.java index c3c5528d6e9..fc128dc55a8 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdType.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdType.java @@ -29,16 +29,22 @@ public enum DtdType { "transforms", "validity"), ldmlBCP47("common/dtd/ldmlBCP47.dtd", "1.7.2", null, "bcp47"), - // keyboard 3.0 - keyboard("keyboards/dtd/ldmlKeyboard.dtd", "44.0", null, "../keyboards/3.0"), - keyboardTest("keyboards/dtd/ldmlKeyboardTest.dtd", "44.0", null, "../keyboards/test"); + keyboard3("keyboards/dtd/ldmlKeyboard3.dtd", "44.0", null, "../keyboards/3.0"), + keyboardTest3("keyboards/dtd/ldmlKeyboardTest3.dtd", "44.0", null, "../keyboards/test"); + public static final Set STANDARD_SET = - ImmutableSet.of(ldmlBCP47, supplementalData, ldml, keyboard); + ImmutableSet.of(ldmlBCP47, supplementalData, ldml, keyboard3); static Pattern FIRST_ELEMENT = PatternCache.get("//([^/\\[]*)"); public final String dtdPath; + /** + * The actual root type used with the DTD. Used for ldmlICU.dtd which is used with the + * root type. This mechanism isn't used for keyboard2, which simply has a different element + * name, but is not used with the prior DTD. + */ public final DtdType rootType; + public final String firstVersion; public final Set directories; @@ -60,7 +66,14 @@ private DtdType(String dtdPath, String firstVersion, DtdType realType, String... public static DtdType fromPath(String elementOrPath) { Matcher m = FIRST_ELEMENT.matcher(elementOrPath); m.lookingAt(); - return DtdType.valueOf(m.group(1)); + return fromElement(m.group(1)); + } + + /** + * @return the DtdType, given an element name + */ + public static DtdType fromElement(String element) { + return DtdType.valueOf(element); } /** @@ -89,7 +102,7 @@ public String header(Class generatedBy) { return "\n" + "\n" // "common/dtd/ldmlSupplemental.dtd" @@ -98,10 +111,21 @@ public String header(Class generatedBy) { + gline + " -->\n" + "<" - + this + + rootElement() + ">\n"; } + /** + * @return the root element for this DTD Type. Usually matches the DTD name. + */ + public String rootElement() { + if (rootType != null) { + return rootType.name(); + } else { + return name(); + } + } + public String getXsdPath() { return dtdPath.replaceAll("\\.dtd$", ".xsd"); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/ElementAttributeInfo.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/ElementAttributeInfo.java index f86b8bb80c7..85c02e1affb 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/ElementAttributeInfo.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/ElementAttributeInfo.java @@ -73,17 +73,17 @@ public static final ElementAttributeInfo getInstance(String commonDirectory, Dtd canonicalCommonDirectory + "/bcp47/calendar.xml", DtdType.ldmlBCP47)); result.put( - DtdType.keyboard, + DtdType.keyboard3, new ElementAttributeInfo( canonicalCommonDirectory + "/../keyboards/3.0/fr-t-k0-azerty.xml", - DtdType.keyboard)); + DtdType.keyboard3)); result.put( - DtdType.keyboardTest, + DtdType.keyboardTest3, new ElementAttributeInfo( canonicalCommonDirectory + "/../keyboards/test/fr-t-k0-azerty-test.xml", - DtdType.keyboardTest)); + DtdType.keyboardTest3)); cache.put(commonDirectory, result); cache.put(canonicalCommonDirectory, result); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/SupplementalDataInfo.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/SupplementalDataInfo.java index e9714b0e417..1b24733627d 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/SupplementalDataInfo.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/SupplementalDataInfo.java @@ -4897,7 +4897,7 @@ public AttributeValidityInfo( } else { Set temp = EnumSet.noneOf(DtdType.class); for (String s : WHITESPACE_SPLTTER.split(dtds)) { - temp.add(DtdType.valueOf(s)); + temp.add(DtdType.fromElement(s)); } this.dtds = Collections.unmodifiableSet(temp); } diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/util/XPathParts.java b/tools/cldr-code/src/main/java/org/unicode/cldr/util/XPathParts.java index 86513ca009d..6cad7f5e3ff 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/util/XPathParts.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/util/XPathParts.java @@ -491,7 +491,7 @@ public XPathParts addElement(String element) { * Use it to set dtdData. */ File dir = CLDRConfig.getInstance().getCldrBaseDirectory(); - dtdData = DtdData.getInstance(DtdType.valueOf(element), dir); + dtdData = DtdData.getInstance(DtdType.fromElement(element), dir); } catch (Exception e) { dtdData = null; } diff --git a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-keycodes.csv b/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-keycodes.csv deleted file mode 100644 index 08f4d358b1e..00000000000 --- a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-keycodes.csv +++ /dev/null @@ -1,53 +0,0 @@ -keycode,iso -50,E00 -18,E01 -19,E02 -20,E03 -21,E04 -23,E05 -22,E06 -26,E07 -28,E08 -25,E09 -29,E10 -27,E11 -24,E12 -93,E13 -12,D01 -13,D02 -14,D03 -15,D04 -17,D05 -16,D06 -32,D07 -34,D08 -31,D09 -35,D10 -33,D11 -30,D12 -42,D13 -0,C01 -1,C02 -2,C03 -3,C04 -5,C05 -4,C06 -38,C07 -40,C08 -37,C09 -41,C10 -39,C11 -10,B00 -6,B01 -7,B02 -8,B03 -9,B04 -11,B05 -45,B06 -46,B07 -43,B08 -47,B09 -44,B10 -94,B11 -49,A03 - diff --git a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-locales.csv b/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-locales.csv deleted file mode 100644 index 80fd79dd406..00000000000 --- a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/osx/osx-locales.csv +++ /dev/null @@ -1,134 +0,0 @@ -name,locale,attributes -Arabic-QWERTY,ar,qwerty -Afghan Dari,fa-AF, -Afghan Pashto,ps, -Afghan Uzbek,uz-Arab, -Arabic,ar, -Arabic-AZERTY,ar,azerty -Arabic-North_Africa,ar,var -Arabic PC,ar,qwerty-var -Armenian-HM QWERTY,hy, -Armenian-Western QWERTY,hy-arevmda, -Australian,en-AU, -Austrian,de-AT, -Azeri,az, -Bangla,bn, -Bangla-QWERTY,bn,qwerty -Belgian,"nl-BE,de-BE,fr-BE", -Brazilian,pt, -Brazilian-ABNT2,pt,var -British,en-GB, -British-PC,en-GB,var -Bulgarian,bg, -Bulgarian - Phonetic,bg,qwerty -Byelorussian,be, -Canadian,en-CA, -Canadian - CSA,fr-CA, -Cherokee-Nation,chr, -Cherokee-QWERTY,chr,qwerty -Colemak,en,colemak -Croatian,hr, -Croatian-PC,hr,var -Czech,cs, -Czech-QWERTY,cs,qwerty -Danish,da, -Devanagari,hi, -Devanagari-QWERTY,hi,qwerty -Dutch,nl, -Dvorak,en,dvorak -Dvorak - Left,en,dvorakl -DVORAK - QWERTY CMD,en,dvorak-qwerty -Dvorak - Right,en,dvorakr -Estonian,et, -Faroese,fo, -Finnish,fi, -FinnishSami-PC,fi,var -Finnish Extended,fi,extended -French,fr, -French - numerical,fr,var -French-PC,fr,qwerty -German,de, -Georgian-QWERTY,ka, -Greek,el, -Greek Polytonic,el-polyton, -Gujarati,gu, -Gujarati-QWERTY,gu,qwerty -Gurmukhi,pa, -Gurmukhi-QWERTY,pa,qwerty -Hawaiian,haw, -Hebrew,he, -Hebrew-QWERTY,he,qwerty -Hebrew-PC,he,var -Hungarian,hu, -Hungarian-QWERTY,hu,qwerty -Icelandic,is, -Inuktitut-Nunavut,iu, -Inuktitut-Nutaaq,iu,nutaaq -Inuktitut-QWERTY,iu,qwerty -Inuttitut Nunavik,iu,var -Irish,ga, -Irish Extended,ga,extended -Italian,it, -Italian - Pro,it,extended -Jawi-QWERTY,ms, -Kannada,kn, -Kannada-QWERTY,kn,qwerty -Kazakh,kk, -Khmer,km, -Kurdish-Sorani,ckb, -Latvian,lv, -Lithuanian,lt, -Macedonian,mk, -Malayalam,ml, -Malayalam-QWERTY,ml,qwerty -Maltese,mt, -Maori,mi, -Nepali,ne, -Northern Sami,se, -Norwegian,nb, -Norwegian Extended,nb,extended -NorwegianSami-PC,nb,extended-var -Oriya,or, -Oriya-QWERTY,or,qwerty -Persian,fa, -Persian-ISIRI 2901,fa,isiri -Persian-QWERTY,fa,qwerty -Polish,pl, -Polish Pro,pl,extended -Portuguese,pt-PT, -Romanian,ro, -Romanian-Standard,ro,extended -Russian,ru, -RussianWin,ru,extended -Russian - Phonetic,ru,qwerty -Serbian,sr, -Serbian-Latin,sr-Latn, -Sinhala,si, -Sinhala-QWERTY,si,qwerty -Slovak,sk, -Slovak-QWERTY,sk,qwerty -Slovenian,sl, -Spanish,es, -Spanish - ISO,es,extended -Swedish,sv, -SwedishSami-PC,sv,extended-var -Swedish - Pro,sv,extended -Swiss French,fr-CH, -Swiss German,de-CH, -Telugu,te, -Telugu-QWERTY,te,qwerty -TibetanOtaniUS,bo, -Tibetan-QWERTY,bo,qwerty -Thai,th, -Thai-PattaChote,th,patta -Turkish,tr, -Turkish-QWERTY,tr,qwerty -Turkish-QWERTY-PC,tr,qwerty-var -Urdu,ur, -U.S.,en, -Ukrainian,uk, -USInternational-PC,en,extended-var -US Extended,en,extended -Uyghur,ug, -Vietnamese,vi, -Welsh,cy, diff --git a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/test/windows/test_layout.txt b/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/test/windows/test_layout.txt deleted file mode 100644 index 627df55ab84..00000000000 --- a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/test/windows/test_layout.txt +++ /dev/null @@ -1,41 +0,0 @@ -SHIFTSTATE - -0 //Column 4 -1 //Column 5 : Shft -3 //Column 7 : Shft Ctrl - -LAYOUT ;an extra '@' at the end is a dead key - -//SC VK_ Cap 0 1 2 -02 1 0 1 0021 -1 // DIGIT ONE, EXCLAMATION MARK, , PLUS-MINUS SIGN -03 2 0 2 0022 -1 // DIGIT TWO, QUOTATION MARK, , COMMERCIAL AT - -LIGATURE - -//VK_ Mod# Char0 Char1 Char2 Char3 -3 1 094d 0930 // DEVANAGARI SIGN VIRAMA + DEVANAGARI LETTER RA -4 1 0930 094d // DEVANAGARI LETTER RA + DEVANAGARI SIGN VIRAMA - -DEADKEY 0060 - -0061 00e0 // a -> à -0065 00e8 // e -> è - -DEADKEY 00b4 - -0061 00e1 // a -> á -0065 00e9 // e -> é - -KEYNAME - -01 Esc - -DESCRIPTIONS - -0409 Canadian French - Custom - -LANGUAGENAMES - -0409 English (Canada) - -ENDKBD \ No newline at end of file diff --git a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-keycodes.csv b/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-keycodes.csv deleted file mode 100644 index 4a407774d3d..00000000000 --- a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-keycodes.csv +++ /dev/null @@ -1,51 +0,0 @@ -keycode,iso -41,E00 -2,E01 -3,E02 -4,E03 -5,E04 -6,E05 -7,E06 -8,E07 -9,E08 -10,E09 -11,E10 -12,E11 -13,E12 -16,D01 -17,D02 -18,D03 -19,D04 -20,D05 -21,D06 -22,D07 -23,D08 -24,D09 -25,D10 -26,D11 -27,D12 -30,C01 -31,C02 -32,C03 -33,C04 -34,C05 -35,C06 -36,C07 -37,C08 -38,C09 -39,C10 -40,C11 -43,C12 -86,B00 -44,B01 -45,B02 -46,B03 -47,B04 -48,B05 -49,B06 -50,B07 -51,B08 -52,B09 -53,B10 -115,B11 -57,A03 diff --git a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-locales.csv b/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-locales.csv deleted file mode 100644 index 6a9fd8f3f10..00000000000 --- a/tools/cldr-code/src/main/resources/org/unicode/cldr/draft/keyboard/windows/windows-locales.csv +++ /dev/null @@ -1,208 +0,0 @@ -name,locale,attributes -Arabic (102),ar,102key -Albanian,sq, -Arabic (101),ar, -Arabic (102) AZERTY,ar,azerty -Armenian Eastern (Legacy),hy,legacy -Armenian Phonetic,hy,phonetic -Armenian Typewriter,hy, -Armenian Western (Legacy),hy-AREVMDA, -Assamese - INSCRIPT,as, -Azeri Cyrillic,az-Cyrl, -Azeri Latin,az, -Azerbaijani (Standard),az,extended -Bashkir,ba, -Belarusian,be, -Belgian (Comma),de-BE, -Belgian (Comma),fr-BE, -Belgian (Comma),nl-BE, -Belgian (Period),de-BE,var -Belgian (Period),fr-BE,var -Belgian (Period),nl-BE,var -Belgian French,fr-BE, -Bengali,bn,qwerty -Bengali - INSCRIPT,bn, -Bengali - INSCRIPT (Legacy),bn,legacy -Bosnian (Cyrillic),bs-Cyrl, -Buginese,bug, -Bulgarian,bg, -Bulgarian (Latin),bg-Latn, -Bulgarian (Phonetic Traditional),bg,qwerty-legacy -Bulgarian (Phonetic),bg,qwerty -Bulgarian (Typewriter),bg,legacy -Canadian French,fr-CA,var -Canadian French (Legacy),fr-CA,legacy -Canadian Multilingual Standard,fr-CA, -Central Atlas Tamazight,tzm, -Central Kurdish,ckb, -Cherokee Phonetic,chr,phonetic -Cherokee Nation,chr, -"Chinese (Simplified, Singapore) - US",zh-SG, -Chinese (Simplified) - US,zh, -"Chinese (Traditional, Hong Kong S.A.R.) - US",zh-HK, -"Chinese (Traditional, Macao S.A.R.) - US",zh-MO, -Chinese (Traditional) - US,zh-Hant, -Czech,cs, -Czech (QWERTY),cs,qwerty -Czech Programmers,cs,extended -Danish,da, -Devanagari - INSCRIPT,hi, -Divehi Phonetic,dv, -Divehi Typewriter,dv,legacy -Dutch,nl, -Dzongkha,dz, -English (India),en-IN, -Estonian,et, -Faeroese,fo, -Finnish,fi, -Finnish with Sami,fi,extended -French,fr, -Futhark,non, -Georgian (Ergonomic),ka,var -Georgian (Legacy),ka,legacy -Georgian (MES),ka, -Georgian (Old Alphabets),ka,legacy-var -Georgian (QWERTY),ka,qwerty -German,de, -German (IBM),de,extended -Gothic,got, -Greek,el, -Greek (220),el,el220 -Greek (220) Latin,el-Latn,el220 -Greek (319),el,el319 -Greek (319) Latin,el-Latn,el319 -Greek Latin,el-Latn, -Greek Polytonic,el-POLYTON, -Greenlandic,kl, -Guarani,gn, -Gujarati,gu, -Hausa,ha, -Hawaiian,haw, -Hebrew,he, -Hebrew (Standard),he,extended -Hindi Traditional,hi,legacy -Hungarian,hu, -Hungarian 101-key,hu,101key -Icelandic,is, -Igbo,ig, -Inuktitut - Latin,iu,var -Inuktitut - Naqittaut,iu, -Irish,ga, -Italian,it, -Italian (142),it,var -Japanese,ja, -Javanese,jv, -Kannada,kn, -Kazakh,kk, -Khmer,km, -Khmer (NIDA),km,extended -Korean,ko, -Kyrgyz Cyrillic,ky, -Lao,lo, -Latin American,es-419, -Latvian,lv, -Latvian (QWERTY),lv,qwerty -Latvian (Standard),lv,extended -Lisu (Basic),lis, -Lisu (Standard),lis,extended -Lithuanian,lt, -Lithuanian IBM,lt,lt1205 -Lithuanian Standard,lt,lt1582 -Luxembourgish,lb, -Macedonian (FYROM),mk,legacy -Macedonian (FYROM) - Standard,mk, -Malayalam,ml, -Maltese 47-Key,mt,101key -Maltese 48-Key,mt, -Māori,mi, -Marathi,mr, -Mongolian (Mongolian Script),mn-Mong, -Mongolian Cyrillic,mn, -Traditional Mongolian (Standard),mn-Mong,extended -Myanmar,my, -Nepali,ne, -New Tai Lue,khb, -N’Ko,bm, -Norwegian,nb, -Norwegian with Sami,nb,extended -Odia,or, -Ogham,ga-Ogam, -Ol Chiki,sat-Olck, -Old Italic,la-Ital, -Osmanya,so-Osma, -Pashto (Afghanistan),ps, -Persian,fa, -Persian (Standard),fa,extended -Phags-pa,mn-Phag, -Polish (214),pl, -Polish (Programmers),pl,extended -Portuguese,pt-PT, -Portuguese (Brazil ABNT),pt, -Portuguese (Brazil ABNT2),pt,var -Punjabi,pa, -Romanian (Legacy),ro,legacy -Romanian (Programmers),ro,extended -Romanian (Standard),ro, -Russian,ru, -Russian (Typewriter),ru,legacy -Russian - Mnemonic,ru,phonetic -Sakha,sah, -Sami Extended Finland-Sweden,se-FI, -Sami Extended Finland-Sweden,se-SE, -Sami Extended Norway,se, -Scottish Gaelic,gd, -Serbian (Cyrillic),sr, -Serbian (Latin),sr-Latn, -Sesotho sa Leboa,nso, -Setswana,tn, -Sinhala,si,legacy -Sinhala - Wij 9,si, -Slovak,sk, -Slovak (QWERTY),sk,qwerty -Slovenian,sl, -Sora,srb, -Sorbian Extended,dsb,extended -Sorbian Standard,dsb, -Sorbian Standard (Legacy),dsb,legacy -Spanish,es, -Spanish Variation,es,extended -Swedish,sv, -Swedish with Sami,sv,extended -Swiss French,fr-CH, -Swiss German,de-CH, -Syriac,syr, -Syriac Phonetic,syr,qwerty -Tai Le,khb-Tale, -Tajik,tg, -Tamil,ta, -Tatar,tt, -Tatar (Legacy),tt,legacy -Telugu,te, -Thai Kedmanee,th, -Thai Kedmanee (non-ShiftLock),th,var -Thai Pattachote,th,patta -Thai Pattachote (non-ShiftLock),th,patta-var -Tibetan (PRC),bo, -Tibetan (PRC) - Updated,bo,extended -Tifinagh (Basic),tmh, -Tifinagh (Extended),tmh,extended -Turkish F,tr,legacy -Turkish Q,tr, -Turkmen,tk, -Ukrainian,uk, -Ukrainian (Enhanced),uk,extended -United Kingdom,en-GB, -United Kingdom Extended,en-GB,extended -United States-Dvorak,en,dvorak -United States-Dvorak for left hand,en,dvorakl -United States-Dvorak for right hand,en,dvorakr -United States-International,en,extended -Urdu,ur, -US,en, -US English Table for IBM Arabic 238_L,en,var -Uyghur,ug, -Uyghur (Legacy),ug,legacy -Uzbek Cyrillic,uz, -Vietnamese,vi, -Wolof,wo, -Yoruba,yo, diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java index 6ea865a55bb..e943ce3048c 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestAttributeValues.java @@ -307,9 +307,9 @@ private void checkAttribute(String element, String attribute, String attrValue) } void show(boolean verbose, ImmutableSet retain) { - if (dtdData.dtdType == DtdType.keyboard + if (dtdData.dtdType == DtdType.keyboard3 && testLog.logKnownIssue("CLDR-14974", "skipping for keyboard")) { - testLog.warnln("Skipping for keyboard"); + testLog.warnln("Skipping for keyboard3"); } boolean haveProblems = false; // if (testLog.logKnownIssue("cldrbug 10120", "Don't enable error until diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java index 2953fb3b60a..fc0887bd595 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestBasic.java @@ -1408,7 +1408,7 @@ public void TestDtdCompatibility() { switch (type) { case ldmlBCP47: case ldmlICU: - case keyboard: + case keyboard3: tooOld = version.isOlderThan(CldrVersion.from(type.firstVersion)); break; default: @@ -1549,6 +1549,7 @@ public void checkDtdComparatorFor(File fileToRead, DtdType overrideDtdType) { xfr.read(myHandler.fileName, -1, true); logln(myHandler.fileName); } catch (Exception e) { + e.printStackTrace(); Throwable t = e; StringBuilder b = new StringBuilder(); String indent = ""; diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestComparisonBuilder.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestComparisonBuilder.java index 421795f8d66..588c9c90bcf 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestComparisonBuilder.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestComparisonBuilder.java @@ -86,7 +86,7 @@ public void TestDtdElements() { continue; } Builder builder = new Builder(Ordering.NATURAL); - builder.add(dtd.toString()); + builder.add(dtd.rootElement()); Relation eaInfo = ElementAttributeInfo.getInstance(dtd).getElement2Children(); for (String element : eaInfo.keySet()) { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDtdData.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDtdData.java index 0eda5c0e480..95e3f00aa36 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDtdData.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestDtdData.java @@ -454,7 +454,7 @@ public void TestNewDtdData() { /** paths that can be empty elements. Each item starts with '!' because of showPath. */ static final Set ALLOWED_EMPTY_NO_VALUE_PATHS = Collections.unmodifiableSet( - new HashSet<>(Arrays.asList("!//keyboardTest/tests/test/backspace"))); + new HashSet<>(Arrays.asList("!//keyboardTest3/tests/test/backspace"))); // TESTING CODE static final Set orderedElements = @@ -581,9 +581,9 @@ public void TestNewDtdData() { public static boolean isOrderedOld(String element, DtdType type) { switch (type) { - case keyboardTest: + case keyboardTest3: return orderedKeyboardTestElements.contains(element); - case keyboard: + case keyboard3: return orderedKeyboardElements.contains(element); default: // all others, above @@ -756,8 +756,8 @@ public boolean isDistinguishingOld(DtdType dtdType, String elementName, String a || (elementName.equals("nameOrderLocalesDefault") && attribute.equals("order")); - case keyboard: - if (elementName.equals("keyboard") && attribute.equals("locale") + case keyboard3: + if (elementName.equals("keyboard3") && attribute.equals("locale") || elementName.equals("vkeys") && attribute.equals("from") || elementName.equals("layers") && attribute.equals("form") || elementName.equals("layers") && attribute.equals("minDeviceWidth") @@ -776,7 +776,7 @@ public boolean isDistinguishingOld(DtdType dtdType, String elementName, String a } // fall through to old keyboard return attribute.equals("_q") - || elementName.equals("keyboard") && attribute.equals("locale") + || elementName.equals("keyboard3") && attribute.equals("locale") || elementName.equals("keyMap") && attribute.equals("modifiers") || elementName.equals("key") && attribute.equals("flicks") || elementName.equals("transforms") && attribute.equals("type") @@ -794,7 +794,7 @@ public boolean isDistinguishingOld(DtdType dtdType, String elementName, String a || elementName.equals("display") && attribute.equals("id") || elementName.equals("flicks") && attribute.equals("id") || elementName.equals("flick") && attribute.equals("directions"); - case keyboardTest: + case keyboardTest3: return elementName.equals("tests") && attribute.equals("name") || elementName.equals("test") && attribute.equals("name") || elementName.equals("repertoire") && attribute.equals("name") diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboard.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboard.java deleted file mode 100644 index d929e494f57..00000000000 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboard.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.unicode.cldr.unittest; - -import static org.unicode.cldr.util.PathUtilities.getNormalizedPathString; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; -import org.unicode.cldr.draft.Keyboard; -import org.unicode.cldr.draft.Keyboard.KeyboardWarningException; -import org.unicode.cldr.util.CLDRConfig; - -public class TestKeyboard extends TestFmwkPlus { - public static void main(String[] args) { - new TestKeyboard().run(args); - } - - static final String dtdLocation = - getNormalizedPathString(CLDRConfig.getInstance().getCldrBaseDirectory()) - + "/keyboards/dtd/ldmlKeyboard.dtd"; - - public void TestGoodSample() throws IOException { - // preload these to make debugging easier - // DtdData.getInstance(DtdType.ldml); - // DtdData.getInstance(DtdType.keyboard); - - String fixedDtdReference = sampleGood.replace("../dtd/ldmlKeyboard.dtd", dtdLocation); - Reader r = new StringReader(fixedDtdReference); - Set errors = new LinkedHashSet<>(); - Keyboard.getKeyboard("no-error", r, errors); - assertEquals("sample-without-errors", Collections.EMPTY_SET, errors); - } - - public void TestBadSample() throws IOException { - // preload these to make debugging easier - // DtdData.getInstance(DtdType.ldml); - // DtdData.getInstance(DtdType.keyboard); - - String fixedDtdReference = sampleBad.replace("../dtd/ldmlKeyboard.dtd", dtdLocation); - Reader r = new StringReader(fixedDtdReference); - Set errors = new LinkedHashSet<>(); - Keyboard.getKeyboard("sample-with-error", r, errors); - assertNotEquals("should have errors", Collections.EMPTY_SET, errors); - if (isVerbose()) { - for (Exception e : errors) { - showException(e, ""); - } - } - } - - public void showException(Throwable e, String indent) { - logln(e + "\t" + e.getMessage()); - for (StackTraceElement ste : e.getStackTrace()) { - String className = ste.getClassName(); - if ((className.startsWith("org.unicode") && !className.contains("XMLFileReader")) - || (className.startsWith("com.ibm") && !className.contains("TestFmwk"))) { - logln("\t" + indent + ste); - } - } - Throwable cause = e.getCause(); - if (cause != null) { - showException(cause, "\t" + indent); - } - } - - String sampleGood = - "\n" - + "\n" - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + ""; - - String sampleBad = - "\n" - + "\n" - + "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + ""; - - public void testVerifyKeyboardLoad() { - Set errors = new LinkedHashSet<>(); - for (String keyboardPlatformId : Keyboard.getPlatformIDs()) { - for (String keyboardId : Keyboard.getKeyboardIDs(keyboardPlatformId)) { - errors.clear(); - try { - Keyboard keyboard = - Keyboard.getKeyboard(keyboardPlatformId, keyboardId, errors); - String localeId = keyboard.getLocaleId(); - if (!localeId.equals(keyboardId.replace(".xml", ""))) { - errors.add( - new IllegalArgumentException( - "filename and id don't match:\t" - + keyboardId - + "\t" - + localeId)); - } - } catch (Exception e) { - errors.add(e); - } - int errorCount = 0; - StringBuilder errorString = new StringBuilder(); - for (Exception item : errors) { - if (!(item instanceof KeyboardWarningException)) { - errorCount++; - } - } - msg( - keyboardPlatformId + "\t" + keyboardId, - errors.size() == 0 ? LOG : errorCount == 0 ? WARN : ERR, - true, - true); - for (Exception item : errors) { - showException(item, ""); - } - } - } - } -} diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboardModifierSet.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboardModifierSet.java deleted file mode 100644 index 00fce3bb2ac..00000000000 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestKeyboardModifierSet.java +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2012 Google Inc. All Rights Reserved. - -package org.unicode.cldr.unittest; - -import com.ibm.icu.dev.test.TestFmwk; -import java.util.EnumSet; -import org.unicode.cldr.draft.KeyboardModifierSet; -import org.unicode.cldr.draft.KeyboardModifierSet.Modifier; - -/** - * @author rwainman@google.com (Raymond Wainman) - */ -public class TestKeyboardModifierSet extends TestFmwk { - public static void main(String[] args) { - new TestKeyboardModifierSet().run(args); - } - - public void testParseSet_null() { - try { - KeyboardModifierSet.parseSet(null); - errln("Should have error"); - } catch (IllegalArgumentException e) { - // Expected behavior - } - } - - public void testParseSet_empty() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet(""); - - assertNotNull("x", modifierSet); - assertEquals("x", 1, modifierSet.getVariants().size()); - EnumSet emptySet = - EnumSet.noneOf(KeyboardModifierSet.Modifier.class); - assertTrue("x", modifierSet.contains(emptySet)); - } - - public void testParseSet_allOnKeys() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("cmd+ctrlL+altR"); - - assertNotNull("x", modifierSet); - assertEquals("x", 1, modifierSet.getVariants().size()); - EnumSet testSet = EnumSet.of(Modifier.cmd, Modifier.ctrlL, Modifier.altR); - assertTrue("x", modifierSet.contains(testSet)); - } - - public void testParseSet_allDontCareKeys() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("cmd?+ctrlL?"); - - assertNotNull("x", modifierSet); - assertEquals("x", 4, modifierSet.getVariants().size()); - assertTrue("x", modifierSet.contains(EnumSet.noneOf(Modifier.class))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.cmd))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.ctrlL))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.cmd, Modifier.ctrlL))); - } - - public void testParseSet_mix() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("optR+shiftR+ctrlL?"); - - assertNotNull("x", modifierSet); - assertEquals("x", 2, modifierSet.getVariants().size()); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.optR, Modifier.shiftR))); - assertTrue( - "x", - modifierSet.contains(EnumSet.of(Modifier.optR, Modifier.shiftR, Modifier.ctrlL))); - } - - public void testParseSet_parentOn() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("alt"); - - assertNotNull("x", modifierSet); - assertEquals("x", 3, modifierSet.getVariants().size()); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.altL))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.altR))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.altL, Modifier.altR))); - } - - public void testParseSet_parentDontCare() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("alt?"); - - assertNotNull("x", modifierSet); - assertEquals("x", 4, modifierSet.getVariants().size()); - assertTrue("x", modifierSet.contains(EnumSet.noneOf(Modifier.class))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.altL))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.altR))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.altL, Modifier.altR))); - } - - public void testParseSet_parentMix() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("cmd+shift+alt?+caps?"); - - assertNotNull("x", modifierSet); - // 3 (shift) * 4 (alt?) * 2 (caps?) = 24 - assertEquals("x", 24, modifierSet.getVariants().size()); - } - - public void testParseSet_multiple() { - KeyboardModifierSet modifierSet = KeyboardModifierSet.parseSet("optR+caps? cmd+shift"); - assertNotNull("x", modifierSet); - assertEquals("x", 5, modifierSet.getVariants().size()); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.optR))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.optR, Modifier.caps))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.cmd, Modifier.shiftL))); - assertTrue("x", modifierSet.contains(EnumSet.of(Modifier.cmd, Modifier.shiftR))); - assertTrue( - "x", - modifierSet.contains(EnumSet.of(Modifier.cmd, Modifier.shiftL, Modifier.shiftR))); - } -} diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java index 20676ab3802..bbfbc007e97 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java @@ -1271,8 +1271,8 @@ public void TestCompletenessNonLdmlDtd() { for (DtdType dtdType : DtdType.values()) { if (dtdType == DtdType.ldml || dtdType == DtdType.ldmlICU - || dtdType == DtdType.keyboard - || dtdType == DtdType.keyboardTest) { + || dtdType == DtdType.keyboard3 + || dtdType == DtdType.keyboardTest3) { continue; } DtdData dtdData = DtdData.getInstance(dtdType); diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPaths.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPaths.java index 6cb32ba4815..88cbcce72ac 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPaths.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPaths.java @@ -538,7 +538,7 @@ public void TestNonLdml() { // parts.set(path); // removeNonDistinguishing(parts, dtdData, // counter, removed, nonFinalValues); - if (type != DtdType.keyboardTest + if (type != DtdType.keyboardTest3 || !logKnownIssue( "CLDR-15034", "keyboardTest data appears as duplicate xpaths")) { diff --git a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-missing.xml b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-missing.xml index 8fe2e03dcf2..803de54ae7a 100644 --- a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-missing.xml +++ b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-missing.xml @@ -2,8 +2,8 @@ - + --> + @@ -82,4 +82,4 @@ - + diff --git a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownbase.xml b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownbase.xml index b75697565fe..334cceee9b2 100644 --- a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownbase.xml +++ b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownbase.xml @@ -2,8 +2,8 @@ - + --> + @@ -82,4 +82,4 @@ - + diff --git a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownver.xml b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownver.xml index 3f301db3ae4..8907032203c 100644 --- a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownver.xml +++ b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-unknownver.xml @@ -2,8 +2,8 @@ - + --> + @@ -82,4 +82,4 @@ - + diff --git a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-wrongparent.xml b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-wrongparent.xml index 78ea52773d0..c5a63cbae0c 100644 --- a/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-wrongparent.xml +++ b/tools/cldr-code/src/test/resources/org/unicode/cldr/tool/KeyboardFlatten/broken-import-wrongparent.xml @@ -2,8 +2,8 @@ - + --> + @@ -83,4 +83,4 @@ - +