SFML 3.0.1
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-2025 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
39 namespace sf
40{
41 namespace priv
42{
43 template <class InputIt, class OutputIt>
44OutputIt copy(InputIt first, InputIt last, OutputIt dFirst);
45}
46
47 template <unsigned int N>
48 class Utf;
49
54 template <>
55 class Utf<8>
56{
57 public:
72 template <typename In>
73 static In decode(In begin, In end, char32_t& output, char32_t replacement = 0);
74
88 template <typename Out>
89 static Out encode(char32_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
260 template <>
261 class Utf<16>
262{
263 public:
278 template <typename In>
279 static In decode(In begin, In end, char32_t& output, char32_t replacement = 0);
280
294 template <typename Out>
295 static Out encode(char32_t input, Out output, char16_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
466 template <>
467 class Utf<32>
468{
469 public:
485 template <typename In>
486 static In decode(In begin, In end, char32_t& output, char32_t replacement = 0);
487
502 template <typename Out>
503 static Out encode(char32_t input, Out output, char32_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 char32_t decodeAnsi(In input, const std::locale& locale = {});
683
696 template <typename In>
697 static char32_t decodeWide(In input);
698
714 template <typename Out>
715 static Out encodeAnsi(char32_t codepoint, Out output, char replacement = 0, const std::locale& locale = {});
716
731 template <typename Out>
732 static Out encodeWide(char32_t codepoint, Out output, wchar_t replacement = 0);
733};
734
735// Make type aliases to get rid of the template syntax
736 using Utf8 = Utf<8>;
737 using Utf16 = Utf<16>;
738 using Utf32 = Utf<32>;
739
740} // namespace sf
741
742#include <SFML/System/Utf.inl>
743
744
Config.hpp
sf::Utf
Utility class providing generic functions for UTF conversions.
Definition Utf.hpp:48
sf
Definition AudioResource.hpp:36
sf::Utf32
Utf< 32 > Utf32
Definition Utf.hpp:738
sf::Utf16
Utf< 16 > Utf16
Definition Utf.hpp:737
sf::Utf8
Utf< 8 > Utf8
Definition Utf.hpp:736