Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Hidehiko Abe | 080ad30 | 2020-10-30 17:41:27 | [diff] [blame] | 2 | // 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 Ikuta | b29c7c7 | 2024-12-16 08:35:38 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 10 | #include <optional> |
Helmut Januschka | 36619c1 | 2024-04-24 14:33:19 | [diff] [blame] | 11 | #include <string_view> |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 12 | |
Hidehiko Abe | 080ad30 | 2020-10-30 17:41:27 | [diff] [blame] | 13 | #include "base/component_export.h" |
Hidehiko Abe | 080ad30 | 2020-10-30 17:41:27 | [diff] [blame] | 14 | |
| 15 | namespace 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). |
| 20 | COMPONENT_EXPORT(UI_BASE) |
Helmut Januschka | 36619c1 | 2024-04-24 14:33:19 | [diff] [blame] | 21 | std::optional<size_t> Utf16OffsetFromUtf8Offset(std::string_view text, |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 22 | size_t utf8_offset); |
Hidehiko Abe | 080ad30 | 2020-10-30 17:41:27 | [diff] [blame] | 23 | |
| 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). |
| 27 | COMPONENT_EXPORT(UI_BASE) |
Helmut Januschka | 36619c1 | 2024-04-24 14:33:19 | [diff] [blame] | 28 | std::optional<size_t> Utf8OffsetFromUtf16Offset(std::u16string_view text, |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 29 | size_t utf16_offset); |
Hidehiko Abe | 080ad30 | 2020-10-30 17:41:27 | [diff] [blame] | 30 | |
| 31 | } // namespace ui |
| 32 | |
| 33 | #endif // UI_BASE_IME_UTF_OFFSET_H_ |