From bd7c89b188369cd98fc0b238701b10978fa8dd7e Mon Sep 17 00:00:00 2001 From: Danny Su Date: Wed, 29 Jan 2025 21:21:10 -0800 Subject: [PATCH] Use the same AndroidUnicodeUtils.java everywhere Summary: hermes and hermes-snapshot have this issue where including both and use their own copies of AndroidUnicodeUtils would cause a package name clash. This is because by having different dependencies, BUCK will try to include 2 packages that have the same package name. The solution used before was to have both take dependency on the same copy of AndroidUnicodeUtils. Now that we're trying to include both Hermes and Static Hermes, we have the same exact issue. For now I'm taking the same approach by moving to a common copy. The code is identical so there isn't a behavioral change. Reviewed By: neildhar Differential Revision: D68173770 fbshipit-source-id: ae62a35a49fc7b8b9680cb47f40457137f717c4d --- .../hermes/unicode/AndroidUnicodeUtils.java | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 lib/Platform/Unicode/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java diff --git a/lib/Platform/Unicode/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java b/lib/Platform/Unicode/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java deleted file mode 100644 index 7e4805ac825..00000000000 --- a/lib/Platform/Unicode/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.hermes.unicode; - -import com.facebook.proguard.annotations.DoNotStrip; -import java.text.Collator; -import java.text.DateFormat; -import java.text.Normalizer; -import java.util.Locale; - -// TODO: use com.facebook.common.locale.Locales.getApplicationLocale() as the current locale, -// rather than the device locale. This is challenging because getApplicationLocale() is only -// available via DI. -@DoNotStrip -public class AndroidUnicodeUtils { - @DoNotStrip - public static int localeCompare(String left, String right) { - Collator collator = Collator.getInstance(); - return collator.compare(left, right); - } - - @DoNotStrip - public static String dateFormat(double unixtimeMs, boolean formatDate, boolean formatTime) { - DateFormat format; - if (formatDate && formatTime) { - format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); - } else if (formatDate) { - format = DateFormat.getDateInstance(DateFormat.MEDIUM); - } else if (formatTime) { - format = DateFormat.getTimeInstance(DateFormat.MEDIUM); - } else { - throw new RuntimeException("Bad dateFormat configuration"); - } - return format.format((long) unixtimeMs).toString(); - } - - @DoNotStrip - public static String convertToCase(String input, int targetCase, boolean useCurrentLocale) { - // These values must match CaseConversion in PlatformUnicode.h - final int targetUppercase = 0; - final int targetLowercase = 1; - // Note Java's case conversions use the user's locale. For example "I".toLowerCase() - // will produce a dotless i. From Java's docs: "To obtain correct results for locale - // insensitive strings, use toLowerCase(Locale.ENGLISH)." - Locale locale = useCurrentLocale ? Locale.getDefault() : Locale.ENGLISH; - switch (targetCase) { - case targetLowercase: - return input.toLowerCase(locale); - case targetUppercase: - return input.toUpperCase(locale); - default: - throw new RuntimeException("Invalid target case"); - } - } - - @DoNotStrip - public static String normalize(String input, int form) { - // Values must match NormalizationForm in PlatformUnicode.h. - final int formC = 0; - final int formD = 1; - final int formKC = 2; - final int formKD = 3; - - switch (form) { - case formC: - return Normalizer.normalize(input, Normalizer.Form.NFC); - case formD: - return Normalizer.normalize(input, Normalizer.Form.NFD); - case formKC: - return Normalizer.normalize(input, Normalizer.Form.NFKC); - case formKD: - return Normalizer.normalize(input, Normalizer.Form.NFKD); - default: - throw new RuntimeException("Invalid form"); - } - } -}