Skip to content

Fix missing ICU UTF-16 header includes, C++17/20 CTAD guides, and empty INFLECTION_ROOT path resolution #206

Description

@nciric

Overview

This issue addresses compiler compatibility and runtime path resolution improvements across inflection:

  1. Explicit <unicode/utf16.h> includes:
    Several C++ source files use ICU UTF-16 code point macros (U16_PREV, U16_GET, U16_LENGTH, U16_NEXT) without explicitly including <unicode/utf16.h>. On strict compiler toolchains that do not transitively include ICU sub-headers, compilation fails.

  2. C++17/20 Class Template Argument Deduction (CTAD) Guides:
    Template classes (Finally, CompressedArray, MarisaTrie) and test code (DialogThreadSafetyTest.cpp) rely on template argument deduction. On toolchains compiling with strict C++17/20 warning options (such as -Wctad-maybe-unsupported), compiler warnings or errors are triggered. Adding explicit deduction guides for these classes and specifying explicit template arguments (std::atomic<bool>, std::barrier<>) ensures clean compilation.

  3. ResourceLocator.cpp Relative Path Resolution:
    In ResourceLocator::getRootForLocale(), when the INFLECTION_ROOT environment variable is unset/empty, string concatenation INFLECTION_ROOT_DIRECTORY() + u"/" + U16(INFLECTION_DATA_ROOT_DIR) + u"/inflection" evaluates with an unintended leading slash (u"/..."). This converts relative INFLECTION_DATA_ROOT_DIR paths into absolute filesystem root paths. Updating getRootForLocale to check if INFLECTION_ROOT_DIRECTORY() is empty preserves intended relative directory pathing.


Proposed Changes

  • Header Includes: Add #include <unicode/utf16.h> to:

    • src/inflection/tokenizer/ControlCleaver.cpp
    • src/inflection/grammar/synthesis/HeGrammarSynthesizer_WithConditionalHyphen.cpp
    • src/inflection/grammar/synthesis/KoGrammarSynthesizer_ParticleResolver.cpp
    • src/inflection/grammar/synthesis/TrGrammarSynthesizer_TrDisplayFunction.cpp
    • src/inflection/lang/StringFilterUtil.cpp
    • src/inflection/tokenizer/TokenUtil.cpp
    • src/inflection/util/StringViewUtils.cpp
    • src/inflection/util/UnicodeSetUtils.cpp
  • CTAD Guides & Test Updates:

    • src/inflection/util/Finally.hpp: Add deduction guide template <typename Function> Finally(Function) -> Finally<Function>;
    • src/inflection/dictionary/metadata/CompressedArray.hpp: Add deduction guide template <typename T> CompressedArray(const std::vector<T>&) -> CompressedArray<T>;
    • src/inflection/dictionary/metadata/MarisaTrie.hpp: Add deduction guide template <typename T> MarisaTrie(const std::map<std::u16string_view, T>&) -> MarisaTrie<T>;
    • test/src/inflection/dialog/DialogThreadSafetyTest.cpp: Specify explicit template parameters for std::atomic<bool> and std::barrier<>.
  • Path Resolution:

    • src/inflection/util/ResourceLocator.cpp: Check if INFLECTION_ROOT_DIRECTORY() is empty before prepending u"/".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions