From b1a4cbce3920da8e7b4d3e26ea4f864d08ad26c5 Mon Sep 17 00:00:00 2001 From: zhangdd_ewan Date: Fri, 12 Apr 2024 14:46:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangdd_ewan --- frameworks/i18n/include/date_time_data.h | 1 + frameworks/i18n/include/i18n_memory_adapter.h | 4 ++-- frameworks/i18n/include/plural_format_impl.h | 1 + frameworks/i18n/src/date_time_data.cpp | 2 +- frameworks/i18n/src/plural_format_impl.cpp | 6 +++--- .../src/main/java/ohos/global/i18n/DataFetcher.java | 11 ++++++----- .../src/main/java/ohos/global/i18n/Fetcher.java | 9 +++++++-- .../src/main/java/ohos/global/i18n/FileConfig.java | 2 +- .../src/main/java/ohos/global/i18n/LocaleConfig.java | 6 +++++- .../src/main/java/ohos/global/i18n/LocaleList.java | 2 +- .../main/java/ohos/global/i18n/LocaleMaskItem.java | 5 ++++- .../ohos/global/i18n/MeasureFormatPatternFetcher.java | 2 +- .../src/main/java/ohos/global/i18n/PluralFetcher.java | 5 ++--- .../java/ohos/global/i18n/ResourceConfiguration.java | 8 ++++++-- .../src/main/java/ohos/global/i18n/StringPool.java | 5 ++++- .../src/main/java/ohos/global/i18n/Utils.java | 9 ++++++--- 16 files changed, 51 insertions(+), 27 deletions(-) diff --git a/frameworks/i18n/include/date_time_data.h b/frameworks/i18n/include/date_time_data.h index 339ffa6..3964e4f 100644 --- a/frameworks/i18n/include/date_time_data.h +++ b/frameworks/i18n/include/date_time_data.h @@ -62,6 +62,7 @@ private: char *amPmMarkers = nullptr; char timeSeparator = ':'; char defaultHour = 'H'; + const int CONFIG_MIN_SIZE = 2; }; } // namespace I18N } // namespace OHOS diff --git a/frameworks/i18n/include/i18n_memory_adapter.h b/frameworks/i18n/include/i18n_memory_adapter.h index e3c3541..06dd00c 100644 --- a/frameworks/i18n/include/i18n_memory_adapter.h +++ b/frameworks/i18n/include/i18n_memory_adapter.h @@ -26,12 +26,12 @@ // memory operator define #include -inline void *I18nMalloc(size_t size) +inline static void *I18nMalloc(size_t size) { return malloc(size); } -inline void I18nFree(void *a) +inline static void I18nFree(void *a) { if (a != nullptr) { (void) free(a); diff --git a/frameworks/i18n/include/plural_format_impl.h b/frameworks/i18n/include/plural_format_impl.h index 322be42..5a45e09 100644 --- a/frameworks/i18n/include/plural_format_impl.h +++ b/frameworks/i18n/include/plural_format_impl.h @@ -66,6 +66,7 @@ private: static constexpr int NUMBER_INFO_SIZE = 3; const double EPS = 1e-6; const int MAX_FRACTION_NUMBERS = 6; + const int DECIMALISM = 10; }; } // namespace I18N } // namespace OHOS diff --git a/frameworks/i18n/src/date_time_data.cpp b/frameworks/i18n/src/date_time_data.cpp index 0adf86a..1adec5d 100644 --- a/frameworks/i18n/src/date_time_data.cpp +++ b/frameworks/i18n/src/date_time_data.cpp @@ -31,7 +31,7 @@ DateTimeData::DateTimeData(const char *amPmMarkers, const char *configs, const i } // size must >= 2, The first 2 element of configs need to be extracted, the first element // is the time separator and the second is the default hour. - if (configs && size >= 2) { // 2 is the size of configs need to be extracted + if (configs && size >= CONFIG_MIN_SIZE) { // 2 is the size of configs need to be extracted timeSeparator = configs[0]; defaultHour = configs[1]; } diff --git a/frameworks/i18n/src/plural_format_impl.cpp b/frameworks/i18n/src/plural_format_impl.cpp index 90c61ee..6e6211c 100644 --- a/frameworks/i18n/src/plural_format_impl.cpp +++ b/frameworks/i18n/src/plural_format_impl.cpp @@ -145,9 +145,9 @@ void PluralFormatImpl::ComputeDecimalInfo(double number, int integerNumber, int temp = round(temp); } if (temp - ((int)temp) < EPS) { - while (i > 1 && (int) temp % 10 == 0) { // 10 means decimal + while (i > 1 && (int) temp % DECIMALISM == 0) { // 10 means decimal i--; - temp /= 10; // 10 means decimal + temp /= DECIMALISM; // 10 means decimal } // 10 is base fractionNumber = (int)(temp - integerNumber * pow(10, i)); @@ -378,7 +378,7 @@ int PluralFormatImpl::ParseNumber(const std::string &rule, const int ruleSize, i // Parse number in the formula. while ((index < ruleSize) && (rule[index] != ' ') && (rule[index] != TO) && (rule[index] != COMMA)) { - num *= 10; // 10 means decimal. Calculate decimal value of the number. + num *= DECIMALISM; // 10 means decimal. Calculate decimal value of the number. num += rule[index] - '0'; index++; } diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/DataFetcher.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/DataFetcher.java index 621f842..844a1f1 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/DataFetcher.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/DataFetcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -156,7 +156,8 @@ public class DataFetcher { return sStatus == 0; } - private static int countData(Fetcher currentFetcher, int count, Fetcher fallbackFetcher, ArrayList temp) { + private static int countData(Fetcher currentFetcher, int count, + Fetcher fallbackFetcher, ArrayList temp) { String fallbackData = null; for (int i = 0; i < Fetcher.getResourceCount(); i++) { String targetMetaData = Fetcher.getInt2Str().get(i); @@ -272,7 +273,7 @@ public class DataFetcher { osw.flush(); osw.close(); } catch (IOException e) { - e.printStackTrace(); + LOG.log(Level.SEVERE, "Write locales.json failed: IO exception"); } } @@ -298,7 +299,7 @@ public class DataFetcher { osw.flush(); osw.close(); } catch (IOException e) { - e.printStackTrace(); + LOG.log(Level.SEVERE, "Write file failed: IO exception"); } } @@ -350,7 +351,7 @@ public class DataFetcher { osw.flush(); osw.close(); } catch (IOException e) { - e.printStackTrace(); + LOG.log(Level.SEVERE, "Write measure data failed: IO exception"); } } diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Fetcher.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Fetcher.java index 50a42c6..fe23b6d 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Fetcher.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Fetcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -74,7 +74,8 @@ public class Fetcher implements Runnable, Comparable { */ public final String languageTag; - private boolean included = true; // Indicate whether this Fetcher is included in the final generation process of i18n.dat file. + // Indicate whether this Fetcher is included in the final generation process of i18n.dat file. + private boolean included = true; private String lan; // language private ReentrantLock lock; // Lock used to synchronize dump operation private ULocale locale; @@ -175,6 +176,8 @@ public class Fetcher implements Runnable, Comparable { /** * Get included. + * + * @return If this Fetcher is included in the final generation process of i18n.dat file. */ public boolean getIncluded() { return included; @@ -182,6 +185,8 @@ public class Fetcher implements Runnable, Comparable { /** * Set included. + * + * @param val this Fetcher is included in the final generation process of i18n.dat file. */ public void setIncluded(boolean val) { included = val; diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/FileConfig.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/FileConfig.java index 059f1b5..439f431 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/FileConfig.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/FileConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleConfig.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleConfig.java index af812c3..a601937 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleConfig.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,6 +32,10 @@ public class LocaleConfig { /** * Constructor of class LocaleConfig + * + * @param str Meata data's name + * @param nameId Meta data's index in str2Int + * @param stringId Meta data's index in sIdMap */ public LocaleConfig(String str, int nameId, int stringId) { this.name = str; diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleList.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleList.java index 6ffa7d8..bb78cc2 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleList.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleMaskItem.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleMaskItem.java index 54ba6b3..d29ba9e 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleMaskItem.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/LocaleMaskItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,6 +39,9 @@ public class LocaleMaskItem implements Comparable { /** * Constructor of class LocaleMaskItem. + * + * @param languageTag language tag + * @param configs locale config list */ public LocaleMaskItem(String languageTag, ArrayList configs) { this.languageTag = languageTag; diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/MeasureFormatPatternFetcher.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/MeasureFormatPatternFetcher.java index 1427a3c..55176bc 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/MeasureFormatPatternFetcher.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/MeasureFormatPatternFetcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/PluralFetcher.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/PluralFetcher.java index fc1107d..121b252 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/PluralFetcher.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/PluralFetcher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -114,8 +114,7 @@ public class PluralFetcher { String[] splits = trimedLine.split(" ", 2); // Split into 2 parts if (splits.length != 2) { logger.log(Level.SEVERE, "Init error"); - String[] emptyArray = new String[0]; - return emptyArray; + return new String[0]; } String languageTag = splits[0]; if (!languageTag.contains("-")) { diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/ResourceConfiguration.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/ResourceConfiguration.java index 55a18bc..30bb771 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/ResourceConfiguration.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/ResourceConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,6 +24,8 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Resource configuration defined in the reource_items.json @@ -31,6 +33,8 @@ import java.util.ArrayList; * @since 2022-8-22 */ public class ResourceConfiguration { + private static final Logger LOG = Logger.getLogger("ResourceConfiguration"); + private ResourceConfiguration() {} /** @@ -56,7 +60,7 @@ public class ResourceConfiguration { ret.add(item); } } catch (IOException | URISyntaxException e) { - e.printStackTrace(); + LOG.log(Level.SEVERE, "Generated errors when read resource_items.json file."); } return ret; } diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/StringPool.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/StringPool.java index 9a55d53..c0a9be4 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/StringPool.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/StringPool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -42,6 +42,9 @@ public class StringPool { /** * Constructor of class StringPool. + * + * @param hashMap string and it's offset mapping + * @param offset string's offset */ public StringPool(HashMap hashMap, int offset) { size = hashMap.size(); diff --git a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Utils.java b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Utils.java index 6d3d22a..9f2011d 100644 --- a/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Utils.java +++ b/tools/i18n-dat-tool/src/main/java/ohos/global/i18n/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,6 +31,8 @@ import java.util.Iterator; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; import ohos.global.i18n.ResourceConfiguration.ConfigItem; import ohos.global.i18n.ResourceConfiguration.Element; @@ -47,6 +49,7 @@ public class Utils { private static final String PATTERN_INDEX_MASK = "#define PATTERN_INDEX_MASK = 0x0000ffff"; private static final String I18N_MACROS_BEGIN = "// this file should only be included by date_time_format_impl.cpp"; private static final int MAX_CASE_NUMBER = 14; + private static final Logger LOG = Logger.getLogger("Utils"); private Utils() {} @@ -262,7 +265,7 @@ public class Utils { } } } catch (IOException e) { - e.printStackTrace(); + LOG.log(Level.SEVERE, "Generated errors when processed file."); } } @@ -370,7 +373,7 @@ public class Utils { } } } catch (IOException e) { - e.printStackTrace(); + LOG.log(Level.SEVERE, "Generated error when processed file."); } } -- Gitee