blob: 38bcf1369f08a358463135f3b2f3d90a2dba668f [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2020 The Chromium Authors
Hidehiko Abe080ad302020-10-30 17:41:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_BASE_IME_UTF_OFFSET_H_
6#define UI_BASE_IME_UTF_OFFSET_H_
7
Takuto Ikutab29c7c72024-12-16 08:35:388#include <stddef.h>
9
Arthur Sonzogni3eb9fd512024-02-09 12:20:4310#include <optional>
Helmut Januschka36619c12024-04-24 14:33:1911#include <string_view>
Arthur Sonzogni3eb9fd512024-02-09 12:20:4312
Hidehiko Abe080ad302020-10-30 17:41:2713#include "base/component_export.h"
Hidehiko Abe080ad302020-10-30 17:41:2714
15namespace ui {
16
17// Given UTF8 string and its valid offset, returns the offset in UTF16.
18// Returns nullopt if the given offset is invalid (not at a valid boundary
19// or out of range).
20COMPONENT_EXPORT(UI_BASE)
Helmut Januschka36619c12024-04-24 14:33:1921std::optional<size_t> Utf16OffsetFromUtf8Offset(std::string_view text,
Arthur Sonzogni3eb9fd512024-02-09 12:20:4322 size_t utf8_offset);
Hidehiko Abe080ad302020-10-30 17:41:2723
24// Given UTF16 string and its valid offset, returns the offset in UTF8.
25// Returns nullopt if the given offset is invalid (not at a valid boundary
26// or out of range).
27COMPONENT_EXPORT(UI_BASE)
Helmut Januschka36619c12024-04-24 14:33:1928std::optional<size_t> Utf8OffsetFromUtf16Offset(std::u16string_view text,
Arthur Sonzogni3eb9fd512024-02-09 12:20:4329 size_t utf16_offset);
Hidehiko Abe080ad302020-10-30 17:41:2730
31} // namespace ui
32
33#endif // UI_BASE_IME_UTF_OFFSET_H_