Commit 63e26820 authored by Yoshi Cheng-Hao Huang's avatar Yoshi Cheng-Hao Huang
Browse files

Bug 1735341 : Rename FillVectorWithICUCall to FillBufferWithICUCall....

Bug 1735341 : Rename FillVectorWithICUCall to FillBufferWithICUCall. r=platform-i18n-reviewers,anba,dminor

So with this patch FillVectorWithICUCall could become an overload of FillBufferWithICUCall,
with the buffer type is mozilla::Vector.

The callers of mozilla::intl could provide a mozilla::Vector as the
buffer, instead of creating some buffer adapter like nsTArrayU8Buffer,
TestBuffer, or FormatBuffer.

Differential Revision: https://phabricator.services.mozilla.com/D128240
parent edaed7ec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ class DateTimeFormat final {
      // Write the formatted date into the u16Buffer.
      PatternVector u16Vec;

      auto result = FillVectorWithICUCall(
      auto result = FillBufferWithICUCall(
          u16Vec, [this, &aUnixEpoch](UChar* target, int32_t length,
                                      UErrorCode* status) {
            return udat_format(mDateFormat, aUnixEpoch, target, length,
+0 −36
Original line number Diff line number Diff line
@@ -76,25 +76,6 @@ class DateTimePatternGenerator final {
        });
  }

  /**
   * Given a skeleton (a string with unordered datetime fields), get a best
   * pattern that will fit for that locale. This pattern will be filled into the
   * buffer. e.g. The skeleton "yMd" would return the pattern "M/d/y" for en-US,
   * or "dd/MM/y" for en-GB.
   */
  template <size_t S>
  ICUResult GetBestPattern(Span<const char16_t> aSkeleton,
                           Vector<char16_t, S>& aVector,
                           EnumSet<PatternMatchOption> options = {}) {
    return FillVectorWithICUCall(
        aVector, [&](UChar* target, int32_t length, UErrorCode* status) {
          return udatpg_getBestPatternWithOptions(
              mGenerator.GetMut(), aSkeleton.data(),
              static_cast<int32_t>(aSkeleton.Length()),
              toUDateTimePatternMatchOptions(options), target, length, status);
        });
  }

  /**
   * Get a skeleton (a string with unordered datetime fields) from a pattern.
   * For example, both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
@@ -111,23 +92,6 @@ class DateTimePatternGenerator final {
        });
  }

  /**
   * Get a skeleton (a string with unordered datetime fields) from a pattern.
   * For example, both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
   */
  template <typename V, size_t N, typename A>
  static ICUResult GetSkeleton(Span<const char16_t> aPattern,
                               Vector<V, N, A>& aVector) {
    // At one time udatpg_getSkeleton required a UDateTimePatternGenerator*, but
    // now it is valid to pass in a nullptr.
    return FillVectorWithICUCall(
        aVector, [&](UChar* target, int32_t length, UErrorCode* status) {
          return udatpg_getSkeleton(nullptr, aPattern.data(),
                                    static_cast<int32_t>(aPattern.Length()),
                                    target, length, status);
        });
  }

  /**
   * TODO(Bug 1686965) - Temporarily get the underlying ICU object while
   * migrating to the unified API. This should be removed when completing the
+3 −3
Original line number Diff line number Diff line
@@ -159,11 +159,11 @@ class VectorToBufferAdaptor {
};

/**
 * A variant of FillBufferWithICUCall that accepts a mozilla::Vector rather than
 * a Buffer.
 * An overload of FillBufferWithICUCall that accepts a mozilla::Vector rather
 * than a Buffer.
 */
template <typename ICUStringFunction, size_t InlineSize, typename CharType>
static ICUResult FillVectorWithICUCall(Vector<CharType, InlineSize>& vector,
static ICUResult FillBufferWithICUCall(Vector<CharType, InlineSize>& vector,
                                       const ICUStringFunction& strFn) {
  VectorToBufferAdaptor buffer(vector);
  return FillBufferWithICUCall(buffer, strFn);
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ namespace mozilla::intl {
/* static */
ICUResult LocaleCanonicalizer::CanonicalizeICULevel1(
    const char* aLocaleIn, LocaleCanonicalizer::Vector& aLocaleOut) {
  auto result = FillVectorWithICUCall(
  auto result = FillBufferWithICUCall(
      aLocaleOut,
      [&aLocaleIn](char* target, int32_t length, UErrorCode* status) {
        return uloc_canonicalize(aLocaleIn, target, length, status);
+1 −1
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ class RelativeTimeFormat final {
    if constexpr (std::is_same<typename B::CharType, char>::value) {
      mozilla::Vector<char16_t, StackU16VectorSize> u16Vec;

      MOZ_TRY(FillVectorWithICUCall(
      MOZ_TRY(FillBufferWithICUCall(
          u16Vec, [this, aNumber, aUnit, fmt](UChar* target, int32_t length,
                                              UErrorCode* status) {
            return fmt(mFormatter, aNumber, ToURelativeDateTimeUnit(aUnit),
Loading