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-2024 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
35#include <cstdint>
36#include <cstdlib>
37
38
39namespace sf
40{
41namespace priv
42{
43template <class InputIt, class OutputIt>
44OutputIt copy(InputIt first, InputIt last, OutputIt dFirst);
45}
46
47template <unsigned int N>
48class Utf;
49
54template <>
55class Utf<8>
56{
57public:
72 template <typename In>
73 static In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0);
74
88 template <typename Out>
89 static Out encode(std::uint32_t input, Out output, std::uint8_t replacement = 0);
90
103 template <typename In>
104 static In next(In begin, In end);
105
119 template <typename In>
120 static std::size_t count(In begin, In end);
121
136 template <typename In, typename Out>
137 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {});
138
149 template <typename In, typename Out>
150 static Out fromWide(In begin, In end, Out output);
151
162 template <typename In, typename Out>
163 static Out fromLatin1(In begin, In end, Out output);
164
180 template <typename In, typename Out>
181 static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {});
182
194 template <typename In, typename Out>
195 static Out toWide(In begin, In end, Out output, wchar_t replacement = 0);
196
208 template <typename In, typename Out>
209 static Out toLatin1(In begin, In end, Out output, char replacement = 0);
210
226 template <typename In, typename Out>
227 static Out toUtf8(In begin, In end, Out output);
228
239 template <typename In, typename Out>
240 static Out toUtf16(In begin, In end, Out output);
241
252 template <typename In, typename Out>
253 static Out toUtf32(In begin, In end, Out output);
254};
255
260template <>
261class Utf<16>
262{
263public:
278 template <typename In>
279 static In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0);
280
294 template <typename Out>
295 static Out encode(std::uint32_t input, Out output, std::uint16_t replacement = 0);
296
309 template <typename In>
310 static In next(In begin, In end);
311
325 template <typename In>
326 static std::size_t count(In begin, In end);
327
342 template <typename In, typename Out>
343 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {});
344
355 template <typename In, typename Out>
356 static Out fromWide(In begin, In end, Out output);
357
368 template <typename In, typename Out>
369 static Out fromLatin1(In begin, In end, Out output);
370
386 template <typename In, typename Out>
387 static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {});
388
400 template <typename In, typename Out>
401 static Out toWide(In begin, In end, Out output, wchar_t replacement = 0);
402
414 template <typename In, typename Out>
415 static Out toLatin1(In begin, In end, Out output, char replacement = 0);
416
427 template <typename In, typename Out>
428 static Out toUtf8(In begin, In end, Out output);
429
445 template <typename In, typename Out>
446 static Out toUtf16(In begin, In end, Out output);
447
458 template <typename In, typename Out>
459 static Out toUtf32(In begin, In end, Out output);
460};
461
466template <>
467class Utf<32>
468{
469public:
485 template <typename In>
486 static In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0);
487
502 template <typename Out>
503 static Out encode(std::uint32_t input, Out output, std::uint32_t replacement = 0);
504
517 template <typename In>
518 static In next(In begin, In end);
519
532 template <typename In>
533 static std::size_t count(In begin, In end);
534
549 template <typename In, typename Out>
550 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {});
551
562 template <typename In, typename Out>
563 static Out fromWide(In begin, In end, Out output);
564
575 template <typename In, typename Out>
576 static Out fromLatin1(In begin, In end, Out output);
577
593 template <typename In, typename Out>
594 static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {});
595
607 template <typename In, typename Out>
608 static Out toWide(In begin, In end, Out output, wchar_t replacement = 0);
609
621 template <typename In, typename Out>
622 static Out toLatin1(In begin, In end, Out output, char replacement = 0);
623
634 template <typename In, typename Out>
635 static Out toUtf8(In begin, In end, Out output);
636
647 template <typename In, typename Out>
648 static Out toUtf16(In begin, In end, Out output);
649
665 template <typename In, typename Out>
666 static Out toUtf32(In begin, In end, Out output);
667
681 template <typename In>
682 static std::uint32_t decodeAnsi(In input, const std::locale& locale = {});
683
696 template <typename In>
697 static std::uint32_t decodeWide(In input);
698
714 template <typename Out>
715 static Out encodeAnsi(std::uint32_t codepoint, Out output, char replacement = 0, const std::locale& locale = {});
716
731 template <typename Out>
732 static Out encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement = 0);
733};
734
735// Make type aliases to get rid of the template syntax
736using Utf8 = Utf<8>;
739
740} // namespace sf
741
742#include <SFML/System/Utf.inl>
743
744
Specialization of the Utf template for UTF-16.
Definition Utf.hpp:262
static Out toUtf16(In begin, In end, Out output)
Convert a UTF-16 characters range to UTF-16.
static Out fromWide(In begin, In end, Out output)
Convert a wide characters range to UTF-16.
static Out toWide(In begin, In end, Out output, wchar_t replacement=0)
Convert an UTF-16 characters range to wide characters.
static Out fromLatin1(In begin, In end, Out output)
Convert a latin-1 (ISO-5589-1) characters range to UTF-16.
static Out fromAnsi(In begin, In end, Out output, const std::locale &locale={})
Convert an ANSI characters range to UTF-16.
static std::size_t count(In begin, In end)
Count the number of characters of a UTF-16 sequence.
static Out toUtf32(In begin, In end, Out output)
Convert a UTF-16 characters range to UTF-32.
static In decode(In begin, In end, std::uint32_t &output, std::uint32_t replacement=0)
Decode a single UTF-16 character.
static Out toAnsi(In begin, In end, Out output, char replacement=0, const std::locale &locale={})
Convert an UTF-16 characters range to ANSI characters.
static In next(In begin, In end)
Advance to the next UTF-16 character.
static Out toLatin1(In begin, In end, Out output, char replacement=0)
Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters.
static Out encode(std::uint32_t input, Out output, std::uint16_t replacement=0)
Encode a single UTF-16 character.
static Out toUtf8(In begin, In end, Out output)
Convert a UTF-16 characters range to UTF-8.
Specialization of the Utf template for UTF-32.
Definition Utf.hpp:468
static Out fromLatin1(In begin, In end, Out output)
Convert a latin-1 (ISO-5589-1) characters range to UTF-32.
static Out encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement=0)
Encode a single UTF-32 character to wide.
static Out toLatin1(In begin, In end, Out output, char replacement=0)
Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters.
static Out toWide(In begin, In end, Out output, wchar_t replacement=0)
Convert an UTF-32 characters range to wide characters.
static Out encode(std::uint32_t input, Out output, std::uint32_t replacement=0)
Encode a single UTF-32 character.
static Out toUtf8(In begin, In end, Out output)
Convert a UTF-32 characters range to UTF-8.
static In decode(In begin, In end, std::uint32_t &output, std::uint32_t replacement=0)
Decode a single UTF-32 character.
static Out toUtf16(In begin, In end, Out output)
Convert a UTF-32 characters range to UTF-16.
static std::uint32_t decodeWide(In input)
Decode a single wide character to UTF-32.
static Out fromAnsi(In begin, In end, Out output, const std::locale &locale={})
Convert an ANSI characters range to UTF-32.
static In next(In begin, In end)
Advance to the next UTF-32 character.
static std::size_t count(In begin, In end)
Count the number of characters of a UTF-32 sequence.
static std::uint32_t decodeAnsi(In input, const std::locale &locale={})
Decode a single ANSI character to UTF-32.
static Out toAnsi(In begin, In end, Out output, char replacement=0, const std::locale &locale={})
Convert an UTF-32 characters range to ANSI characters.
static Out toUtf32(In begin, In end, Out output)
Convert a UTF-32 characters range to UTF-32.
static Out fromWide(In begin, In end, Out output)
Convert a wide characters range to UTF-32.
static Out encodeAnsi(std::uint32_t codepoint, Out output, char replacement=0, const std::locale &locale={})
Encode a single UTF-32 character to ANSI.
Specialization of the Utf template for UTF-8.
Definition Utf.hpp:56
static Out toAnsi(In begin, In end, Out output, char replacement=0, const std::locale &locale={})
Convert an UTF-8 characters range to ANSI characters.
static In next(In begin, In end)
Advance to the next UTF-8 character.
static In decode(In begin, In end, std::uint32_t &output, std::uint32_t replacement=0)
Decode a single UTF-8 character.
static Out fromAnsi(In begin, In end, Out output, const std::locale &locale={})
Convert an ANSI characters range to UTF-8.
static Out toUtf32(In begin, In end, Out output)
Convert a UTF-8 characters range to UTF-32.
static Out fromLatin1(In begin, In end, Out output)
Convert a latin-1 (ISO-5589-1) characters range to UTF-8.
static Out toUtf16(In begin, In end, Out output)
Convert a UTF-8 characters range to UTF-16.
static Out fromWide(In begin, In end, Out output)
Convert a wide characters range to UTF-8.
static Out toWide(In begin, In end, Out output, wchar_t replacement=0)
Convert an UTF-8 characters range to wide characters.
static Out toLatin1(In begin, In end, Out output, char replacement=0)
Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters.
static Out encode(std::uint32_t input, Out output, std::uint8_t replacement=0)
Encode a single UTF-8 character.
static Out toUtf8(In begin, In end, Out output)
Convert a UTF-8 characters range to UTF-8.
static std::size_t count(In begin, In end)
Count the number of characters of a UTF-8 sequence.
Utility class providing generic functions for UTF conversions.
Definition Utf.hpp:48