SFML - Simple and Fast Multimedia Library

SFML 3.1.0
Loading...
Searching...
No Matches
Utf.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Config.hpp>
31
32#include <array>
33#include <locale>
34#include <optional>
35
36#include <cstdint>
37#include <cstdlib>
38
39
40namespace sf
41{
42template <unsigned int N>
43 class Utf;
44
49template <>
50 class Utf<8>
51{
52public:
67 template <typename In>
68 static In decode(In begin, In end, char32_t& output, std::optional<char32_t> replacement = std::nullopt);
69
83 template <typename Out>
84 static Out encode(char32_t input, Out output, std::optional<std::uint8_t> replacement = std::nullopt);
85
98 template <typename In>
99 static In next(In begin, In end);
100
114 template <typename In>
115 static std::size_t count(In begin, In end);
116
131 template <typename In, typename Out>
132 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {});
133
144 template <typename In, typename Out>
145 static Out fromWide(In begin, In end, Out output);
146
157 template <typename In, typename Out>
158 static Out fromLatin1(In begin, In end, Out output);
159
175 template <typename In, typename Out>
176 static Out toAnsi(In begin,
177 In end,
178 Out output,
179 std::optional<char> replacement = std::nullopt,
180 const std::locale& locale = {});
181
193 template <typename In, typename Out>
194 static Out toWide(In begin, In end, Out output, std::optional<wchar_t> replacement = std::nullopt);
195
207 template <typename In, typename Out>
208 static Out toLatin1(In begin, In end, Out output, std::optional<char> replacement = std::nullopt);
209
226 template <typename In, typename Out>
227 static Out toUtf8(In begin, In end, Out output, std::optional<std::uint8_t> replacement = std::nullopt);
228
240 template <typename In, typename Out>
241 static Out toUtf16(In begin, In end, Out output, std::optional<char16_t> replacement = std::nullopt);
242
254 template <typename In, typename Out>
255 static Out toUtf32(In begin, In end, Out output, std::optional<char32_t> replacement = std::nullopt);
256};
257
262template <>
263 class Utf<16>
264{
265public:
280 template <typename In>
281 static In decode(In begin, In end, char32_t& output, std::optional<char32_t> replacement = std::nullopt);
282
296 template <typename Out>
297 static Out encode(char32_t input, Out output, std::optional<char16_t> replacement = std::nullopt);
298
311 template <typename In>
312 static In next(In begin, In end);
313
327 template <typename In>
328 static std::size_t count(In begin, In end);
329
344 template <typename In, typename Out>
345 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {});
346
357 template <typename In, typename Out>
358 static Out fromWide(In begin, In end, Out output);
359
370 template <typename In, typename Out>
371 static Out fromLatin1(In begin, In end, Out output);
372
388 template <typename In, typename Out>
389 static Out toAnsi(In begin,
390 In end,
391 Out output,
392 std::optional<char> replacement = std::nullopt,
393 const std::locale& locale = {});
394
406 template <typename In, typename Out>
407 static Out toWide(In begin, In end, Out output, std::optional<wchar_t> replacement = std::nullopt);
408
420 template <typename In, typename Out>
421 static Out toLatin1(In begin, In end, Out output, std::optional<char> replacement = std::nullopt);
422
434 template <typename In, typename Out>
435 static Out toUtf8(In begin, In end, Out output, std::optional<std::uint8_t> replacement = std::nullopt);
436
453 template <typename In, typename Out>
454 static Out toUtf16(In begin, In end, Out output, std::optional<char16_t> replacement = std::nullopt);
455
467 template <typename In, typename Out>
468 static Out toUtf32(In begin, In end, Out output, std::optional<char32_t> replacement = std::nullopt);
469};
470
475template <>
476 class Utf<32>
477{
478public:
494 template <typename In>
495 static In decode(In begin, In end, char32_t& output, std::optional<char32_t> replacement = std::nullopt);
496
511 template <typename Out>
512 static Out encode(char32_t input, Out output, std::optional<char32_t> replacement = std::nullopt);
513
526 template <typename In>
527 static In next(In begin, In end);
528
541 template <typename In>
542 static std::size_t count(In begin, In end);
543
558 template <typename In, typename Out>
559 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {});
560
571 template <typename In, typename Out>
572 static Out fromWide(In begin, In end, Out output);
573
584 template <typename In, typename Out>
585 static Out fromLatin1(In begin, In end, Out output);
586
602 template <typename In, typename Out>
603 static Out toAnsi(In begin,
604 In end,
605 Out output,
606 std::optional<char> replacement = std::nullopt,
607 const std::locale& locale = {});
608
620 template <typename In, typename Out>
621 static Out toWide(In begin, In end, Out output, std::optional<wchar_t> replacement = std::nullopt);
622
634 template <typename In, typename Out>
635 static Out toLatin1(In begin, In end, Out output, std::optional<char> replacement = std::nullopt);
636
648 template <typename In, typename Out>
649 static Out toUtf8(In begin, In end, Out output, std::optional<std::uint8_t> replacement = std::nullopt);
650
662 template <typename In, typename Out>
663 static Out toUtf16(In begin, In end, Out output, std::optional<char16_t> replacement = std::nullopt);
664
681 template <typename In, typename Out>
682 static Out toUtf32(In begin, In end, Out output, std::optional<char32_t> replacement = std::nullopt);
683
697 template <typename In>
698 static char32_t decodeAnsi(In input, const std::locale& locale = {});
699
712 template <typename In>
713 static char32_t decodeWide(In input);
714
730 template <typename Out>
731 static Out encodeAnsi(char32_t codepoint,
732 Out output,
733 std::optional<char> replacement = std::nullopt,
734 const std::locale& locale = {});
735
750 template <typename Out>
751 static Out encodeWide(char32_t codepoint, Out output, std::optional<wchar_t> replacement = std::nullopt);
752};
753
754// Make type aliases to get rid of the template syntax
755 using Utf8 = Utf<8>;
756 using Utf16 = Utf<16>;
757 using Utf32 = Utf<32>;
758
759} // namespace sf
760
761#include <SFML/System/Utf.inl>
762
763
Config.hpp
sf::Utf< 16 >::toUtf16
static Out toUtf16(In begin, In end, Out output, std::optional< char16_t > replacement=std::nullopt)
Convert a UTF-16 characters range to UTF-16.
sf::Utf< 16 >::toWide
static Out toWide(In begin, In end, Out output, std::optional< wchar_t > replacement=std::nullopt)
Convert an UTF-16 characters range to wide characters.
sf::Utf< 16 >::fromWide
static Out fromWide(In begin, In end, Out output)
Convert a wide characters range to UTF-16.
sf::Utf< 16 >::fromLatin1
static Out fromLatin1(In begin, In end, Out output)
Convert a latin-1 (ISO-5589-1) characters range to UTF-16.
sf::Utf< 16 >::encode
static Out encode(char32_t input, Out output, std::optional< char16_t > replacement=std::nullopt)
Encode a single UTF-16 character.
sf::Utf< 16 >::fromAnsi
static Out fromAnsi(In begin, In end, Out output, const std::locale &locale={})
Convert an ANSI characters range to UTF-16.
sf::Utf< 16 >::toUtf32
static Out toUtf32(In begin, In end, Out output, std::optional< char32_t > replacement=std::nullopt)
Convert a UTF-16 characters range to UTF-32.
sf::Utf< 16 >::count
static std::size_t count(In begin, In end)
Count the number of characters of a UTF-16 sequence.
sf::Utf< 16 >::toUtf8
static Out toUtf8(In begin, In end, Out output, std::optional< std::uint8_t > replacement=std::nullopt)
Convert a UTF-16 characters range to UTF-8.
sf::Utf< 16 >::next
static In next(In begin, In end)
Advance to the next UTF-16 character.
sf::Utf< 16 >::toLatin1
static Out toLatin1(In begin, In end, Out output, std::optional< char > replacement=std::nullopt)
Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters.
sf::Utf< 16 >::toAnsi
static Out toAnsi(In begin, In end, Out output, std::optional< char > replacement=std::nullopt, const std::locale &locale={})
Convert an UTF-16 characters range to ANSI characters.
sf::Utf< 16 >::decode
static In decode(In begin, In end, char32_t &output, std::optional< char32_t > replacement=std::nullopt)
Decode a single UTF-16 character.
sf::Utf< 32 >::fromLatin1
static Out fromLatin1(In begin, In end, Out output)
Convert a latin-1 (ISO-5589-1) characters range to UTF-32.
sf::Utf< 32 >::toUtf8
static Out toUtf8(In begin, In end, Out output, std::optional< std::uint8_t > replacement=std::nullopt)
Convert a UTF-32 characters range to UTF-8.
sf::Utf< 32 >::encode
static Out encode(char32_t input, Out output, std::optional< char32_t > replacement=std::nullopt)
Encode a single UTF-32 character.
sf::Utf< 32 >::decodeWide
static char32_t decodeWide(In input)
Decode a single wide character to UTF-32.
sf::Utf< 32 >::encodeWide
static Out encodeWide(char32_t codepoint, Out output, std::optional< wchar_t > replacement=std::nullopt)
Encode a single UTF-32 character to wide.
sf::Utf< 32 >::encodeAnsi
static Out encodeAnsi(char32_t codepoint, Out output, std::optional< char > replacement=std::nullopt, const std::locale &locale={})
Encode a single UTF-32 character to ANSI.
sf::Utf< 32 >::toUtf16
static Out toUtf16(In begin, In end, Out output, std::optional< char16_t > replacement=std::nullopt)
Convert a UTF-32 characters range to UTF-16.
sf::Utf< 32 >::toLatin1
static Out toLatin1(In begin, In end, Out output, std::optional< char > replacement=std::nullopt)
Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters.
sf::Utf< 32 >::fromAnsi
static Out fromAnsi(In begin, In end, Out output, const std::locale &locale={})
Convert an ANSI characters range to UTF-32.
sf::Utf< 32 >::next
static In next(In begin, In end)
Advance to the next UTF-32 character.
sf::Utf< 32 >::decodeAnsi
static char32_t decodeAnsi(In input, const std::locale &locale={})
Decode a single ANSI character to UTF-32.
sf::Utf< 32 >::count
static std::size_t count(In begin, In end)
Count the number of characters of a UTF-32 sequence.
sf::Utf< 32 >::toAnsi
static Out toAnsi(In begin, In end, Out output, std::optional< char > replacement=std::nullopt, const std::locale &locale={})
Convert an UTF-32 characters range to ANSI characters.
sf::Utf< 32 >::fromWide
static Out fromWide(In begin, In end, Out output)
Convert a wide characters range to UTF-32.
sf::Utf< 32 >::decode
static In decode(In begin, In end, char32_t &output, std::optional< char32_t > replacement=std::nullopt)
Decode a single UTF-32 character.
sf::Utf< 32 >::toWide
static Out toWide(In begin, In end, Out output, std::optional< wchar_t > replacement=std::nullopt)
Convert an UTF-32 characters range to wide characters.
sf::Utf< 32 >::toUtf32
static Out toUtf32(In begin, In end, Out output, std::optional< char32_t > replacement=std::nullopt)
Convert a UTF-32 characters range to UTF-32.
sf::Utf< 8 >::next
static In next(In begin, In end)
Advance to the next UTF-8 character.
sf::Utf< 8 >::decode
static In decode(In begin, In end, char32_t &output, std::optional< char32_t > replacement=std::nullopt)
Decode a single UTF-8 character.
sf::Utf< 8 >::toUtf16
static Out toUtf16(In begin, In end, Out output, std::optional< char16_t > replacement=std::nullopt)
Convert a UTF-8 characters range to UTF-16.
sf::Utf< 8 >::fromAnsi
static Out fromAnsi(In begin, In end, Out output, const std::locale &locale={})
Convert an ANSI characters range to UTF-8.
sf::Utf< 8 >::toUtf8
static Out toUtf8(In begin, In end, Out output, std::optional< std::uint8_t > replacement=std::nullopt)
Convert a UTF-8 characters range to UTF-8.
sf::Utf< 8 >::toUtf32
static Out toUtf32(In begin, In end, Out output, std::optional< char32_t > replacement=std::nullopt)
Convert a UTF-8 characters range to UTF-32.
sf::Utf< 8 >::toWide
static Out toWide(In begin, In end, Out output, std::optional< wchar_t > replacement=std::nullopt)
Convert an UTF-8 characters range to wide characters.
sf::Utf< 8 >::fromLatin1
static Out fromLatin1(In begin, In end, Out output)
Convert a latin-1 (ISO-5589-1) characters range to UTF-8.
sf::Utf< 8 >::fromWide
static Out fromWide(In begin, In end, Out output)
Convert a wide characters range to UTF-8.
sf::Utf< 8 >::encode
static Out encode(char32_t input, Out output, std::optional< std::uint8_t > replacement=std::nullopt)
Encode a single UTF-8 character.
sf::Utf< 8 >::toLatin1
static Out toLatin1(In begin, In end, Out output, std::optional< char > replacement=std::nullopt)
Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters.
sf::Utf< 8 >::count
static std::size_t count(In begin, In end)
Count the number of characters of a UTF-8 sequence.
sf::Utf< 8 >::toAnsi
static Out toAnsi(In begin, In end, Out output, std::optional< char > replacement=std::nullopt, const std::locale &locale={})
Convert an UTF-8 characters range to ANSI characters.
sf::Utf
Utility class providing generic functions for UTF conversions.
Definition Utf.hpp:43
sf
Definition AudioResource.hpp:36
sf::Utf32
Utf< 32 > Utf32
Definition Utf.hpp:757
sf::Utf16
Utf< 16 > Utf16
Definition Utf.hpp:756
sf::Utf8
Utf< 8 > Utf8
Definition Utf.hpp:755