Create a bcp47 constexpr parser to be used in LanguageTag. [chromium/src : main]

0 views
Skip to first unread message

Greg Thompson (Gerrit)

unread,
Jul 7, 2026, 4:18:01 AM (yesterday) Jul 7
to Danilo Tedeschi, Chromium LUCI CQ, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, jshin...@chromium.org
Attention needed from Danilo Tedeschi

Greg Thompson added 12 comments

File base/i18n/internal/bcp47_parser.h
Line 122, Patchset 7 (Latest):constexpr std::optional<ParsedBcp47Tag> ParseBcp47Tag(std::string_view tag) {
Greg Thompson . unresolved

`std::string_view tag LIFETIME_BOUND`

Line 92, Patchset 7 (Latest): base::span<const std::string_view> subtags) {
Greg Thompson . unresolved

`base::span<const std::string_view> subtags LIFETIME_BOUND`

(#include "base/compiler_specific.h")

Line 77, Patchset 7 (Latest): // See the comments in `IsLanguageSubgtag`.
Greg Thompson . unresolved

Please fix this WARNING reported by autoreview issue finding: There are a few typos in these comments:

  • `IsLanguageSubgtag` -> `IsLanguageSubtag`
  • `IsScriptSubgtag` -> `IsScriptSubtag`
  • `IsRegionSubgtag` -> `IsRegion` (the function is named `IsRegion`)
  • `IsVariantSubgtag` -> `IsVariant` (the function is named `IsVariant`)
Line 74, Patchset 7 (Latest):// The parsed BCP47 tag. It is a view on the actual input string, be-aware of
// life-time.
Greg Thompson . unresolved

i find this wording a little odd. consider removing this since we can use an annotation to enforce the correct behavior; see below.

Line 19, Patchset 7 (Latest): return std::ranges::all_of(
Greg Thompson . unresolved

#include <algorithm>

Line 16, Patchset 7 (Latest):namespace base::i18n::internal {
Greg Thompson . unresolved

i recently became aware of the guidance to avoid generic nested namespace named like `internal` in go/totw/130#best-practices. wdyt about `base::i18n_internal` here? can migrate other files in a distinct CL.

Line 12, Patchset 7 (Latest):#include "base/containers/fixed_flat_map.h"
Greg Thompson . unresolved

Please fix this WARNING reported by autoreview issue finding: This header does not appear to be used in this file and can be removed.

Line 8, Patchset 7 (Latest):#include <array>
Greg Thompson . unresolved

Please fix this WARNING reported by autoreview issue finding: These headers (`<array>`, `<limits>`) do not appear to be used in this file and can be removed.

File base/i18n/internal/bcp47_parser_unittest.cc
Line 17, Patchset 7 (Latest): static_assert(IsLanguageSubtag("en"));
Greg Thompson . unresolved

add tests for empty strings to all of these?

Line 34, Patchset 7 (Latest): // Constexpr check for full tag parsing from a span.
Greg Thompson . unresolved

"string"? or did you mean to use a span below?

Line 72, Patchset 7 (Latest): const std::optional<ParsedBcp47Tag> parsed = ParseBcp47Tag("en-US");
Greg Thompson . unresolved

this is the string variant -- do you mean to call the span variant here?

Line 73, Patchset 7 (Latest): ASSERT_TRUE(parsed.has_value());
Greg Thompson . unresolved
replace this with:
```
ASSERT_OK_AND_ASSIGN(auto parsed, ParseBcp47Tag("en-US"));
```
and then use `parsed.` rather than `parsed->` below

comment applies to the tests below, too

Open in Gerrit

Related details

Attention is currently required from:
  • Danilo Tedeschi
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I8a614eab8985ec9004f0ad6dffa56b25385af05a
Gerrit-Change-Number: 8046520
Gerrit-PatchSet: 7
Gerrit-Owner: Danilo Tedeschi <da...@google.com>
Gerrit-Reviewer: Danilo Tedeschi <da...@google.com>
Gerrit-Reviewer: Greg Thompson <g...@chromium.org>
Gerrit-Attention: Danilo Tedeschi <da...@google.com>
Gerrit-Comment-Date: Tue, 07 Jul 2026 08:17:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Danilo Tedeschi (Gerrit)

unread,
Jul 7, 2026, 11:32:23 AM (20 hours ago) Jul 7
to Chromium LUCI CQ, Greg Thompson, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, jshin...@chromium.org
Attention needed from Greg Thompson

Danilo Tedeschi added 12 comments

File base/i18n/internal/bcp47_parser.h
Line 122, Patchset 7:constexpr std::optional<ParsedBcp47Tag> ParseBcp47Tag(std::string_view tag) {
Greg Thompson . resolved

`std::string_view tag LIFETIME_BOUND`

Danilo Tedeschi

Done

Line 92, Patchset 7: base::span<const std::string_view> subtags) {
Greg Thompson . resolved

`base::span<const std::string_view> subtags LIFETIME_BOUND`

(#include "base/compiler_specific.h")

Danilo Tedeschi

The bound is actually in the `tag` string_view that generated the span of subtags. If I add a LIFETIME_BOUND here, the compiler gives me an error if I call this from the ParseBcp47Tag(std::string_view tag) overload.

Line 77, Patchset 7: // See the comments in `IsLanguageSubgtag`.
Greg Thompson . resolved

Please fix this WARNING reported by autoreview issue finding: There are a few typos in these comments:

  • `IsLanguageSubgtag` -> `IsLanguageSubtag`
  • `IsScriptSubgtag` -> `IsScriptSubtag`
  • `IsRegionSubgtag` -> `IsRegion` (the function is named `IsRegion`)
  • `IsVariantSubgtag` -> `IsVariant` (the function is named `IsVariant`)
Danilo Tedeschi

fixed and renamed IsRegion, IsVariant -> IsRegionSubtag, IsVariantSubtag.

Line 74, Patchset 7:// The parsed BCP47 tag. It is a view on the actual input string, be-aware of
// life-time.
Greg Thompson . resolved

i find this wording a little odd. consider removing this since we can use an annotation to enforce the correct behavior; see below.

Danilo Tedeschi

Done

Line 19, Patchset 7: return std::ranges::all_of(
Greg Thompson . resolved

#include <algorithm>

Danilo Tedeschi

Done

Line 16, Patchset 7:namespace base::i18n::internal {
Greg Thompson . resolved

i recently became aware of the guidance to avoid generic nested namespace named like `internal` in go/totw/130#best-practices. wdyt about `base::i18n_internal` here? can migrate other files in a distinct CL.

Danilo Tedeschi

Done

Line 12, Patchset 7:#include "base/containers/fixed_flat_map.h"
Greg Thompson . resolved

Please fix this WARNING reported by autoreview issue finding: This header does not appear to be used in this file and can be removed.

Danilo Tedeschi

Done

Line 8, Patchset 7:#include <array>
Greg Thompson . resolved

Please fix this WARNING reported by autoreview issue finding: These headers (`<array>`, `<limits>`) do not appear to be used in this file and can be removed.

Danilo Tedeschi

Done

File base/i18n/internal/bcp47_parser_unittest.cc
Line 17, Patchset 7: static_assert(IsLanguageSubtag("en"));
Greg Thompson . resolved

add tests for empty strings to all of these?

Danilo Tedeschi

Done

Line 34, Patchset 7: // Constexpr check for full tag parsing from a span.
Greg Thompson . resolved

"string"? or did you mean to use a span below?

Danilo Tedeschi

Done

Line 72, Patchset 7: const std::optional<ParsedBcp47Tag> parsed = ParseBcp47Tag("en-US");
Greg Thompson . resolved

this is the string variant -- do you mean to call the span variant here?

Danilo Tedeschi

Done

Line 73, Patchset 7: ASSERT_TRUE(parsed.has_value());
Greg Thompson . resolved
replace this with:
```
ASSERT_OK_AND_ASSIGN(auto parsed, ParseBcp47Tag("en-US"));
```
and then use `parsed.` rather than `parsed->` below

comment applies to the tests below, too

Danilo Tedeschi

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Greg Thompson
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I8a614eab8985ec9004f0ad6dffa56b25385af05a
    Gerrit-Change-Number: 8046520
    Gerrit-PatchSet: 8
    Gerrit-Owner: Danilo Tedeschi <da...@google.com>
    Gerrit-Reviewer: Danilo Tedeschi <da...@google.com>
    Gerrit-Reviewer: Greg Thompson <g...@chromium.org>
    Gerrit-Attention: Greg Thompson <g...@chromium.org>
    Gerrit-Comment-Date: Tue, 07 Jul 2026 15:32:05 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Greg Thompson <g...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Greg Thompson (Gerrit)

    unread,
    2:48 AM (4 hours ago) 2:48 AM
    to Danilo Tedeschi, Chromium LUCI CQ, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, jshin...@chromium.org
    Attention needed from Danilo Tedeschi

    Greg Thompson voted and added 1 comment

    Votes added by Greg Thompson

    Code-Review+1

    1 comment

    File base/i18n/internal/bcp47_parser_unittest.cc
    Line 112, Patchset 9 (Latest): ASSERT_OK_AND_ASSIGN(ParsedBcp47Tag parsed,
    Greg Thompson . unresolved

    nit: could use just `parsed` here and get rid of the extra scopes

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Danilo Tedeschi
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I8a614eab8985ec9004f0ad6dffa56b25385af05a
      Gerrit-Change-Number: 8046520
      Gerrit-PatchSet: 9
      Gerrit-Owner: Danilo Tedeschi <da...@google.com>
      Gerrit-Reviewer: Danilo Tedeschi <da...@google.com>
      Gerrit-Reviewer: Greg Thompson <g...@chromium.org>
      Gerrit-Attention: Danilo Tedeschi <da...@google.com>
      Gerrit-Comment-Date: Wed, 08 Jul 2026 06:48:16 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages