| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
// This file is part of GCC. |
| 4 |
|
| 5 |
// GCC is free software; you can redistribute it and/or modify it under |
| 6 |
// the terms of the GNU General Public License as published by the Free |
| 7 |
// Software Foundation; either version 3, or (at your option) any later |
| 8 |
// version. |
| 9 |
|
| 10 |
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
// WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 |
// for more details. |
| 14 |
|
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with GCC; see the file COPYING3. If not see |
| 17 |
// <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
#ifndef RUST_UNICODE_H |
| 20 |
#define RUST_UNICODE_H |
| 21 |
|
| 22 |
#include "optional.h" |
| 23 |
#include "rust-system.h" |
| 24 |
#include "rust-input-source.h" |
| 25 |
|
| 26 |
namespace Rust { |
| 27 |
|
| 28 |
class Utf8String |
| 29 |
{ |
| 30 |
private: |
| 31 |
std::vector<Codepoint> chars; |
| 32 |
|
| 33 |
public: |
| 34 |
static tl::optional<Utf8String> |
| 35 |
make_utf8_string (const std::string &maybe_utf8) |
| 36 |
{ |
| 37 |
BufferInputSource input_source = {maybe_utf8, 0}; |
| 38 |
tl::optional<std::vector<Codepoint>> chars_opt = input_source.get_chars (); |
| 39 |
if (chars_opt.has_value ()) |
| 40 |
return {Utf8String (chars_opt.value ())}; |
| 41 |
else |
| 42 |
return tl::nullopt; |
| 43 |
} |
| 44 |
|
| 45 |
Utf8String (const std::vector<Codepoint> codepoints) : chars ({codepoints}) {} |
| 46 |
|
| 47 |
std::string as_string () const |
| 48 |
{ |
| 49 |
std::stringstream ss; |
| 50 |
for (Codepoint c : chars) |
| 51 |
ss << c.as_string (); |
| 52 |
|
| 53 |
return ss.str (); |
| 54 |
}; |
| 55 |
|
| 56 |
// Returns characters |
| 57 |
std::vector<Codepoint> get_chars () const { return chars; } |
| 58 |
|
| 59 |
Utf8String nfc_normalize () const; |
| 60 |
}; |
| 61 |
|
| 62 |
bool |
| 63 |
is_alphabetic (uint32_t codepoint); |
| 64 |
|
| 65 |
bool |
| 66 |
is_ascii_only (const std::string &str); |
| 67 |
|
| 68 |
bool |
| 69 |
is_numeric (uint32_t codepoint); |
| 70 |
|
| 71 |
bool |
| 72 |
is_nfc_qc_no (uint32_t codepoint); |
| 73 |
|
| 74 |
bool |
| 75 |
is_nfc_qc_maybe (uint32_t codepoint); |
| 76 |
|
| 77 |
enum class QuickCheckResult |
| 78 |
{ |
| 79 |
YES, |
| 80 |
NO, |
| 81 |
MAYBE |
| 82 |
}; |
| 83 |
|
| 84 |
QuickCheckResult |
| 85 |
nfc_quick_check (const std::vector<Codepoint> &s); |
| 86 |
|
| 87 |
} // namespace Rust |
| 88 |
|
| 89 |
#if CHECKING_P |
| 90 |
|
| 91 |
namespace selftest { |
| 92 |
|
| 93 |
void |
| 94 |
rust_nfc_qc_test (); |
| 95 |
|
| 96 |
void |
| 97 |
rust_utf8_normalize_test (); |
| 98 |
|
| 99 |
void |
| 100 |
rust_utf8_property_test (); |
| 101 |
|
| 102 |
} // namespace selftest |
| 103 |
|
| 104 |
#endif // CHECKING_P |
| 105 |
|
| 106 |
#endif |